-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdestination_test.dart
More file actions
108 lines (105 loc) · 4.99 KB
/
destination_test.dart
File metadata and controls
108 lines (105 loc) · 4.99 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
import 'package:flutter/foundation.dart' hide Category;
import 'package:flutter_test/flutter_test.dart';
import 'package:theseus_navigator/theseus_navigator.dart';
import 'common/index.dart';
void main() {
group('Destination', () {
test('Equality', () {
final categoryParametersId1 =
DestinationParameters(<String, String>{'id': '1'});
final categoryParametersId2 =
DestinationParameters(<String, String>{'id': '2'});
final categoryParametersId1Q1 =
DestinationParameters(<String, String>{'id': '1', 'q': '1'});
expect(TestDestinations.home == TestDestinations.home, true);
expect(TestDestinations.home == TestDestinations.about, false);
expect(TestDestinations.categories == TestDestinations.categories, true);
expect(
TestDestinations.categories.withParameters(categoryParametersId1) ==
TestDestinations.categories.withParameters(categoryParametersId1),
true);
expect(
TestDestinations.categories.withParameters(categoryParametersId1) ==
TestDestinations.categories.withParameters(categoryParametersId2),
false);
expect(
TestDestinations.categories.withParameters(categoryParametersId1) ==
TestDestinations.categories
.withParameters(categoryParametersId1Q1),
false);
expect(TestDestinations.home != TestDestinations.about, true);
});
test('Matching URI', () {
final destination1 = TestDestinations.categories;
final destination2 = destination1
.withParameters(DestinationParameters(<String, String>{'id': '1'}));
expect(destination1.isMatch('/categories/1'), true);
expect(destination1.isMatch('/categories'), true);
expect(destination1.isMatch('/home'), false);
expect(destination2.isMatch('/categories/1'), true);
});
test('Parsing URI', () async {
final destination1 = TestDestinations.categories;
final destination2 = destination1
.withParameters(DestinationParameters(<String, String>{'id': '1'}));
final destination3 = destination1
.withParameters(DestinationParameters(<String, String>{'id': '2'}));
expect(await destination1.parse('/categories/1') == destination2, true);
expect(await destination1.parse('/categories/1') == destination3, false);
});
test('Parsing URI - typed parameters', () async {
final destination1 = TestDestinations.categoriesTyped;
const parentCategory1 = Category(id: 1, name: 'Category 1');
const parentCategory2 = Category(id: 2, name: 'Category 2');
final destination2 = destination1
.withParameters(CategoriesParameters(parent: parentCategory1));
final destination3 = destination1
.withParameters(CategoriesParameters(parent: parentCategory2));
final result = await destination1.parse('/categories/1');
expect(result == destination2, true);
expect(result.parameters is CategoriesParameters, true);
expect(result.parameters!.parent == parentCategory1, true);
expect(result == destination3, false);
});
test('Applying parameters', () async {
final destination1 = TestDestinations.categories;
final categoryParametersId1 =
DestinationParameters(<String, String>{'id': '1'});
final destination2 = destination1.withParameters(categoryParametersId1);
expect(destination2.parameters is CategoriesParameters, false);
expect(destination2.parameters!.map.isNotEmpty, true);
expect(
mapEquals(destination2.parameters!.map, <String, String>{'id': '1'}),
true);
});
test('Applying parameters - Typed parameters', () async {
final destination1 = TestDestinations.categoriesTyped;
const parentCategory1 = Category(id: 1, name: 'Category 1');
final destination2 = destination1
.withParameters(CategoriesParameters(parent: parentCategory1));
expect(destination2.parameters is CategoriesParameters, true);
expect(destination2.parameters!.map.isNotEmpty, true);
expect(
mapEquals(
destination2.parameters!.map, <String, String>{'parentId': '1'}),
true);
});
test('Settings to display a dialog', () async {
final destination1 = TestDestinations.aboutWithDialogSettings;
expect(destination1.settings.transitionMethod, TransitionMethod.push);
expect(destination1.settings.transition,
DestinationTransition.materialDialog);
});
test('Settings without visual effects on transition', () async {
final destination1 = TestDestinations.aboutWithQuietSettings;
expect(destination1.settings.transitionMethod, TransitionMethod.replace);
expect(destination1.settings.transition, DestinationTransition.none);
});
});
group('Destination Parameters', () {
test('Reserved parameters', () {
expect(DestinationParameters.isReservedParameter('id'), false);
expect(DestinationParameters.isReservedParameter('state'), true);
});
});
}