TF-3278 Handle open app via deep link at MailboxDashboard screen

This commit is contained in:
dab246
2024-11-22 23:30:37 +07:00
committed by Dat H. Pham
parent 8022559bc2
commit 223fdbf1fb
59 changed files with 1058 additions and 429 deletions
@@ -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);
});
});
}
+36
View File
@@ -5,6 +5,42 @@ 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);
});
});
group('StringConvert::extractStrings::', () {
group('Basic Functionality', () {
test('should extract strings separated by spaces', () {