|
1 | 1 | import { RSVP } from '@ember/-internals/runtime';
|
2 | 2 | import { Route } from '@ember/-internals/routing';
|
| 3 | +import Controller from '@ember/controller'; |
| 4 | + |
3 | 5 | import { moduleFor, ApplicationTestCase, runTask } from 'internal-test-helpers';
|
4 | 6 |
|
5 | 7 | let counter;
|
@@ -193,6 +195,155 @@ moduleFor(
|
193 | 195 | });
|
194 | 196 | }
|
195 | 197 |
|
| 198 | + ['@test Enter loading route with correct query parameters'](assert) { |
| 199 | + let deferred = RSVP.defer(); |
| 200 | + |
| 201 | + this.router.map(function () { |
| 202 | + this.route('dummy'); |
| 203 | + }); |
| 204 | + |
| 205 | + this.add( |
| 206 | + 'route:dummy', |
| 207 | + Route.extend({ |
| 208 | + model() { |
| 209 | + step(assert, 1, 'DummyRoute#model'); |
| 210 | + return deferred.promise; |
| 211 | + }, |
| 212 | + }) |
| 213 | + ); |
| 214 | + |
| 215 | + this.add( |
| 216 | + 'controller:application', |
| 217 | + class extends Controller { |
| 218 | + queryParams = ['qux']; |
| 219 | + |
| 220 | + qux = 'initial'; |
| 221 | + } |
| 222 | + ); |
| 223 | + |
| 224 | + this.add( |
| 225 | + 'route:loading', |
| 226 | + Route.extend({ |
| 227 | + setupController() { |
| 228 | + step(assert, 2, 'LoadingRoute#setupController'); |
| 229 | + }, |
| 230 | + }) |
| 231 | + ); |
| 232 | + this.addTemplate('dummy', 'DUMMY'); |
| 233 | + |
| 234 | + return this.visit('/?qux=updated').then(() => { |
| 235 | + assert.equal( |
| 236 | + this.getController('application').qux, |
| 237 | + 'updated', |
| 238 | + 'the application controller has the correct qp value' |
| 239 | + ); |
| 240 | + |
| 241 | + let promise = this.visit('/dummy?qux=updated').then(() => { |
| 242 | + let text = this.$('#app').text(); |
| 243 | + |
| 244 | + assert.equal(text, 'DUMMY', `dummy template has been rendered`); |
| 245 | + assert.equal( |
| 246 | + this.getController('application').qux, |
| 247 | + 'updated', |
| 248 | + 'the application controller has the correct qp value' |
| 249 | + ); |
| 250 | + }); |
| 251 | + |
| 252 | + assert.equal(this.currentPath, 'loading', `loading state entered`); |
| 253 | + assert.equal( |
| 254 | + this.currentURL, |
| 255 | + '/dummy?qux=updated', |
| 256 | + `during loading url reflect the correct state` |
| 257 | + ); |
| 258 | + assert.equal( |
| 259 | + this.getController('application').qux, |
| 260 | + 'updated', |
| 261 | + 'the application controller has the correct qp value' |
| 262 | + ); |
| 263 | + |
| 264 | + deferred.resolve(); |
| 265 | + |
| 266 | + return promise; |
| 267 | + }); |
| 268 | + } |
| 269 | + |
| 270 | + ['@test Enter child-loading route with correct query parameters'](assert) { |
| 271 | + assert.expect(9); |
| 272 | + let deferred = RSVP.defer(); |
| 273 | + |
| 274 | + this.router.map(function () { |
| 275 | + this.route('parent', function () { |
| 276 | + this.route('child'); |
| 277 | + }); |
| 278 | + }); |
| 279 | + |
| 280 | + this.add( |
| 281 | + 'route:parent.child', |
| 282 | + Route.extend({ |
| 283 | + model() { |
| 284 | + step(assert, 1, 'ChildRoute#model'); |
| 285 | + return deferred.promise; |
| 286 | + }, |
| 287 | + }) |
| 288 | + ); |
| 289 | + |
| 290 | + this.add( |
| 291 | + 'controller:parent', |
| 292 | + class extends Controller { |
| 293 | + queryParams = ['qux']; |
| 294 | + |
| 295 | + qux = 'initial'; |
| 296 | + } |
| 297 | + ); |
| 298 | + |
| 299 | + this.add( |
| 300 | + 'route:parent.child_loading', |
| 301 | + Route.extend({ |
| 302 | + setupController() { |
| 303 | + step(assert, 2, 'ChildLoadingRoute#setupController'); |
| 304 | + }, |
| 305 | + }) |
| 306 | + ); |
| 307 | + this.addTemplate('parent', 'PARENT {{outlet}}'); |
| 308 | + |
| 309 | + this.addTemplate('parent.child', 'CHILD'); |
| 310 | + |
| 311 | + return this.visit('/parent?qux=updated').then(() => { |
| 312 | + assert.equal( |
| 313 | + this.getController('parent').qux, |
| 314 | + 'updated', |
| 315 | + 'in the parent route, the parent controller has the correct qp value' |
| 316 | + ); |
| 317 | + |
| 318 | + let promise = this.visit('/parent/child?qux=updated').then(() => { |
| 319 | + let text = this.$('#app').text(); |
| 320 | + |
| 321 | + assert.equal(text, 'PARENT CHILD', `child template has been rendered`); |
| 322 | + assert.equal( |
| 323 | + this.getController('parent').qux, |
| 324 | + 'updated', |
| 325 | + 'after entered in the parent.child route, the parent controller has the correct qp value' |
| 326 | + ); |
| 327 | + }); |
| 328 | + |
| 329 | + assert.equal(this.currentPath, 'parent.child_loading', `child loading state entered`); |
| 330 | + assert.equal( |
| 331 | + this.currentURL, |
| 332 | + '/parent/child?qux=updated', |
| 333 | + `during child loading, url reflect the correct state` |
| 334 | + ); |
| 335 | + assert.equal( |
| 336 | + this.getController('parent').qux, |
| 337 | + 'updated', |
| 338 | + 'in the child_loading route, the parent controller has the correct qp value' |
| 339 | + ); |
| 340 | + |
| 341 | + deferred.resolve(); |
| 342 | + |
| 343 | + return promise; |
| 344 | + }); |
| 345 | + } |
| 346 | + |
196 | 347 | ['@test Slow promises returned from ApplicationRoute#model enter ApplicationLoadingRoute if present'](
|
197 | 348 | assert
|
198 | 349 | ) {
|
|
0 commit comments