TF-3278 Handle open app via deep link at MailboxDashboard screen
This commit is contained in:
@@ -52,6 +52,7 @@ export 'utils/broadcast_channel/broadcast_channel.dart';
|
||||
export 'utils/list_utils.dart';
|
||||
export 'utils/mail/domain.dart';
|
||||
export 'utils/mail/mail_address.dart';
|
||||
export 'utils/application_manager.dart';
|
||||
export 'utils/preview_eml_file_utils.dart';
|
||||
|
||||
// Views
|
||||
|
||||
@@ -2,7 +2,18 @@ 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));
|
||||
}
|
||||
|
||||
dynamic foldSuccessWithResult<T>() {
|
||||
return fold(
|
||||
(failure) => failure,
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'app_logger.dart';
|
||||
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/domain/exceptions/string_exception.dart';
|
||||
|
||||
class StringConvert {
|
||||
@@ -17,6 +16,15 @@ class StringConvert {
|
||||
return text ?? '';
|
||||
}
|
||||
|
||||
static String decodeBase64ToString(String text) {
|
||||
try {
|
||||
return utf8.decode(base64Decode(text));
|
||||
} catch (e) {
|
||||
logError('StringConvert::decodeBase64ToString:Exception = $e');
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
static List<String> extractStrings(String input) {
|
||||
try {
|
||||
// Check if the input is URL encoded
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -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', () {
|
||||
|
||||
Reference in New Issue
Block a user