-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrouter_delegate_test.dart
More file actions
118 lines (104 loc) · 3.88 KB
/
router_delegate_test.dart
File metadata and controls
118 lines (104 loc) · 3.88 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// ignore_for_file: invalid_use_of_protected_member
import 'package:flutter_test/flutter_test.dart';
import 'package:theseus_navigator/theseus_navigator.dart';
import 'package:theseus_navigator/src/router_delegate.dart';
import 'common/index.dart';
void main() {
late NavigationScheme navigationScheme;
late TheseusRouterDelegate delegate;
late List<String> log;
TestWidgetsFlutterBinding.ensureInitialized();
void currentDestinationListener() {
log.add(navigationScheme.currentDestination.uri);
}
group('TheseusRouterDelegate', () {
setUp(() {
navigationScheme = NavigationScheme(
destinations: [
TestDestinations.home,
TestDestinations.about,
TestDestinations.categoriesTyped,
],
errorDestination: TestDestinations.error,
);
delegate = navigationScheme.routerDelegate;
log = <String>[];
navigationScheme.addListener(currentDestinationListener);
});
group('Set new route by the platform', () {
test('New route is pushed to the app', () async {
await delegate.setNewRoutePath(TestDestinations.about);
expect(delegate.currentConfiguration, TestDestinations.about);
expect(navigationScheme.currentDestination, TestDestinations.about);
expect(
navigationScheme
.findNavigator(navigationScheme.currentDestination)
?.stack
.length,
1);
});
test(
'New route with custom "upwardDestinationBuilder" is pushed to the app',
() async {
final destination = TestDestinations.categoriesTyped.withParameters(
CategoriesParameters(parent: categoriesDataSource[1]));
await delegate.setNewRoutePath(destination);
expect(navigationScheme.currentDestination, destination);
expect(
navigationScheme
.findNavigator(navigationScheme.currentDestination)
?.stack
.length,
2);
});
test(
'Pushing the same route as the current one should not cause notifying router delegate by navigation scheme',
() async {
// Navigation scheme notifies once on initialization
expect(log.length, 0);
final destination = TestDestinations.home;
await delegate.setNewRoutePath(destination);
expect(log.length, 0);
expect(navigationScheme.currentDestination, destination);
expect(
navigationScheme
.findNavigator(navigationScheme.currentDestination)
?.stack
.length,
1);
});
});
group('Pop route', () {
test(
'Popping the only route should keep the current destination on non-Android platform',
() async {
final result = await delegate.popRoute();
expect(result, true);
expect(navigationScheme.currentDestination, TestDestinations.home);
});
test(
'Popping the current route should set the current destination to previous one',
() async {
await navigationScheme.goTo(TestDestinations.about);
expect(navigationScheme.currentDestination, TestDestinations.about);
expect(
navigationScheme
.findNavigator(navigationScheme.currentDestination)
?.stack
.length,
2);
final result = await delegate.popRoute();
expect(result, true);
expect(navigationScheme.currentDestination, TestDestinations.home);
});
});
group('Service', () {
test('Stop listen to navigation scheme on dispose', () async {
expect(navigationScheme.hasListeners, true);
navigationScheme.removeListener(currentDestinationListener);
navigationScheme.routerDelegate.dispose();
expect(navigationScheme.hasListeners, false);
});
});
});
}