Skip to content

Commit

Permalink
Merge pull request #14068 from alisdair/fix-link-to-query-params-unde…
Browse files Browse the repository at this point in the history
…fined

Default queryParams for link-to must have values
  • Loading branch information
rwjblue authored Aug 15, 2016
2 parents 574b64b + 266474d commit 07cc789
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/components/link-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ const LinkComponent = EmberComponent.extend({
if (lastParam && lastParam.isQueryParams) {
queryParams = params.pop();
} else {
queryParams = {};
queryParams = { values: {} };
}
this.set('queryParams', queryParams);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Application from 'ember-application/system/application';
import jQuery from 'ember-views/system/jquery';
import NoneLocation from 'ember-routing/location/none_location';
import { setTemplates, set as setTemplate } from 'ember-templates/template_registry';
import RSVP from 'ember-runtime/ext/rsvp';

let Router, App, router, registry, container;

Expand Down Expand Up @@ -876,4 +877,63 @@ if (isEnabled('ember-routing-route-configured-query-params')) {
jQuery('#app-link').click();
equal(router.get('location.path'), '/parent');
});

QUnit.test('link-to default query params while in active transition regression test', function() {
App.Router.map(function() {
this.route('foos');
this.route('bars');
});
let foos = RSVP.defer();
let bars = RSVP.defer();

setTemplate('application', compile(`
{{link-to 'Foos' 'foos' id='foos-link'}}
{{link-to 'Baz Foos' 'foos' (query-params baz=true) id='baz-foos-link'}}
{{link-to 'Quux Bars' 'bars' (query-params quux=true) id='bars-link'}}
`));

App.FoosController = Controller.extend({
queryParams: ['status'],
baz: false
});

App.FoosRoute = Route.extend({
model() {
return foos.promise;
}
});

App.BarsController = Controller.extend({
queryParams: ['status'],
quux: false
});

App.BarsRoute = Route.extend({
model() {
return bars.promise;
}
});

bootApplication();
equal(jQuery('#foos-link').attr('href'), '/foos');
equal(jQuery('#baz-foos-link').attr('href'), '/foos?baz=true');
equal(jQuery('#bars-link').attr('href'), '/bars?quux=true');

equal(router.get('location.path'), '');

shouldNotBeActive('#foos-link');
shouldNotBeActive('#baz-foos-link');
shouldNotBeActive('#bars-link');

run(jQuery('#bars-link'), 'click');
shouldNotBeActive('#bars-link');

run(jQuery('#foos-link'), 'click');
shouldNotBeActive('#foos-link');

run(foos, 'resolve');

equal(router.get('location.path'), '/foos');
shouldBeActive('#foos-link');
});
}

0 comments on commit 07cc789

Please sign in to comment.