Skip to content

Commit

Permalink
TF-2168 Add unit-test for parseMapMailtoFromUri
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Sep 27, 2023
1 parent c559dae commit b8974ee
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/main/routes/route_utils_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:tmail_ui_user/main/routes/app_routes.dart';
import 'package:tmail_ui_user/main/routes/route_utils.dart';

void main() {
group('parseMapMailtoFromUri test', () {
test('should parse a valid mailto URI', () {
const mailtoUri = 'mailto:[email protected]?subject=Hello';
final result = RouteUtils.parseMapMailtoFromUri(mailtoUri);

expect(result[RouteUtils.paramRouteName], equals(AppRoutes.mailtoURL));
expect(result[RouteUtils.paramMailtoAddress], equals('[email protected]'));
expect(result[RouteUtils.paramSubject], equals('Hello'));
});

test('should parse a valid mailto URI encoded', () {
const mailtoUri = 'mailto:test%40example.com%3Fsubject=Hello';
final result = RouteUtils.parseMapMailtoFromUri(mailtoUri);

expect(result[RouteUtils.paramRouteName], equals(AppRoutes.mailtoURL));
expect(result[RouteUtils.paramMailtoAddress], equals('[email protected]'));
expect(result[RouteUtils.paramSubject], equals('Hello'));
});

test('should handle a mailto URI without subject', () {
const mailtoUri = 'mailto:[email protected]';
final result = RouteUtils.parseMapMailtoFromUri(mailtoUri);

expect(result[RouteUtils.paramRouteName], equals(AppRoutes.mailtoURL));
expect(result[RouteUtils.paramMailtoAddress], equals('[email protected]'));
expect(result[RouteUtils.paramSubject], isNull);
});

test('should handle a mailto URI without subject encoded', () {
const mailtoUri = 'mailto:test%40example.com';
final result = RouteUtils.parseMapMailtoFromUri(mailtoUri);

expect(result[RouteUtils.paramRouteName], equals(AppRoutes.mailtoURL));
expect(result[RouteUtils.paramMailtoAddress], equals('[email protected]'));
expect(result[RouteUtils.paramSubject], isNull);
});

test('should handle a non-mailto URI', () {
const nonMailtoUri = '[email protected]';
final result = RouteUtils.parseMapMailtoFromUri(nonMailtoUri);

expect(result[RouteUtils.paramRouteName], equals(AppRoutes.mailtoURL));
expect(result[RouteUtils.paramMailtoAddress], equals(nonMailtoUri));
expect(result[RouteUtils.paramSubject], isNull);
});

test('should handle a non-mailto URI encoded', () {
const nonMailtoUri = 'test%40example.com';
final result = RouteUtils.parseMapMailtoFromUri(nonMailtoUri);

expect(result[RouteUtils.paramRouteName], equals(AppRoutes.mailtoURL));
expect(result[RouteUtils.paramMailtoAddress], equals('[email protected]'));
expect(result[RouteUtils.paramSubject], isNull);
});

test('should handle null input', () {
final result = RouteUtils.parseMapMailtoFromUri(null);

expect(result[RouteUtils.paramRouteName], equals(AppRoutes.mailtoURL));
expect(result[RouteUtils.paramMailtoAddress], isNull);
expect(result[RouteUtils.paramSubject], isNull);
});
});
}

0 comments on commit b8974ee

Please sign in to comment.