Skip to content

Commit

Permalink
Merge pull request #12058 from cibernox/fix_qps_only_links
Browse files Browse the repository at this point in the history
[BUGFIX release] Fix link-to with only qps linking to outdated route
  • Loading branch information
rwjblue committed Aug 12, 2015
2 parents 9bffc1a + 1b63604 commit 4082280
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ember-routing-views/lib/views/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ var LinkComponent = EmberComponent.extend({
}

var routing = get(this, '_routing');
var targetRouteName = get(this, 'targetRouteName');
var targetRouteName = this._handleOnlyQueryParamsSupplied(get(this, 'targetRouteName'));
var models = get(this, 'models');
var queryParamValues = get(this, 'queryParams.values');
var shouldReplace = get(this, 'attrs.replace');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,56 @@ if (isEnabled('ember-routing-route-configured-query-params')) {
equal(Ember.$('#the-link').attr('href'), '/?bar=BORF&foo=lol');
});

QUnit.test('The {{link-to}} with only query params always transitions to the current route with the query params applied', function() {
// Test harness for bug #12033

Ember.TEMPLATES.cars = compile(
'{{#link-to \'cars.create\' id=\'create-link\'}}Create new car{{/link-to}} ' +
'{{#link-to (query-params page=\'2\') id=\'page2-link\'}}Page 2{{/link-to}}' +
'{{outlet}}'
);

Ember.TEMPLATES['cars/create'] = compile(
'{{#link-to \'cars\' id=\'close-link\'}}Close create form{{/link-to}}'
);

Router.map(function() {
this.route('cars', function() {
this.route('create');
});
});

App.CarsRoute = Ember.Route.extend({
queryParams: {
page: { defaultValue: 1 }
}
});

bootApplication();

Ember.run(function() {
router.handleURL('/cars/create');
});

Ember.run(function() {
equal(router.currentRouteName, 'cars.create');
Ember.$('#close-link').click();
});

Ember.run(function() {
equal(router.currentRouteName, 'cars.index');
equal(router.get('url'), '/cars');
equal(container.lookup('controller:cars').get('page'), 1, 'The page query-param is 1');
Ember.$('#page2-link').click();
});

Ember.run(function() {
equal(router.currentRouteName, 'cars.index', 'The active route is still cars');
equal(router.get('url'), '/cars?page=2', 'The url has been updated');
equal(container.lookup('controller:cars').get('page'), 2, 'The query params have been updated');
});
});

QUnit.test('The {{link-to}} applies activeClass when query params are not changed', function() {
Ember.TEMPLATES.index = compile(
'{{#link-to (query-params foo=\'cat\') id=\'cat-link\'}}Index{{/link-to}} ' +
Expand Down Expand Up @@ -578,6 +628,57 @@ if (isEnabled('ember-routing-route-configured-query-params')) {
equal(Ember.$('#the-link').attr('href'), '/?bar=BORF&foo=lol');
});

QUnit.test('The {{link-to}} with only query params always transitions to the current route with the query params applied', function() {
// Test harness for bug #12033

Ember.TEMPLATES.cars = compile(
'{{#link-to \'cars.create\' id=\'create-link\'}}Create new car{{/link-to}} ' +
'{{#link-to (query-params page=\'2\') id=\'page2-link\'}}Page 2{{/link-to}}' +
'{{outlet}}'
);

Ember.TEMPLATES['cars/create'] = compile(
'{{#link-to \'cars\' id=\'close-link\'}}Close create form{{/link-to}}'
);

Router.map(function() {
this.route('cars', function() {
this.route('create');
});
});

App.CarsController = Ember.Controller.extend({
queryParams: ['page'],
page: 1
});

bootApplication();

var carsController = container.lookup('controller:cars');

Ember.run(function() {
router.handleURL('/cars/create');
});

Ember.run(function() {
equal(router.currentRouteName, 'cars.create');
Ember.$('#close-link').click();
});

Ember.run(function() {
equal(router.currentRouteName, 'cars.index');
equal(router.get('url'), '/cars');
equal(carsController.get('page'), 1, 'The page query-param is 1');
Ember.$('#page2-link').click();
});

Ember.run(function() {
equal(router.currentRouteName, 'cars.index', 'The active route is still cars');
equal(router.get('url'), '/cars?page=2', 'The url has been updated');
equal(carsController.get('page'), 2, 'The query params have been updated');
});
});

QUnit.test('The {{link-to}} applies activeClass when query params are not changed', function() {
Ember.TEMPLATES.index = compile(
'{{#link-to (query-params foo=\'cat\') id=\'cat-link\'}}Index{{/link-to}} ' +
Expand Down

0 comments on commit 4082280

Please sign in to comment.