Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
xav-car committed Jan 7, 2025
1 parent 90dfc73 commit 9f86799
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 88 deletions.
19 changes: 5 additions & 14 deletions tests/integration/components/pix-return-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@1024pix/ember-testing-library';
import { hbs } from 'ember-cli-htmlbars';
import EmberDebug from '@ember/debug';
import sinon from 'sinon';

module('Integration | Component | pix-return-to', function (hooks) {
setupRenderingTest(hooks);
let warnStub;

hooks.beforeEach(function () {
sinon.stub(EmberDebug, 'warn');
warnStub = sinon.stub(console, 'warn');
});

hooks.afterEach(function () {
sinon.restore();
warnStub.restore();
});

setupRenderingTest(hooks);
const RETURN_TO_SELECTOR = '.pix-return-to';

test('it renders the default PixReturnTo', async function (assert) {
Expand All @@ -40,15 +40,6 @@ module('Integration | Component | pix-return-to', function (hooks) {
await render(hbs`<PixReturnTo />`);

// then
assert.ok(
EmberDebug.warn
.getCalls()
.find((call) => {
return call.args[0] === 'PixReturnTo: @route param is not provided';
})
.calledWith('PixReturnTo: @route param is not provided', false, {
id: 'pix-ui.returnTo.route.required',
}),
);
assert.ok(warnStub.calledWith('WARNING: PixReturnTo: @route param is not provided'));
});
});
18 changes: 4 additions & 14 deletions tests/integration/components/pix-table-column-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { render } from '@1024pix/ember-testing-library';
import { hbs } from 'ember-cli-htmlbars';
import sinon from 'sinon';

import EmberDebug from '@ember/debug';

module('Integration | Component | table-column', function (hooks) {
setupRenderingTest(hooks);

Expand All @@ -26,14 +24,13 @@ module('Integration | Component | table-column', function (hooks) {
});

module('#warn', function (hooks) {
let sandbox;
let warnStub;
hooks.beforeEach(function () {
sandbox = sinon.createSandbox();
sandbox.stub(EmberDebug, 'warn');
warnStub = sinon.stub(console, 'warn');
});

hooks.afterEach(function () {
sandbox.restore();
warnStub.restore();
});

test('should warn when provided incorrect type', async function (assert) {
Expand All @@ -57,14 +54,7 @@ module('Integration | Component | table-column', function (hooks) {

// then
assert.ok(
EmberDebug.warn
.getCalls()
.find((call) => {
return call.args[0] === 'PixTableColumn: you need to provide a valid type';
})
.calledWith('PixTableColumn: you need to provide a valid type', false, {
id: 'pix-ui.table-column.type.incorrect',
}),
warnStub.calledWithExactly('WARNING: PixTableColumn: you need to provide a valid type'),
);
});
});
Expand Down
66 changes: 13 additions & 53 deletions tests/integration/components/pix-table-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { setupRenderingTest } from 'ember-qunit';
import { render } from '@1024pix/ember-testing-library';
import { click } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import EmberDebug from '@ember/debug';
import sinon from 'sinon';

module('Integration | Component | table', function (hooks) {
Expand Down Expand Up @@ -266,14 +265,13 @@ module('Integration | Component | table', function (hooks) {
});

module('#warn', function (hooks) {
let sandbox;
let warnStub;
hooks.beforeEach(function () {
sandbox = sinon.createSandbox();
sandbox.stub(EmberDebug, 'warn');
warnStub = sinon.stub(console, 'warn');
});

hooks.afterEach(function () {
sandbox.restore();
warnStub.restore();
});

test('it should warn when @variant is incorrect', async function (assert) {
Expand All @@ -285,21 +283,9 @@ module('Integration | Component | table', function (hooks) {

// then
assert.ok(
EmberDebug.warn
.getCalls()
.find((call) => {
return (
call.args[0] ===
'PixTable: @variant "wrong variant" should be certif, orga or primary'
);
})
.calledWith(
'PixTable: @variant "wrong variant" should be certif, orga or primary',
false,
{
id: 'pix-ui.pix-table.variant.not-valid',
},
),
warnStub.calledWithExactly(
'WARNING: PixTable: @variant "wrong variant" should be certif, orga or primary',
),
);
});

Expand All @@ -309,16 +295,7 @@ module('Integration | Component | table', function (hooks) {
await render(hbs`<PixTable @data={{this.data}} />`);

// then
assert.ok(
EmberDebug.warn
.getCalls()
.find((call) => {
return call.args[0] === 'PixTable: @caption is required';
})
.calledWith('PixTable: @caption is required', false, {
id: 'pix-ui.pix-table.caption.required',
}),
);
assert.ok(warnStub.calledWithExactly('WARNING: PixTable: @caption is required'));
});

test('it should warn when @sortOrder is incorrect', async function (assert) {
Expand All @@ -335,14 +312,9 @@ module('Integration | Component | table', function (hooks) {

// then
assert.ok(
EmberDebug.warn
.getCalls()
.find((call) => {
return call.args[2].id === 'pix-ui.table-column.sortOrder.not-valid';
})
.calledWith('PixTableColumn: you need to provide a valid sortOrder', false, {
id: 'pix-ui.table-column.sortOrder.not-valid',
}),
warnStub.calledWithExactly(
'WARNING: PixTableColumn: you need to provide a valid sortOrder',
),
);
});

Expand Down Expand Up @@ -386,21 +358,9 @@ module('Integration | Component | table', function (hooks) {

// then
assert.ok(
EmberDebug.warn
.getCalls()
.find((call) => {
return (
call.args[0] ===
'PixTableColumn: parameters `@ariaLabelDefaultSort`, `@ariaLabelSortDesc` and `@ariaLabelSortAsc` are required for sort buttons'
);
})
.calledWith(
'PixTableColumn: parameters `@ariaLabelDefaultSort`, `@ariaLabelSortDesc` and `@ariaLabelSortAsc` are required for sort buttons',
false,
{
id: 'pix-ui.pix-table-column.sortAriaLabels.required',
},
),
warnStub.calledWithExactly(
'WARNING: PixTableColumn: parameters `@ariaLabelDefaultSort`, `@ariaLabelSortDesc` and `@ariaLabelSortAsc` are required for sort buttons',
),
);
});
});
Expand Down
12 changes: 5 additions & 7 deletions tests/unit/services/pix-toast-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import ToastService from '@1024pix/pix-ui/services/pix-toast';
import sinon from 'sinon';
import EmberDebug from '@ember/debug';

module('Unit | Service | toast', function (hooks) {
setupTest(hooks);

let toastService;

let warnStub;
hooks.beforeEach(function () {
toastService = new ToastService();
sinon.stub(EmberDebug, 'warn');
warnStub = sinon.stub(console, 'warn');
});

hooks.afterEach(function () {
sinon.restore();
warnStub.restore();
});

module('#addNotification', function () {
Expand Down Expand Up @@ -44,10 +44,8 @@ module('Unit | Service | toast', function (hooks) {
toastService.addNotification(invalidNotification);

// then
sinon.assert.calledWith(EmberDebug.warn, 'Message mandatory attribute is missing', false, {
id: 'pix-ui.toast.not-message',
});
assert.ok(EmberDebug.warn.calledOnce);
sinon.assert.calledWith(warnStub, 'WARNING: Message mandatory attribute is missing');
assert.ok(warnStub.calledOnce);
assert.strictEqual(toastService.content.length, 0);
});
});
Expand Down

0 comments on commit 9f86799

Please sign in to comment.