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.
[BUGFIX beta] sets the controller _qpDelegate
before mapping all the queryParams. In certain scenarios, if query params are shared through a service, bound query params will fire the _qpDelegate while transitioning to a new controller if the property has been modified from it's default value. Loosely related to - emberjs#11592 Based on a previous PR - emberjs#13981
- Loading branch information
Showing
2 changed files
with
79 additions
and
2 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
76 changes: 76 additions & 0 deletions
76
packages/ember/tests/routing/query_params_test/shared_state_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,76 @@ | ||
import { | ||
Controller, | ||
Service | ||
} from 'ember-runtime'; | ||
import Ember from 'ember'; | ||
import { run } from 'ember-metal'; | ||
import { jQuery } from 'ember-views'; | ||
import { QueryParamTestCase, moduleFor } from 'internal-test-helpers'; | ||
|
||
moduleFor('Query Params - shared service state', class extends QueryParamTestCase { | ||
|
||
boot() { | ||
this.setupApplication(); | ||
return this.visitApplication(); | ||
} | ||
|
||
setupApplication() { | ||
this.router.map(function() { | ||
this.route('home', { path: '/' }); | ||
this.route('dashboard'); | ||
}); | ||
|
||
this.application.register('service:filters', Service.extend({ | ||
shared: true | ||
})); | ||
|
||
this.registerController('home', Controller.extend({ | ||
filters: Ember.inject.service() | ||
})); | ||
|
||
this.registerController('dashboard', Controller.extend({ | ||
filters: Ember.inject.service(), | ||
queryParams: [ | ||
{ 'filters.shared': 'shared' } | ||
] | ||
})); | ||
|
||
this.registerTemplate('application', `{{link-to 'Home' 'home' }} <div> {{outlet}} </div>`); | ||
this.registerTemplate('home', `{{link-to 'Dashboard' 'dashboard' }}{{input type="checkbox" id='filters-checkbox' checked=(mut filters.shared) }}`); | ||
this.registerTemplate('dashboard', `{{link-to 'Home' 'home' }}`); | ||
} | ||
visitApplication() { | ||
return this.visit('/'); | ||
} | ||
|
||
['@test can modify shared state before transition'](assert) { | ||
assert.expect(1); | ||
|
||
return this.boot().then(() => { | ||
this.$input = jQuery('#filters-checkbox'); | ||
|
||
// click the checkbox once to set filters.shared to false | ||
run(this.$input, 'click'); | ||
|
||
return this.visit('/dashboard').then(() => { | ||
assert.ok(true, 'expecting navigating to dashboard to succeed'); | ||
}); | ||
}); | ||
} | ||
|
||
['@test can modify shared state back to the default value before transition'](assert) { | ||
assert.expect(1); | ||
|
||
return this.boot().then(() => { | ||
this.$input = jQuery('#filters-checkbox'); | ||
|
||
// click the checkbox twice to set filters.shared to false and back to true | ||
run(this.$input, 'click'); | ||
run(this.$input, 'click'); | ||
|
||
return this.visit('/dashboard').then(() => { | ||
assert.ok(true, 'expecting navigating to dashboard to succeed'); | ||
}); | ||
}); | ||
} | ||
}); |