Skip to content

Commit

Permalink
[refactor] Refactored tests to use QUnit (45m)
Browse files Browse the repository at this point in the history
Also has happy byproduct of eliminating vulnerable dependency on rollup
  • Loading branch information
kobsy committed Oct 7, 2024
1 parent 3a4af6f commit e7e2e44
Show file tree
Hide file tree
Showing 9 changed files with 4,071 additions and 669 deletions.
13 changes: 2 additions & 11 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = function() {
return Promise.all([
getChannelURL('release'),
getChannelURL('beta'),
getChannelURL('canary')
]).then((urls) => {
return {
useYarn: true,
Expand All @@ -15,15 +14,15 @@ module.exports = function() {
name: 'ember-lts-previous',
npm: {
devDependencies: {
'ember-source': '~3.24.0'
'ember-source': '~3.28.0'
}
}
},
{
name: 'ember-lts-current',
npm: {
devDependencies: {
'ember-source': '~3.28.0'
'ember-source': '~4.12.0'
}
}
},
Expand All @@ -43,14 +42,6 @@ module.exports = function() {
}
}
},
{
name: 'ember-canary',
npm: {
devDependencies: {
'ember-source': urls[2]
}
}
},
// The default `.travis.yml` runs this scenario via `npm test`,
// not via `ember try`. It's still included here so that running
// `ember try:each` manually or from a customized CI config will run it
Expand Down
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@
"@ember/render-modifiers": "^1.0.2",
"@glimmer/component": "^1.0.0",
"@glimmer/tracking": "^1.0.0",
"ember-cli-babel": "^7.20.5",
"ember-cli-babel": "^7.26.11",
"ember-cli-htmlbars": "^3.0.0",
"ember-copy": "^1.0.0",
"ember-list-keyboard-navigator": "^0.1.1",
"ember-truth-helpers": "^2.1.0"
},
"devDependencies": {
"@babel/helper-environment-visitor": "^7.24.7",
"@ember/test-helpers": "^2.8.1",
"babel-eslint": "^10.1.0",
"broccoli-asset-rev": "^2.7.0",
"ember-auto-import": "^2.8.1",
"ember-cli": "~3.20.0",
"ember-cli-chai": "^0.5.0",
"ember-cli-dependency-checker": "^3.0.0",
"ember-cli-htmlbars-inline-precompile": "^1.0.3",
"ember-cli-inject-live-reload": "^1.8.2",
Expand All @@ -49,7 +51,7 @@
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^1.1.0",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-mocha": "^0.16.2",
"ember-qunit": "^5.1.5",
"ember-resolver": "^5.0.1",
"ember-source": "~3.28.0",
"ember-source-channel-url": "^3.0.0",
Expand All @@ -59,7 +61,10 @@
"eslint-plugin-ember": "^8.6.0",
"eslint-plugin-node": "^11.1.0",
"loader.js": "^4.7.0",
"npm-run-all": "^4.1.5"
"npm-run-all": "^4.1.5",
"qunit": "^2.22.0",
"qunit-dom": "^3.2.1",
"webpack": "5"
},
"engines": {
"node": "16.* || >= 18"
Expand All @@ -68,6 +73,7 @@
"configPath": "tests/dummy/config"
},
"resolutions": {
"@babel/traverse": ">=7.16.5",
"ansi-html": "mahdyar/ansi-html-community#v0.0.8",
"ansi-regex": "^5.0.1",
"async": "^2.6.4",
Expand Down
7 changes: 7 additions & 0 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,12 @@

{{content-for "body-footer"}}
{{content-for "test-body-footer"}}

<div id="qunit"></div>
<div id="qunit-fixture">
<div id="ember-testing-container">
<div id="ember-testing"></div>
</div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { assert } from 'chai';
import { describe, it } from 'mocha';
import { setupRenderingTest } from 'ember-mocha';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, find } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { prepareConfig } from 'ember-search-with-modifiers/utils/search';

describe('Integration | Component | SearchWithModifiers::SearchBox', function() {
setupRenderingTest();
module('Integration | Component | SearchWithModifiers::SearchBox', function(hooks) {
setupRenderingTest(hooks);

const configHash = {
"category:": {
Expand All @@ -21,7 +20,7 @@ describe('Integration | Component | SearchWithModifiers::SearchBox', function()
}
};

it('highlights modifiers', async function() {
test('highlights modifiers', async function(assert) {
this.set('query', '');
this.set('cursorLocation', -1);
this.set('tokenConfig', prepareConfig(configHash));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { assert } from 'chai';
import { it, describe } from 'mocha';
import { setupRenderingTest } from 'ember-mocha';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, findAll, find, triggerKeyEvent } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

Expand All @@ -12,17 +11,17 @@ const hintList = [
{ category: 'Action Types', index: 1, position: 1, value: 'plant', label: 'plant' },
{ category: 'Action Types', index: 2, position: 2, value: 'mineral', label: 'mineral' } ] } ];

describe('Integration | Component | SearchWithModifiers::SearchModifiers', function() {
setupRenderingTest();
module('Integration | Component | SearchWithModifiers::SearchModifiers', function(hooks) {
setupRenderingTest(hooks);

it('renders', async function() {
test('renders', async function(assert) {
await render(hbs`
<SearchWithModifiers::SearchModifiers />
`);
assert.exists(find('.search-modifiers'));
assert.ok(find('.search-modifiers'));
});

it('displays hintList', async function() {
test('displays hintList', async function(assert) {
this.set('hintList', hintList);

await render(hbs`
Expand All @@ -34,7 +33,7 @@ describe('Integration | Component | SearchWithModifiers::SearchModifiers', funct
['animal', 'plant', 'mineral']);
});

it('list current item works', async function() {
test('list current item works', async function(assert) {
this.set('hintList', hintList);

let model = null;
Expand All @@ -47,7 +46,7 @@ describe('Integration | Component | SearchWithModifiers::SearchModifiers', funct
@hintList={{hintList}}/>
`);

assert.isNull(find('.search-modifier.highlighted'), 'Expected nothing to be selected');
assert.strictEqual(null, find('.search-modifier.highlighted'), 'Expected nothing to be selected');

let target = find('[data-test-list-keyboard-navigator]');
target.focus();
Expand Down
5 changes: 4 additions & 1 deletion tests/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Application from '../app';
import config from '../config/environment';
import * as QUnit from 'qunit';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-mocha';
import { setup } from 'qunit-dom';
import { start } from 'ember-qunit';

setApplication(Application.create(config.APP));
setup(QUnit.assert);
start();
12 changes: 7 additions & 5 deletions tests/unit/models/token-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { assert } from 'chai';
import { it, describe } from 'mocha';
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { prepareConfig } from 'ember-search-with-modifiers/utils/search';
import Token from 'ember-search-with-modifiers/models/token';

describe('Unit | token', function() {
module('Unit | token', function(hooks) {
setupTest(hooks);

const configHash = prepareConfig({
"before:": {
type: 'date',
Expand All @@ -24,7 +26,7 @@ describe('Unit | token', function() {
}
});

it('token list type works', function() {
test('token list type works', function(assert) {
let token = new Token({ configHash, fullText: 'category:plant' });

assert.equal(token.type, 'list');
Expand Down Expand Up @@ -60,7 +62,7 @@ describe('Unit | token', function() {
]);
});

it('token list type works with quoted tokens', function() {
test('token list type works with quoted tokens', function(assert) {
let token = new Token({ configHash, fullText: 'category:"quoted type"' });

assert.equal(token.type, 'list', 'should identify the type');
Expand Down
36 changes: 19 additions & 17 deletions tests/unit/utils/search-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { assert } from 'chai';
import { it, describe } from 'mocha';
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { tokenize } from 'ember-search-with-modifiers/utils/search';

describe('Unit | Utility | search', function() {
module('Unit | Utility | search', function(hooks) {
setupTest(hooks);

function tokenizeAndDescribe(text) {
let config = {
'#': {
Expand All @@ -24,56 +26,56 @@ describe('Unit | Utility | search', function() {
}).join('');
}

describe('tokenize', function() {
it('treats words as spaces', function() {
module('tokenize', function() {
test('treats words as spaces', function(assert) {
assert.equal(tokenizeAndDescribe('hello'), 'hello(space)');
});

it('splits words', function() {
test('splits words', function(assert) {
assert.equal(tokenizeAndDescribe('hello world'), 'hello(space) (space)world(space)');
});

it('consolidates spaces', function() {
test('consolidates spaces', function(assert) {
assert.equal(tokenizeAndDescribe('hello world'), 'hello(space) (space)world(space)');
});

it('keeps quoted phrases together', function() {
test('keeps quoted phrases together', function(assert) {
assert.equal(tokenizeAndDescribe('"hello world"'), '"hello world"(space)');
});

it('handles half-quoted phrases', function() {
test('handles half-quoted phrases', function(assert) {
assert.equal(tokenizeAndDescribe('"hello'), '"hello(space)');
});

it('identifies field-modifiers', function() {
test('identifies field-modifiers', function(assert) {
assert.equal(tokenizeAndDescribe('hello fruit:'), 'hello(space) (space)fruit:(field)');
});

it('identifies symbol-modifiers', function() {
test('identifies symbol-modifiers', function(assert) {
assert.equal(tokenizeAndDescribe('#fruits'), '#fruits(symbol)');
});

it('treats completed modifiers as a single token', function() {
test('treats completed modifiers as a single token', function(assert) {
assert.equal(tokenizeAndDescribe('hello fruit:apple'), 'hello(space) (space)fruit:apple(field)');
});

it('permits spaces between a field-modifier and its value', function() {
test('permits spaces between a field-modifier and its value', function(assert) {
assert.equal(tokenizeAndDescribe('hello fruit: apple'), 'hello(space) (space)fruit: apple(field)');
});

it('does not permit spaces between a symbol-modifier and its value', function() {
test('does not permit spaces between a symbol-modifier and its value', function(assert) {
assert.equal(tokenizeAndDescribe('# fruits'), '#(symbol) (space)fruits(space)');
});

it('accepts quoted phrases as values for modifiers', function() {
test('accepts quoted phrases as values for modifiers', function(assert) {
assert.equal(tokenizeAndDescribe('fruit: "apple"'), 'fruit: "apple"(field)');
});

it('treats space after text after modifiers as a token break', function() {
test('treats space after text after modifiers as a token break', function(assert) {
assert.equal(tokenizeAndDescribe('fruit: apple hello'), 'fruit: apple(field) (space)hello(space)');
});

it('treats broken modifiers as a single token', function() {
test('treats broken modifiers as a single token', function(assert) {
assert.equal(tokenizeAndDescribe('hello fruit:grape'), 'hello(space) (space)fruit:grape(field)');
});
});
Expand Down
Loading

0 comments on commit e7e2e44

Please sign in to comment.