-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathstateFiltersSpec.ts
125 lines (113 loc) · 3.12 KB
/
stateFiltersSpec.ts
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
119
120
121
122
123
124
125
import * as angular from 'angular';
declare var inject;
const module = angular['mock'].module;
describe('isState filter', function () {
beforeEach(module('ui.router'));
beforeEach(
module(function ($stateProvider) {
$stateProvider.state('a', { url: '/' }).state('a.b', { url: '/b' }).state('with-param', { url: '/with/:param' });
})
);
it('should return true if the current state exactly matches the input state', inject(function (
$parse,
$state,
$q,
$rootScope
) {
$state.go('a');
$q.flush();
expect($parse('"a" | isState')($rootScope)).toBe(true);
}));
it('should return false if the current state does not exactly match the input state', inject(function (
$parse,
$q,
$state,
$rootScope
) {
$state.go('a.b');
$q.flush();
expect($parse('"a" | isState')($rootScope)).toBe(false);
}));
it('should return true if the current state and param matches the input state', inject(function (
$parse,
$state,
$q,
$rootScope
) {
$state.go('with-param', { param: 'a' });
$q.flush();
expect($parse('"with-param" | isState: {param: "a"}')($rootScope)).toBe(true);
}));
it('should return false if the current state and param does not match the input state', inject(function (
$parse,
$state,
$q,
$rootScope
) {
$state.go('with-param', { param: 'b' });
$q.flush();
expect($parse('"with-param" | isState: {param: "a"}')($rootScope)).toBe(false);
}));
});
describe('includedByState filter', function () {
beforeEach(module('ui.router'));
beforeEach(
module(function ($stateProvider) {
$stateProvider
.state('a', { url: '/' })
.state('a.b', { url: '/b' })
.state('c', { url: '/c' })
.state('d', { url: '/d/:id' });
})
);
it('should return true if the current state exactly matches the input state', inject(function (
$parse,
$state,
$q,
$rootScope
) {
$state.go('a');
$q.flush();
expect($parse('"a" | includedByState')($rootScope)).toBe(true);
}));
it('should return true if the current state includes the input state', inject(function (
$parse,
$state,
$q,
$rootScope
) {
$state.go('a.b');
$q.flush();
expect($parse('"a" | includedByState')($rootScope)).toBe(true);
}));
it('should return false if the current state does not include input state', inject(function (
$parse,
$state,
$q,
$rootScope
) {
$state.go('c');
$q.flush();
expect($parse('"a" | includedByState')($rootScope)).toBe(false);
}));
it('should return true if the current state include input state and params', inject(function (
$parse,
$state,
$q,
$rootScope
) {
$state.go('d', { id: 123 });
$q.flush();
expect($parse('"d" | includedByState:{ id: 123 }')($rootScope)).toBe(true);
}));
it('should return false if the current state does not include input state and params', inject(function (
$parse,
$state,
$q,
$rootScope
) {
$state.go('d', { id: 2377 });
$q.flush();
expect($parse('"d" | includedByState:{ id: 123 }')($rootScope)).toBe(false);
}));
});