Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new QUnit testing APIs #434

Merged
merged 6 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"ember-cli-inject-live-reload": "^2.0.2",
"ember-disable-prototype-extensions": "^1.1.2",
"ember-load-initializers": "^2.1.0",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-qunit": "^4.6.0",
"ember-resolver": "^5.3.0",
"ember-source": "~3.14.1",
Expand Down
4 changes: 4 additions & 0 deletions tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {
parserOptions: {
sourceType: 'module',
ecmaVersion: 2017
},
extends: [
'simplabs/configs/ember-qunit',
'simplabs/plugins/qunit',
Expand Down
137 changes: 70 additions & 67 deletions tests/acceptance/bind-data-test-attributes-in-components-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { test, skip } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
import { module, test, skip } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { visit } from '@ember/test-helpers';

import config from 'dummy/config/environment';
import { hasPositionalParams } from 'dummy/version-checks';
Expand All @@ -11,70 +12,72 @@ if (!config.stripTestSelectors) {
* because initializers are only applied in acceptance tests, but not in
* component integration tests.
*/
moduleForAcceptance('Acceptance | Initializer | ember-test-selectors', {
beforeEach() {
visit('/bind-test');
},
});

test('it binds data-test-* attributes on components', function(assert) {
assert.dom('.test1 div[data-test-first]').exists('data-test-first exists');
assert.dom('.test1 div[data-test-first="foobar"]').exists('data-test-first has correct value');
});

test('it binds data-test-* attributes on components in block form', function(assert) {
assert.dom('.test2 div[data-test-first]').exists('data-test-first exists');
assert.dom('.test2 div[data-test-first="foobar"]').exists('data-test-first has correct value');
});

test('it works with multiple data-test-* attributes on components', function(assert) {
assert.dom('.test3 div[data-test-first]').exists('data-test-first exists');
assert.dom('.test3 div[data-test-first="foobar"]').exists('data-test-first has correct value');
assert.dom('.test3 div[data-test-second]').exists('data-test-second exists');
assert.dom('.test3 div[data-test-second="second"]').exists('data-test-second has correct value');
});

test('it leaves other data attributes untouched, when a data-test-* attribute is present as well on components', function(assert) {
assert.dom('.test4 div[data-test-first]').exists('data-test-first exists');
assert.dom('.test4 div[data-test-first="foobar"]').exists('data-test-first has correct value');
assert.dom('.test4 div[data-non-test]').doesNotExist('data-non-test does not exists');
});

test('it leaves data-test attribute untouched on components', function(assert) {
assert.dom('.test5 div[data-test]').doesNotExist('data-test does not exists');
});

test('it leaves other data attributes untouched on components', function(assert) {
assert.dom('.test6 div[data-non-test]').doesNotExist('data-non-test does not exists');
});

test('it binds data-test-* attributes with boolean values on components', function(assert) {
assert.dom('.test7 div[data-test-with-boolean-value]').exists('data-test-with-boolean-value exists');
});

test('it binds data-test-* attributes without values on components', function(assert) {
assert.dom('.test8 div[data-test-without-value]').exists('data-test-without-value exists');
});

test('it binds data-test-* attributes without values on block components', function(assert) {
assert.dom('.test9 div[data-test-without-value]').exists('data-test-without-value exists');
});

(hasPositionalParams ? test : skip)('it leaves data-test attribute without value untouched on components', function(assert) {
assert.dom('.test10 div[data-test]').doesNotExist('data-test does not exists');
});

test('it transforms data-test params to hash pairs on components', function(assert) {
assert.dom('.test11 div[data-test-something]').exists('data-test-something exists');
});

test('it binds data-test attributes on {{link-to}} components', function(assert) {
assert.dom('.test-link-to-block a').hasAttribute('data-test-foo', 'bar');
assert.dom('.test-link-to-inline a').hasAttribute('data-test-foo', 'bar');
});

test('it handles the tagless components without assert when `supportsDataTestProperties` is set', function(assert) {
assert.dom('.test12 div[data-test-with-boolean-value]').doesNotExist('data-test-with-boolean-value does not exist');
assert.dom('.test13 div[data-test-without-value]').doesNotExist('data-test-without-value does not exist');
module('Acceptance | Initializer | ember-test-selectors', function(hooks) {
setupApplicationTest(hooks);

hooks.beforeEach(async function() {
await visit('/bind-test');
});

test('it binds data-test-* attributes on components', function(assert) {
assert.dom('.test1 div[data-test-first]').exists('data-test-first exists');
assert.dom('.test1 div[data-test-first="foobar"]').exists('data-test-first has correct value');
});

test('it binds data-test-* attributes on components in block form', function(assert) {
assert.dom('.test2 div[data-test-first]').exists('data-test-first exists');
assert.dom('.test2 div[data-test-first="foobar"]').exists('data-test-first has correct value');
});

test('it works with multiple data-test-* attributes on components', function(assert) {
assert.dom('.test3 div[data-test-first]').exists('data-test-first exists');
assert.dom('.test3 div[data-test-first="foobar"]').exists('data-test-first has correct value');
assert.dom('.test3 div[data-test-second]').exists('data-test-second exists');
assert.dom('.test3 div[data-test-second="second"]').exists('data-test-second has correct value');
});

test('it leaves other data attributes untouched, when a data-test-* attribute is present as well on components', function(assert) {
assert.dom('.test4 div[data-test-first]').exists('data-test-first exists');
assert.dom('.test4 div[data-test-first="foobar"]').exists('data-test-first has correct value');
assert.dom('.test4 div[data-non-test]').doesNotExist('data-non-test does not exists');
});

test('it leaves data-test attribute untouched on components', function(assert) {
assert.dom('.test5 div[data-test]').doesNotExist('data-test does not exists');
});

test('it leaves other data attributes untouched on components', function(assert) {
assert.dom('.test6 div[data-non-test]').doesNotExist('data-non-test does not exists');
});

test('it binds data-test-* attributes with boolean values on components', function(assert) {
assert.dom('.test7 div[data-test-with-boolean-value]').exists('data-test-with-boolean-value exists');
});

test('it binds data-test-* attributes without values on components', function(assert) {
assert.dom('.test8 div[data-test-without-value]').exists('data-test-without-value exists');
});

test('it binds data-test-* attributes without values on block components', function(assert) {
assert.dom('.test9 div[data-test-without-value]').exists('data-test-without-value exists');
});

(hasPositionalParams ? test : skip)('it leaves data-test attribute without value untouched on components', function(assert) {
assert.dom('.test10 div[data-test]').doesNotExist('data-test does not exists');
});

test('it transforms data-test params to hash pairs on components', function(assert) {
assert.dom('.test11 div[data-test-something]').exists('data-test-something exists');
});

test('it binds data-test attributes on {{link-to}} components', function(assert) {
assert.dom('.test-link-to-block a').hasAttribute('data-test-foo', 'bar');
assert.dom('.test-link-to-inline a').hasAttribute('data-test-foo', 'bar');
});

test('it handles the tagless components without assert when `supportsDataTestProperties` is set', function(assert) {
assert.dom('.test12 div[data-test-with-boolean-value]').doesNotExist('data-test-with-boolean-value does not exist');
assert.dom('.test13 div[data-test-without-value]').doesNotExist('data-test-without-value does not exist');
});
});
}
1 change: 1 addition & 0 deletions tests/dummy/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = function(environment) {
ENV.APP.LOG_VIEW_LOOKUPS = false;

ENV.APP.rootElement = '#ember-testing';
ENV.APP.autoboot = false;
}

if (environment === 'production') {
Expand Down
5 changes: 0 additions & 5 deletions tests/helpers/destroy-app.js

This file was deleted.

21 changes: 0 additions & 21 deletions tests/helpers/module-for-acceptance.js

This file was deleted.

11 changes: 0 additions & 11 deletions tests/helpers/resolver.js

This file was deleted.

19 changes: 0 additions & 19 deletions tests/helpers/start-app.js

This file was deleted.

112 changes: 55 additions & 57 deletions tests/integration/strip-data-test-attributes-from-components-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { moduleForComponent, test, skip } from 'ember-qunit';
import { module, test, skip } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

import config from 'dummy/config/environment';
Expand All @@ -7,80 +9,76 @@ import {
hasEmberVersion
} from 'dummy/version-checks';

moduleForComponent('print-test-attributes', 'StripTestSelectorsTransform plugin', {
integration: true
});

if (config.stripTestSelectors) {

(hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with single positional params', function(assert) {
this.render(hbs`{{print-test-attributes data-test-should-not-be}}`);
module('StripTestSelectorsTransform plugin', function(hooks) {
setupRenderingTest(hooks);

assert.dom('.data-test-positional-params').hasText(hasEmberVersion(2, 10) || !hasEmberVersion(2, 3) ? '' : '0', 'there should be no params');
});
if (config.stripTestSelectors) {
(hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with single positional params', async function(assert) {
await render(hbs`{{print-test-attributes data-test-should-not-be}}`);

(hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with positional params data-test-* as first param', function(assert) {
this.render(hbs`{{print-test-attributes data-test-should-not-be "param1"}}`);
assert.dom('.data-test-positional-params').hasText(hasEmberVersion(2, 10) || !hasEmberVersion(2, 3) ? '' : '0', 'there should be no params');
});

assert.dom('.data-test-positional-params').hasText('1', 'there should be only one param');
});
(hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with positional params data-test-* as first param', async function(assert) {
await render(hbs`{{print-test-attributes data-test-should-not-be "param1"}}`);

(hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with multiple positional params', function(assert) {
this.render(hbs`{{print-test-attributes "param1" data-test-should-not-be}}`);
assert.dom('.data-test-positional-params').hasText('1', 'there should be only one param');
});

assert.dom('.data-test-positional-params').hasText('1', 'there should be only one param');
});
(hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with multiple positional params', async function(assert) {
await render(hbs`{{print-test-attributes "param1" data-test-should-not-be}}`);

(hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with block and multiple positional params', function(assert) {
this.render(hbs`{{#print-test-attributes "param1" data-test-should-not-be}}{{/print-test-attributes}}`);
assert.dom('.data-test-positional-params').hasText('1', 'there should be only one param');
});

assert.dom('.data-test-positional-params').hasText('1', 'there should be only one param');
});
(hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with block and multiple positional params', async function(assert) {
await render(hbs`{{#print-test-attributes "param1" data-test-should-not-be}}{{/print-test-attributes}}`);

test('it strips data-test-* attributes from components', function(assert) {
this.render(hbs`{{print-test-attributes data-test-first="foobar"}}`);
assert.dom('.data-test-positional-params').hasText('1', 'there should be only one param');
});

assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped');
});
test('it strips data-test-* attributes from components', async function(assert) {
await render(hbs`{{print-test-attributes data-test-first="foobar"}}`);

test('it strips data-test-* attributes from components in block form', function(assert) {
this.render(hbs`{{#print-test-attributes data-test-first="foobar"}}hello{{/print-test-attributes}}`);
assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped');
});

assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped');
});
test('it strips data-test-* attributes from components in block form', async function(assert) {
await render(hbs`{{#print-test-attributes data-test-first="foobar"}}hello{{/print-test-attributes}}`);

test('it works with multiple data-test-* attributes on components', function(assert) {
this.render(hbs`{{print-test-attributes data-test-first="foobar" data-test-second="second"}}`);
assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped');
});

assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped');
assert.dom('.data-test-second').hasText('', 'the data-test-second attribute was stripped');
});
test('it works with multiple data-test-* attributes on components', async function(assert) {
await render(hbs`{{print-test-attributes data-test-first="foobar" data-test-second="second"}}`);

test('it leaves other data attributes untouched, when a data-test-* attribute is present as well on components', function(assert) {
this.render(hbs`{{print-test-attributes data-test-first="foobar" data-non-test="baz"}}`);
assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped');
assert.dom('.data-test-second').hasText('', 'the data-test-second attribute was stripped');
});

assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped');
assert.dom('.data-non-test').hasText('baz', 'the data-non-test attribute was not stripped');
});
test('it leaves other data attributes untouched, when a data-test-* attribute is present as well on components', async function(assert) {
await render(hbs`{{print-test-attributes data-test-first="foobar" data-non-test="baz"}}`);

test('it leaves data-test attributes untouched on components', function(assert) {
this.render(hbs`{{print-test-attributes data-test="foo"}}`);
assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped');
assert.dom('.data-non-test').hasText('baz', 'the data-non-test attribute was not stripped');
});

assert.dom('.data-test').hasText('foo', 'the data-test attribute was stripped');
});
test('it leaves data-test attributes untouched on components', async function(assert) {
await render(hbs`{{print-test-attributes data-test="foo"}}`);

test('it leaves other data attributes untouched on components', function(assert) {
this.render(hbs`{{print-test-attributes data-non-test="foo"}}`);
assert.dom('.data-test').hasText('foo', 'the data-test attribute was stripped');
});

assert.dom('.data-non-test').hasText('foo', 'the data-non-test attribute was not stripped');
});
test('it leaves other data attributes untouched on components', async function(assert) {
await render(hbs`{{print-test-attributes data-non-test="foo"}}`);

} else {
assert.dom('.data-non-test').hasText('foo', 'the data-non-test attribute was not stripped');
});
} else {
test('it does not strip data-test-* attributes from components', async function(assert) {
await render(hbs`{{print-test-attributes data-test-first="foobar"}}`);

test('it does not strip data-test-* attributes from components', function(assert) {
this.render(hbs`{{print-test-attributes data-test-first="foobar"}}`);

assert.dom('.data-test-first').hasText('foobar', 'the data-test-first attribute was not stripped');
});

}
assert.dom('.data-test-first').hasText('foobar', 'the data-test-first attribute was not stripped');
});
}
});
Loading