Skip to content

Commit

Permalink
Bug: updated tests (#569)
Browse files Browse the repository at this point in the history
Move to Sinon, fix failing tests

---------

Co-authored-by: Edward Faulkner <[email protected]>
Co-authored-by: Chris Manson <[email protected]>
  • Loading branch information
3 people authored Jan 25, 2024
1 parent 772c823 commit 3c38e1e
Show file tree
Hide file tree
Showing 9 changed files with 1,138 additions and 183 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Node CI
on:
push:
branches:
- main
- master
tags:
- 'v*'
pull_request:
Expand Down
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@
],
"scripts": {
"clean": "rm -rf dist node_modules test-app/node_modules",
"link-test-app": "addon-dev link-test-app",
"lint": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*",
"lint:devdeps": "addon-dev sync-dev-deps --lint",
"lint:hbs": "ember-template-lint .",
"lint:js": "eslint .",
"lint:devdeps": "addon-dev sync-dev-deps --lint",
"prepare": "npm-run-all prepublishOnly link-test-app",
"prepublishOnly": "rollup --config",
"scenario:list": "scenario-tester list --files test-app/scenarios.js",
"scenario:output": "scenario-tester output --files test-app/scenarios.js --outdir scenario --scenario ",
"scenario:run": "cd test-app && qunit scenarios.js --filter ",
"start": "npm-run-all --parallel start:*",
"start:test-app": "cd test-app && ember serve",
"start:build": "rollup --config --watch",
"start:test-app": "cd test-app && ember serve",
"sync-dev-deps": "addon-dev sync-dev-deps",
"test": "npm-run-all lint:* test:*",
"test:ember": "cd test-app && ember test",
"test:ember-compatibility": "cd test-app && qunit scenarios.js",
"prepare": "npm-run-all prepublishOnly link-test-app",
"link-test-app": "addon-dev link-test-app",
"prepublishOnly": "rollup --config"
"test:ember-compatibility": "cd test-app && qunit scenarios.js"
},
"dependencies": {
"@embroider/addon-shim": "^0.50.2",
Expand Down Expand Up @@ -79,7 +79,6 @@
"ember-qunit": "^5.1.5",
"ember-resolver": "^8.0.3",
"ember-source": "~3.28.8",
"ember-source-3.25": "npm:ember-source@~3.25.0",
"ember-source-beta": "npm:ember-source@beta",
"ember-source-canary": "npm:ember-source@alpha",
"ember-source-channel-url": "^3.0.0",
Expand All @@ -100,11 +99,11 @@
"qunit": "^2.17.2",
"qunit-console-grouper": "^0.3.0",
"qunit-dom": "^1.6.0",
"release-it": "14.0.0",
"release-it-lerna-changelog": "^4.0.1",
"rollup": "^2.63.0",
"scenario-tester": "^2.0.1",
"testdouble": "^3.16.4",
"testdouble-qunit": "^3.0.3",
"sinon": "^17.0.1",
"webpack": "^5.65.0"
},
"peerDependencies": {
Expand All @@ -124,7 +123,7 @@
}
},
"engines": {
"node": ">= 12"
"node": "20.11.0"
},
"ember-addon": {
"version": 2,
Expand All @@ -137,7 +136,7 @@
}
},
"volta": {
"node": "14.17.5",
"node": "20.11.0",
"yarn": "1.22.11"
},
"release-it": {
Expand Down
15 changes: 0 additions & 15 deletions test-app/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { maybeEmbroider } = require('@embroider/test-setup');

let alias = {
testdouble$: 'testdouble/dist/testdouble.js',
};

module.exports = function (defaults) {
let app = new EmberApp(defaults, {
autoImport: {
watchDependencies: ['ember-pikaday'],
alias,
},
});

return maybeEmbroider(app, {
packagerOptions: {
webpackConfig: {
resolve: {
alias,
},
},
},
skipBabel: [
{
package: 'qunit',
Expand All @@ -33,9 +21,6 @@ module.exports = function (defaults) {
{
package: 'moment-timezone',
},
{
package: 'testdouble',
},
],
});
};
7 changes: 3 additions & 4 deletions test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,17 @@
"qunit-console-grouper": "^0.3.0",
"qunit-dom": "^1.6.0",
"scenario-tester": "^2.0.1",
"testdouble": "^3.16.4",
"testdouble-qunit": "^3.0.3",
"sinon": "^17.0.1",
"webpack": "^5.65.0"
},
"engines": {
"node": "12.* || 14.* || >= 16"
"node": "20.11.0"
},
"ember": {
"edition": "octane"
},
"volta": {
"node": "14.17.5",
"node": "20.11.0",
"yarn": "1.22.11"
}
}
12 changes: 0 additions & 12 deletions test-app/scenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { module: Qmodule, test } = require('qunit');

Scenarios.fromDir(__dirname)
.expand({
ember_3_25,
lts_3_28,
release,
beta,
Expand All @@ -25,17 +24,6 @@ Scenarios.fromDir(__dirname)
});
});

async function ember_3_25(project) {
project.linkDevDependency('ember-cli', {
baseDir: __dirname,
resolveName: 'ember-cli-3.25',
});
project.linkDevDependency('ember-source', {
baseDir: __dirname,
resolveName: 'ember-source-3.25',
});
}

async function lts_3_28(project) {
project.linkDevDependency('ember-cli', {
baseDir: __dirname,
Expand Down
30 changes: 17 additions & 13 deletions test-app/tests/integration/components/pikaday-input-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setupRenderingTest } from 'ember-qunit';
import { render, click, fillIn, settled } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { close as closePikaday, Interactor } from 'ember-pikaday/test-support';
import td from 'testdouble';
import sinon from 'sinon';

const getFirstWeekendDayNumber = function () {
const date = new Date();
Expand Down Expand Up @@ -52,13 +52,14 @@ module('Integration | Component | pikaday-input', function (hooks) {

test('selecting a date should send an action', async function (assert) {
const expectedDate = new Date(2013, 3, 28);
this.initialDate = new Date(2013, 3, 1);

this.set('onSelection', function (selectedDate) {
assert.deepEqual(selectedDate, expectedDate);
});

await render(hbs`
<PikadayInput @onSelection={{this.onSelection}}/>
<PikadayInput @value={{this.initialDate}} @onSelection={{this.onSelection}}/>
`);

await click('input');
Expand All @@ -68,6 +69,7 @@ module('Integration | Component | pikaday-input', function (hooks) {
test('selecting multiple dates should send actions', async function (assert) {
const expectedDate1 = new Date(2013, 3, 28);
const expectedDate2 = new Date(2014, 4, 1);
this.initialDate = new Date(2013, 3, 1);

this.set('onSelection1', function (selectedDate) {
assert.deepEqual(selectedDate, expectedDate1);
Expand All @@ -78,8 +80,8 @@ module('Integration | Component | pikaday-input', function (hooks) {
});

await render(hbs`
<PikadayInput @onSelection={{this.onSelection1}} class="first"/>
<PikadayInput @onSelection={{this.onSelection2}} class="second"/>
<PikadayInput @value={{this.initialDate}} @onSelection={{this.onSelection1}} class="first"/>
<PikadayInput @value={{this.initialDate}} @onSelection={{this.onSelection2}} class="second"/>
`);

await click('input.first');
Expand All @@ -106,7 +108,7 @@ module('Integration | Component | pikaday-input', function (hooks) {
});

test('opening picker should send an action', async function (assert) {
const onOpen = td.function();
const onOpen = sinon.fake();
this.set('onOpen', onOpen);

await render(hbs`
Expand All @@ -115,11 +117,11 @@ module('Integration | Component | pikaday-input', function (hooks) {

await click('input');

assert.verify(onOpen());
assert.ok(onOpen.calledOnce);
});

test('closing picker should send an action', async function (assert) {
const onClose = td.function();
const onClose = sinon.fake();
this.set('onClose', onClose);

await render(hbs`
Expand All @@ -129,11 +131,11 @@ module('Integration | Component | pikaday-input', function (hooks) {
await click('input');
await closePikaday();

assert.verify(onClose());
assert.ok(onClose.calledOnce);
});

test('redrawing picker should send an action', async function (assert) {
const onDraw = td.function();
const onDraw = sinon.fake();
this.set('onDraw', onDraw);

await render(hbs`
Expand All @@ -142,7 +144,7 @@ module('Integration | Component | pikaday-input', function (hooks) {

await click('input');

assert.verify(onDraw());
assert.ok(onDraw.calledOnce);
});

test('setting the value attribute should select the correct date', async function (assert) {
Expand Down Expand Up @@ -377,12 +379,14 @@ module('Integration | Component | pikaday-input', function (hooks) {

test('if utc is set the date returned from pikaday should be in UTC format', async function (assert) {
const expectedDate = new Date(Date.UTC(2013, 3, 28));
this.initialDate = new Date(2013, 3, 1);

this.set('onSelection', function (selectedDate) {
assert.deepEqual(selectedDate, expectedDate);
});

await render(hbs`
<PikadayInput @onSelection={{this.onSelection}} @useUTC={{true}}/>
<PikadayInput @value={{this.initialDate}} @onSelection={{this.onSelection}} @useUTC={{true}}/>
`);

await click('input');
Expand Down Expand Up @@ -539,15 +543,15 @@ module('Integration | Component | pikaday-input', function (hooks) {
});

test('if an options hash is passed, default options are overridden', async function (assert) {
const onOpen = td.function();
const onOpen = sinon.fake();
this.set('onOpen', onOpen);

await render(hbs`
<PikadayInput @options={{hash onOpen=this.onOpen disableWeekends=true}}/>
`);
await click('input');

assert.verify(onOpen());
assert.ok(onOpen.calledOnce);

const weekendDay = getFirstWeekendDayNumber();
const disabledWeekendCell = findAll('td', document.body).find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setupRenderingTest } from 'ember-qunit';
import { render, click } from '@ember/test-helpers';
import { Interactor } from 'ember-pikaday/test-support';
import hbs from 'htmlbars-inline-precompile';
import td from 'testdouble';
import sinon from 'sinon';

module('Integration | Component | pikaday-inputless', function (hooks) {
setupRenderingTest(hooks);
Expand All @@ -18,17 +18,18 @@ module('Integration | Component | pikaday-inputless', function (hooks) {

test('selecting a date should send an action', async function (assert) {
const expectedDate = new Date(2013, 3, 28);
const onSelection = td.function();
this.initialDate = new Date(2013, 3, 1);
const onSelection = sinon.fake();
this.set('onSelection', onSelection);

await render(hbs`
<PikadayInputless @onSelection={{this.onSelection}}/>
<PikadayInputless @value={{this.initialDate}} @onSelection={{this.onSelection}}/>
`);

await click('input');
await Interactor.selectDate(expectedDate);

assert.verify(onSelection(expectedDate));
assert.ok(onSelection.calledWith(expectedDate));
});

test('setting the value attribute should select the correct date', async function (assert) {
Expand Down
4 changes: 0 additions & 4 deletions test-app/tests/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import { setApplication } from '@ember/test-helpers';
import { setup } from 'qunit-dom';
import { start } from 'ember-qunit';

import installVerifyAssertion from 'testdouble-qunit';
import td from 'testdouble';
installVerifyAssertion(QUnit, td);

setApplication(Application.create(config.APP));

setup(QUnit.assert);
Expand Down
Loading

0 comments on commit 3c38e1e

Please sign in to comment.