forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request emberjs#15414 from rwjblue/router-service-is-active
[FEATURE ember-routing-router-service] isActive and Cleanup
- Loading branch information
Showing
9 changed files
with
362 additions
and
36 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
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
109 changes: 109 additions & 0 deletions
109
packages/ember/tests/routing/router_service_test/isActive_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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { | ||
Controller, | ||
inject, | ||
String | ||
} from 'ember-runtime'; | ||
import { Component } from 'ember-glimmer'; | ||
import { Route, NoneLocation } from 'ember-routing'; | ||
import { | ||
get, | ||
set | ||
} from 'ember-metal'; | ||
import { | ||
RouterTestCase, | ||
moduleFor | ||
} from 'internal-test-helpers'; | ||
|
||
import { EMBER_ROUTING_ROUTER_SERVICE } from 'ember/features'; | ||
|
||
if (EMBER_ROUTING_ROUTER_SERVICE) { | ||
moduleFor('Router Service - isActive', class extends RouterTestCase { | ||
['@test RouterService#isActive returns true for simple route'](assert) { | ||
assert.expect(1); | ||
|
||
return this.visit('/') | ||
.then(() => { | ||
return this.routerService.transitionTo('parent.child'); | ||
}) | ||
.then(() => { | ||
return this.routerService.transitionTo('parent.sister'); | ||
}) | ||
.then(() => { | ||
assert.ok(this.routerService.isActive('parent.sister')); | ||
}); | ||
} | ||
|
||
['@test RouterService#isActive returns true for simple route with dynamic segments'](assert) { | ||
assert.expect(1); | ||
|
||
let dynamicModel = { id: 1 }; | ||
|
||
return this.visit('/') | ||
.then(() => { | ||
return this.routerService.transitionTo('dynamic', dynamicModel); | ||
}) | ||
.then(() => { | ||
assert.ok(this.routerService.isActive('dynamic', dynamicModel)); | ||
}); | ||
} | ||
|
||
['@test RouterService#isActive does not eagerly instantiate controller for query params'](assert) { | ||
assert.expect(1); | ||
|
||
let queryParams = this.buildQueryParams({ sort: 'ASC' }); | ||
|
||
this.add('controller:parent.sister', Controller.extend({ | ||
queryParams: ['sort'], | ||
sort: 'ASC', | ||
|
||
init() { | ||
assert.ok(false, 'should never create'); | ||
this._super(...arguments); | ||
} | ||
})); | ||
|
||
return this.visit('/') | ||
.then(() => { | ||
return this.routerService.transitionTo('parent.brother'); | ||
}) | ||
.then(() => { | ||
assert.notOk(this.routerService.isActive('parent.sister', queryParams)); | ||
}); | ||
} | ||
|
||
['@test RouterService#isActive is correct for simple route with basic query params'](assert) { | ||
assert.expect(2); | ||
|
||
let queryParams = this.buildQueryParams({ sort: 'ASC' }); | ||
|
||
this.add('controller:parent.child', Controller.extend({ | ||
queryParams: ['sort'], | ||
sort: 'ASC' | ||
}) | ||
); | ||
|
||
return this.visit('/') | ||
.then(() => { | ||
return this.routerService.transitionTo('parent.child', queryParams); | ||
}) | ||
.then(() => { | ||
assert.ok(this.routerService.isActive('parent.child', queryParams)); | ||
assert.notOk(this.routerService.isActive('parent.child', this.buildQueryParams({ sort: 'DESC' }))); | ||
}); | ||
} | ||
|
||
['@test RouterService#isActive for simple route with array as query params'](assert) { | ||
assert.expect(1); | ||
|
||
let queryParams = this.buildQueryParams({ sort: ['ascending'] }); | ||
|
||
return this.visit('/') | ||
.then(() => { | ||
return this.routerService.transitionTo('parent.child', queryParams); | ||
}) | ||
.then(() => { | ||
assert.notOk(this.routerService.isActive('parent.child', this.buildQueryParams({ sort: 'descending' }))); | ||
}); | ||
} | ||
}); | ||
} |
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
Oops, something went wrong.