/
basic_test.js
181 lines (159 loc) · 5.82 KB
/
basic_test.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { Route, NoneLocation } from '@ember/-internals/routing';
import { set } from '@ember/-internals/metal';
import { RouterTestCase, moduleFor } from 'internal-test-helpers';
import { EMBER_ROUTING_ROUTER_SERVICE } from '@ember/canary-features';
moduleFor(
'Router Service - main',
class extends RouterTestCase {
['@test RouterService#currentRouteName is correctly set for top level route'](assert) {
if (EMBER_ROUTING_ROUTER_SERVICE) {
assert.expect(6);
} else {
assert.expect(1);
}
return this.visit('/').then(() => {
if (EMBER_ROUTING_ROUTER_SERVICE) {
let currentRoute = this.routerService.currentRoute;
let { name, localName, params, paramNames, queryParams } = currentRoute;
assert.equal(name, 'parent.index');
assert.equal(localName, 'index');
assert.deepEqual(params, {});
assert.deepEqual(queryParams, {});
assert.deepEqual(paramNames, []);
}
assert.equal(this.routerService.get('currentRouteName'), 'parent.index');
});
}
['@test RouterService#currentRouteName is correctly set for child route'](assert) {
if (EMBER_ROUTING_ROUTER_SERVICE) {
assert.expect(6);
} else {
assert.expect(1);
}
return this.visit('/child').then(() => {
if (EMBER_ROUTING_ROUTER_SERVICE) {
let currentRoute = this.routerService.currentRoute;
let { name, localName, params, paramNames, queryParams } = currentRoute;
assert.equal(name, 'parent.child');
assert.equal(localName, 'child');
assert.deepEqual(params, {});
assert.deepEqual(queryParams, {});
assert.deepEqual(paramNames, []);
}
assert.equal(this.routerService.get('currentRouteName'), 'parent.child');
});
}
['@test RouterService#currentRouteName is correctly set after transition'](assert) {
if (EMBER_ROUTING_ROUTER_SERVICE) {
assert.expect(5);
} else {
assert.expect(1);
}
return this.visit('/child')
.then(() => {
if (EMBER_ROUTING_ROUTER_SERVICE) {
let currentRoute = this.routerService.currentRoute;
let { name, localName } = currentRoute;
assert.equal(name, 'parent.child');
assert.equal(localName, 'child');
}
return this.routerService.transitionTo('parent.sister');
})
.then(() => {
if (EMBER_ROUTING_ROUTER_SERVICE) {
let currentRoute = this.routerService.currentRoute;
let { name, localName } = currentRoute;
assert.equal(name, 'parent.sister');
assert.equal(localName, 'sister');
}
assert.equal(this.routerService.get('currentRouteName'), 'parent.sister');
});
}
'@test substates survive aborts GH#17430'(assert) {
assert.expect(2);
this.add(
`route:parent.child`,
Route.extend({
beforeModel(transition) {
transition.abort();
this.intermediateTransitionTo('parent.sister');
},
})
);
return this.visit('/')
.then(() => {
return this.routerService.transitionTo('/child');
})
.catch(e => {
assert.equal(this.routerService.currentRouteName, 'parent.sister');
assert.equal(e.message, 'TransitionAborted');
});
}
['@test RouterService#currentRouteName is correctly set on each transition'](assert) {
if (EMBER_ROUTING_ROUTER_SERVICE) {
assert.expect(9);
} else {
assert.expect(3);
}
return this.visit('/child')
.then(() => {
if (EMBER_ROUTING_ROUTER_SERVICE) {
let currentRoute = this.routerService.currentRoute;
let { name, localName } = currentRoute;
assert.equal(name, 'parent.child');
assert.equal(localName, 'child');
}
assert.equal(this.routerService.get('currentRouteName'), 'parent.child');
return this.visit('/sister');
})
.then(() => {
if (EMBER_ROUTING_ROUTER_SERVICE) {
let currentRoute = this.routerService.currentRoute;
let { name, localName } = currentRoute;
assert.equal(name, 'parent.sister');
assert.equal(localName, 'sister');
}
assert.equal(this.routerService.get('currentRouteName'), 'parent.sister');
return this.visit('/brother');
})
.then(() => {
if (EMBER_ROUTING_ROUTER_SERVICE) {
let currentRoute = this.routerService.currentRoute;
let { name, localName } = currentRoute;
assert.equal(name, 'parent.brother');
assert.equal(localName, 'brother');
}
assert.equal(this.routerService.get('currentRouteName'), 'parent.brother');
});
}
['@test RouterService#rootURL is correctly set to the default value'](assert) {
assert.expect(1);
return this.visit('/').then(() => {
assert.equal(this.routerService.get('rootURL'), '/');
});
}
['@test RouterService#rootURL is correctly set to a custom value'](assert) {
assert.expect(1);
this.add(
'route:parent.index',
Route.extend({
init() {
this._super();
set(this._router, 'rootURL', '/homepage');
},
})
);
return this.visit('/').then(() => {
assert.equal(this.routerService.get('rootURL'), '/homepage');
});
}
['@test RouterService#location is correctly delegated from router:main'](assert) {
assert.expect(2);
return this.visit('/').then(() => {
let location = this.routerService.get('location');
assert.ok(location);
assert.ok(location instanceof NoneLocation);
});
}
}
);