Skip to content

Commit

Permalink
Merge pull request emberjs#13769 from rwjblue/migrate-some-query-params
Browse files Browse the repository at this point in the history
Migrate a few `link-to` tests to newer testing infrastructure.
  • Loading branch information
rwjblue committed Jul 9, 2016
2 parents eeb236e + af0489e commit 84dc75a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { moduleFor, ApplicationTest } from '../../utils/test-case';
import Controller from 'ember-runtime/controllers/controller';
import Route from 'ember-routing/system/route';
import { set } from 'ember-metal/property_set';
import run from 'ember-metal/run_loop';
import { LinkTo } from '../../utils/helpers';
import { classes as classMatcher } from '../../utils/test-helpers';
import isEnabled from 'ember-metal/features';

moduleFor('Link-to component', class extends ApplicationTest {
runTask(fn) {
Expand Down Expand Up @@ -124,3 +127,56 @@ moduleFor('Link-to component', class extends ApplicationTest {
});
}
});

moduleFor('Link-to component with query-params', class extends ApplicationTest {
constructor() {
super(...arguments);

if (isEnabled('ember-routing-route-configured-query-params')) {
this.registerRoute('index', Route.extend({
queryParams: {
foo: {
defaultValue: '123'
},
bar: {
defaultValue: 'yes'
}
}
}));
} else {
this.registerController('index', Controller.extend({
queryParams: ['foo'],
foo: '123',
bar: 'yes'
}));
}
}

runTask(fn) {
run(fn);
}

['@test populates href with fully supplied query param values'](assert) {
this.registerTemplate('index', `{{#link-to 'index' (query-params foo='456' bar='NAW')}}Index{{/link-to}}`);

return this.visit('/').then(() => {
this.assertComponentElement(this.firstChild.firstElementChild, {
tagName: 'a',
attrs: { href: '/?bar=NAW&foo=456' },
content: 'Index'
});
});
}

['@test populates href with partially supplied query param values, but omits if value is default value']() {
this.registerTemplate('index', `{{#link-to 'index' (query-params foo='123')}}Index{{/link-to}}`);

return this.visit('/').then(() => {
this.assertComponentElement(this.firstChild.firstElementChild, {
tagName: 'a',
attrs: { href: '/', class: classMatcher('ember-view active') },
content: 'Index'
});
});
}
});
92 changes: 0 additions & 92 deletions packages/ember/tests/helpers/link_to_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1337,98 +1337,6 @@ QUnit.test('{{link-to}} populates href with default query param values with empt
equal(jQuery('#the-link').attr('href'), '/', 'link has right href');
});

QUnit.test('{{link-to}} populates href with supplied query param values', function() {
if (isEnabled('ember-routing-route-configured-query-params')) {
App.IndexRoute = Route.extend({
queryParams: {
foo: {
defaultValue: '123'
}
}
});
} else {
App.IndexController = Controller.extend({
queryParams: ['foo'],
foo: '123'
});
}

setTemplate('index', compile("{{#link-to 'index' (query-params foo='456') id='the-link'}}Index{{/link-to}}"));
bootApplication();
equal(jQuery('#the-link').attr('href'), '/?foo=456', 'link has right href');
});

QUnit.test('{{link-to}} populates href with partially supplied query param values', function() {
if (isEnabled('ember-routing-route-configured-query-params')) {
App.IndexRoute = Route.extend({
queryParams: {
foo: {
defaultValue: '123'
},
bar: {
defaultValue: 'yes'
}
}
});
} else {
App.IndexController = Controller.extend({
queryParams: ['foo'],
foo: '123',
bar: 'yes'
});
}

setTemplate('index', compile("{{#link-to 'index' (query-params foo='456') id='the-link'}}Index{{/link-to}}"));
bootApplication();
equal(jQuery('#the-link').attr('href'), '/?foo=456', 'link has right href');
});

QUnit.test('{{link-to}} populates href with partially supplied query param values, but omits if value is default value', function() {
if (isEnabled('ember-routing-route-configured-query-params')) {
App.IndexRoute = Route.extend({
queryParams: {
foo: {
defaultValue: '123'
}
}
});
} else {
App.IndexController = Controller.extend({
queryParams: ['foo'],
foo: '123'
});
}

setTemplate('index', compile("{{#link-to 'index' (query-params foo='123') id='the-link'}}Index{{/link-to}}"));
bootApplication();
equal(jQuery('#the-link').attr('href'), '/', 'link has right href');
});

QUnit.test('{{link-to}} populates href with fully supplied query param values', function() {
if (isEnabled('ember-routing-route-configured-query-params')) {
App.IndexRoute = Route.extend({
queryParams: {
foo: {
defaultValue: '123'
},
bar: {
defaultValue: 'yes'
}
}
});
} else {
App.IndexController = Controller.extend({
queryParams: ['foo', 'bar'],
foo: '123',
bar: 'yes'
});
}

setTemplate('index', compile(`{{#link-to 'index' (query-params foo='456' bar='NAW') id='the-link'}}Index{{/link-to}}`));
bootApplication();
equal(jQuery('#the-link').attr('href'), '/?bar=NAW&foo=456', 'link has right href');
});

QUnit.test('{{link-to}} with only query-params and a block updates when route changes', function() {
Router.map(function() {
this.route('about');
Expand Down

0 comments on commit 84dc75a

Please sign in to comment.