-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
120 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 82 additions & 79 deletions
161
packages/ember/tests/routing/router_service_test/refresh_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,100 @@ | ||
import { Route } from '@ember/-internals/routing'; | ||
import { EMBER_ROUTING_ROUTER_SERVICE_REFRESH } from '@ember/canary-features'; | ||
import { RouterTestCase, moduleFor } from 'internal-test-helpers'; | ||
|
||
moduleFor( | ||
'Router Service - refresh', | ||
class extends RouterTestCase { | ||
async ['@test RouterService#refresh can be used to re-run the model hooks of active routes']( | ||
assert | ||
) { | ||
let parentCounter = 0; | ||
this.add( | ||
'route:parent', | ||
Route.extend({ | ||
model() { | ||
++parentCounter; | ||
}, | ||
}) | ||
); | ||
if (EMBER_ROUTING_ROUTER_SERVICE_REFRESH) { | ||
moduleFor( | ||
'Router Service - refresh', | ||
class extends RouterTestCase { | ||
async ['@test RouterService#refresh can be used to re-run the model hooks of active routes']( | ||
assert | ||
) { | ||
let parentCounter = 0; | ||
this.add( | ||
'route:parent', | ||
Route.extend({ | ||
model() { | ||
++parentCounter; | ||
}, | ||
}) | ||
); | ||
|
||
let childCounter = 0; | ||
this.add( | ||
'route:parent.child', | ||
Route.extend({ | ||
model() { | ||
++childCounter; | ||
}, | ||
}) | ||
); | ||
let childCounter = 0; | ||
this.add( | ||
'route:parent.child', | ||
Route.extend({ | ||
model() { | ||
++childCounter; | ||
}, | ||
}) | ||
); | ||
|
||
let sisterCounter = 0; | ||
this.add( | ||
'route:parent.sister', | ||
Route.extend({ | ||
model() { | ||
++sisterCounter; | ||
}, | ||
}) | ||
); | ||
let sisterCounter = 0; | ||
this.add( | ||
'route:parent.sister', | ||
Route.extend({ | ||
model() { | ||
++sisterCounter; | ||
}, | ||
}) | ||
); | ||
|
||
await this.visit('/'); | ||
assert.equal(parentCounter, 1); | ||
assert.equal(childCounter, 0); | ||
assert.equal(sisterCounter, 0); | ||
await this.visit('/'); | ||
assert.equal(parentCounter, 1); | ||
assert.equal(childCounter, 0); | ||
assert.equal(sisterCounter, 0); | ||
|
||
await this.routerService.refresh(); | ||
assert.equal(parentCounter, 2); | ||
assert.equal(childCounter, 0); | ||
assert.equal(sisterCounter, 0); | ||
await this.routerService.refresh(); | ||
assert.equal(parentCounter, 2); | ||
assert.equal(childCounter, 0); | ||
assert.equal(sisterCounter, 0); | ||
|
||
await this.routerService.refresh('application'); | ||
assert.equal(parentCounter, 3); | ||
assert.equal(childCounter, 0); | ||
assert.equal(sisterCounter, 0); | ||
await this.routerService.refresh('application'); | ||
assert.equal(parentCounter, 3); | ||
assert.equal(childCounter, 0); | ||
assert.equal(sisterCounter, 0); | ||
|
||
await this.routerService.transitionTo('parent.child'); | ||
assert.equal(parentCounter, 3); | ||
assert.equal(childCounter, 1); | ||
assert.equal(sisterCounter, 0); | ||
await this.routerService.transitionTo('parent.child'); | ||
assert.equal(parentCounter, 3); | ||
assert.equal(childCounter, 1); | ||
assert.equal(sisterCounter, 0); | ||
|
||
await this.routerService.refresh('parent.child'); | ||
assert.equal(parentCounter, 3); | ||
assert.equal(childCounter, 2); | ||
assert.equal(sisterCounter, 0); | ||
await this.routerService.refresh('parent.child'); | ||
assert.equal(parentCounter, 3); | ||
assert.equal(childCounter, 2); | ||
assert.equal(sisterCounter, 0); | ||
|
||
await this.routerService.refresh('parent'); | ||
assert.equal(parentCounter, 4); | ||
assert.equal(childCounter, 3); | ||
assert.equal(sisterCounter, 0); | ||
await this.routerService.refresh('parent'); | ||
assert.equal(parentCounter, 4); | ||
assert.equal(childCounter, 3); | ||
assert.equal(sisterCounter, 0); | ||
|
||
await this.routerService.transitionTo('parent.sister'); | ||
assert.equal(parentCounter, 4); | ||
assert.equal(childCounter, 3); | ||
assert.equal(sisterCounter, 1); | ||
await this.routerService.transitionTo('parent.sister'); | ||
assert.equal(parentCounter, 4); | ||
assert.equal(childCounter, 3); | ||
assert.equal(sisterCounter, 1); | ||
|
||
await this.routerService.refresh(); | ||
assert.equal(parentCounter, 5); | ||
assert.equal(childCounter, 3); | ||
assert.equal(sisterCounter, 2); | ||
} | ||
await this.routerService.refresh(); | ||
assert.equal(parentCounter, 5); | ||
assert.equal(childCounter, 3); | ||
assert.equal(sisterCounter, 2); | ||
} | ||
|
||
async ['@test RouterService#refresh verifies that the provided route exists']() { | ||
await this.visit('/'); | ||
async ['@test RouterService#refresh verifies that the provided route exists']() { | ||
await this.visit('/'); | ||
|
||
expectAssertion(() => { | ||
this.routerService.refresh('this-route-does-not-exist'); | ||
}, 'The route "this-route-does-not-exist" was not found'); | ||
} | ||
expectAssertion(() => { | ||
this.routerService.refresh('this-route-does-not-exist'); | ||
}, 'The route "this-route-does-not-exist" was not found'); | ||
} | ||
|
||
async ['@test RouterService#refresh verifies that the provided route name corresponds with an active route']() { | ||
await this.visit('/'); | ||
async ['@test RouterService#refresh verifies that the provided route name corresponds with an active route']() { | ||
await this.visit('/'); | ||
|
||
expectAssertion(() => { | ||
this.routerService.refresh('parent.child'); | ||
}, 'The route "parent.child" is currently not active'); | ||
expectAssertion(() => { | ||
this.routerService.refresh('parent.child'); | ||
}, 'The route "parent.child" is currently not active'); | ||
} | ||
} | ||
} | ||
); | ||
); | ||
} |