-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TF-3278 Handle open app via deep link at MailboxDashboard screen
- Loading branch information
Showing
59 changed files
with
1,070 additions
and
426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
core/lib/presentation/extensions/either_view_state_extension.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:core/presentation/state/failure.dart'; | ||
import 'package:core/presentation/state/success.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
|
||
typedef OnFailureCallback = void Function(Failure? failure); | ||
typedef OnSuccessCallback<T> = void Function(T success); | ||
|
||
extension EitherViewStateExtension on Either<Failure, Success> { | ||
void foldSuccess<T>({ | ||
required OnSuccessCallback<T> onSuccess, | ||
required OnFailureCallback onFailure, | ||
}) { | ||
fold(onFailure, | ||
(success) => success is T ? onSuccess(success as T) : onFailure(null)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:core/utils/app_logger.dart'; | ||
|
||
class StringConvert { | ||
static String? writeEmptyToNull(String text) { | ||
static String? writeEmptyToNull(String text) { | ||
if (text.isEmpty) return null; | ||
return text; | ||
} | ||
|
||
static String writeNullToEmpty(String? text) { | ||
static String writeNullToEmpty(String? text) { | ||
return text ?? ''; | ||
} | ||
|
||
static String decodeBase64ToString(String text) { | ||
try { | ||
return utf8.decode(base64Decode(text)); | ||
} catch (e) { | ||
logError('StringConvert::decodeBase64ToString:Exception = $e'); | ||
return text; | ||
} | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
core/test/presentation/extensions/either_view_state_extension_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import 'package:core/presentation/extensions/either_view_state_extension.dart'; | ||
import 'package:core/presentation/state/failure.dart'; | ||
import 'package:core/presentation/state/success.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
|
||
class MockFailure extends Failure { | ||
final String message; | ||
|
||
MockFailure(this.message); | ||
|
||
@override | ||
List<Object?> get props => [message]; | ||
} | ||
|
||
class MockSuccess extends Success { | ||
final String data; | ||
|
||
MockSuccess(this.data); | ||
|
||
@override | ||
List<Object?> get props => [data]; | ||
} | ||
|
||
class AnotherSuccess extends Success { | ||
@override | ||
List<Object?> get props => []; | ||
} | ||
|
||
void main() { | ||
group('EitherViewStateExtension::foldSuccess::test', () { | ||
test('Should calls onFailure when Either is Left', () { | ||
final either = Left<Failure, Success>(MockFailure('Error occurred')); | ||
bool failureCalled = false; | ||
|
||
either.foldSuccess<Success>( | ||
onSuccess: (_) => fail('onSuccess should not be called'), | ||
onFailure: (failure) { | ||
failureCalled = true; | ||
expect(failure, isNotNull); | ||
expect(failure, isA<MockFailure>()); | ||
}, | ||
); | ||
|
||
expect(failureCalled, isTrue); | ||
}); | ||
|
||
test('Should calls onSuccess when Either is Right with matching type', () { | ||
final either = Right<Failure, Success>(MockSuccess('Successful')); | ||
bool successCalled = false; | ||
|
||
either.foldSuccess<Success>( | ||
onSuccess: (success) { | ||
successCalled = true; | ||
expect(success, isNotNull); | ||
expect(success, isA<MockSuccess>()); | ||
}, | ||
onFailure: (_) => fail('onFailure should not be called'), | ||
); | ||
|
||
expect(successCalled, isTrue); | ||
}); | ||
|
||
test('Should calls onFailure when Either is Right with non-matching type', () { | ||
final either = Right<Failure, Success>(MockSuccess('Successful')); | ||
bool failureCalled = false; | ||
|
||
either.foldSuccess<AnotherSuccess>( | ||
onSuccess: (_) => fail('onSuccess should not be called'), | ||
onFailure: (failure) { | ||
failureCalled = true; | ||
expect(failure, isNull); | ||
}, | ||
); | ||
|
||
expect(failureCalled, isTrue); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'package:core/utils/string_convert.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('StringConvert::decodeBase64ToString::test', () { | ||
test('should decode a valid Base64 string to a normal string', () { | ||
// Arrange | ||
const base64Encoded = 'SGVsbG8gV29ybGQh'; | ||
const expectedDecoded = 'Hello World!'; | ||
|
||
// Act | ||
final result = StringConvert.decodeBase64ToString(base64Encoded); | ||
|
||
// Assert | ||
expect(result, expectedDecoded); | ||
}); | ||
|
||
test('should return the original string for invalid Base64 input', () { | ||
// Arrange | ||
const invalidBase64 = 'InvalidBase64@@'; | ||
|
||
// Act | ||
final result = StringConvert.decodeBase64ToString(invalidBase64); | ||
|
||
// Assert | ||
expect(result, invalidBase64); | ||
}); | ||
|
||
test('should return the original string for empty input', () { | ||
// Arrange | ||
const emptyInput = ''; | ||
|
||
// Act | ||
final result = StringConvert.decodeBase64ToString(emptyInput); | ||
|
||
// Assert | ||
expect(result, emptyInput); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.