-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroute_parser_test.dart
More file actions
96 lines (89 loc) · 3.21 KB
/
route_parser_test.dart
File metadata and controls
96 lines (89 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:theseus_navigator/theseus_navigator.dart';
import 'package:theseus_navigator/src/route_parser.dart';
import 'common/index.dart';
void main() {
late NavigationScheme navigationScheme;
late NavigationScheme navigationSchemeNoError;
late TheseusRouteInformationParser parser;
late TheseusRouteInformationParser parserNoError;
group('TheseusRouteInformationParser', () {
setUp(() {
navigationScheme = NavigationScheme(
destinations: [
TestDestinations.home,
TestDestinations.categoriesTyped,
TestDestinations.about,
],
errorDestination: TestDestinations.error,
);
navigationSchemeNoError = NavigationScheme(
destinations: [
TestDestinations.home,
TestDestinations.categoriesTyped,
TestDestinations.about,
],
);
parser = TheseusRouteInformationParser(
navigationScheme: navigationScheme,
);
parserNoError = TheseusRouteInformationParser(
navigationScheme: navigationSchemeNoError,
);
});
test('Parsing supported uri should return a destination', () async {
expect(
await parser
.parseRouteInformation(RouteInformation(uri: Uri.parse('/home'))),
TestDestinations.home);
});
test('Parsing not supported uri should return an error destination',
() async {
expect(
await parser.parseRouteInformation(
RouteInformation(uri: Uri.parse('/home2'))),
TestDestinations.error);
});
test(
'Throw exception when parsing not supported uri and error destination is not provided',
() async {
expect(
() async => await parserNoError.parseRouteInformation(
RouteInformation(uri: Uri.parse('/home2'))),
throwsA(isA<UnknownUriException>()));
});
test(
'Parsing supported uri which contains wrong parameter values should return an error destination',
() async {
expect(
await parser.parseRouteInformation(
RouteInformation(uri: Uri.parse('/categories/10'))),
TestDestinations.error);
});
test(
'Throw exception when parsing supported uri which contains wrong parameter values, and the error destination is not provided',
() async {
expect(
() async => await parserNoError.parseRouteInformation(
RouteInformation(uri: Uri.parse('/categories/10'))),
throwsA(isA<UnknownUriException>()));
});
test('Restore route information from the destination', () {
expect(parser.restoreRouteInformation(TestDestinations.home)?.uri.toString(),
'/home');
});
test(
'Do not restore route information for the destination when updating history is disabled in destination settings',
() {
expect(
parser
.restoreRouteInformation(TestDestinations.login.withSettings(
TestDestinations.login.settings
.copyWith(updateHistory: false)))
?.uri.toString(),
null);
});
});
}