-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathstateFiltersSpec.js
64 lines (55 loc) · 2.28 KB
/
stateFiltersSpec.js
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
var module = angular.mock.module;
var uiRouter = require("ui-router");
describe('isState filter', function() {
beforeEach(module('ui.router'));
beforeEach(module(function($stateProvider) {
$stateProvider
.state('a', { url: '/' })
.state('a.b', { url: '/b' });
}));
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);
}));
});
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);
}));
});