chore: fix failing tests
This commit is contained in:
parent
781d74d31a
commit
92d85b567a
5 changed files with 62 additions and 81 deletions
|
|
@ -3,6 +3,15 @@ import { expect, fixture, html, unsafeStatic } from '@open-wc/testing';
|
||||||
import '../lion-dialog.js';
|
import '../lion-dialog.js';
|
||||||
|
|
||||||
describe('lion-dialog', () => {
|
describe('lion-dialog', () => {
|
||||||
|
// For some reason, globalRootNode is not cleared properly on disconnectedCallback from previous overlay test fixtures...
|
||||||
|
// Not sure why this "bug" happens...
|
||||||
|
beforeEach(() => {
|
||||||
|
const globalRootNode = document.querySelector('.global-overlays');
|
||||||
|
if (globalRootNode) {
|
||||||
|
globalRootNode.innerHTML = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
describe('Integration tests', () => {
|
describe('Integration tests', () => {
|
||||||
const tagString = 'lion-dialog';
|
const tagString = 'lion-dialog';
|
||||||
const tag = unsafeStatic(tagString);
|
const tag = unsafeStatic(tagString);
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,21 @@
|
||||||
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
|
import '@lion/button/lion-button';
|
||||||
|
import '@lion/checkbox-group/lion-checkbox';
|
||||||
|
import '@lion/checkbox-group/lion-checkbox-group';
|
||||||
|
import { MinLength, Required } from '@lion/form-core';
|
||||||
|
import '@lion/form/lion-form';
|
||||||
import '@lion/input-amount/lion-input-amount';
|
import '@lion/input-amount/lion-input-amount';
|
||||||
import '@lion/input-date/lion-input-date';
|
import '@lion/input-date/lion-input-date';
|
||||||
import '@lion/textarea/lion-textarea';
|
|
||||||
import '@lion/input-datepicker/lion-input-datepicker';
|
import '@lion/input-datepicker/lion-input-datepicker';
|
||||||
import '@lion/input-email/lion-input-email';
|
import '@lion/input-email/lion-input-email';
|
||||||
import '@lion/input-iban/lion-input-iban';
|
import '@lion/input-iban/lion-input-iban';
|
||||||
import '@lion/input-range/lion-input-range';
|
import '@lion/input-range/lion-input-range';
|
||||||
import '@lion/input/lion-input';
|
import '@lion/input/lion-input';
|
||||||
import '@lion/checkbox-group/lion-checkbox-group';
|
|
||||||
import '@lion/checkbox-group/lion-checkbox';
|
|
||||||
import '@lion/radio-group/lion-radio-group';
|
|
||||||
import '@lion/radio-group/lion-radio';
|
import '@lion/radio-group/lion-radio';
|
||||||
|
import '@lion/radio-group/lion-radio-group';
|
||||||
import '@lion/select/lion-select';
|
import '@lion/select/lion-select';
|
||||||
import '@lion/switch/lion-switch';
|
import '@lion/switch/lion-switch';
|
||||||
import '@lion/form/lion-form';
|
import '@lion/textarea/lion-textarea';
|
||||||
import '@lion/button/lion-button';
|
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
|
||||||
import { Required, MinLength } from '@lion/form-core';
|
|
||||||
|
|
||||||
describe(`Submitting/Resetting Form`, async () => {
|
describe(`Submitting/Resetting Form`, async () => {
|
||||||
let el;
|
let el;
|
||||||
|
|
@ -127,8 +126,6 @@ describe(`Submitting/Resetting Form`, async () => {
|
||||||
el.querySelector('#submit_button').click();
|
el.querySelector('#submit_button').click();
|
||||||
await elementUpdated(el);
|
await elementUpdated(el);
|
||||||
el.formElements.forEach(field => {
|
el.formElements.forEach(field => {
|
||||||
console.log(field);
|
|
||||||
console.log(field.submitted);
|
|
||||||
expect(field.submitted).to.be.true;
|
expect(field.submitted).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
import { expect } from '@open-wc/testing';
|
import { expect } from '@open-wc/testing';
|
||||||
import { localize } from '../../src/localize.js';
|
import { localize } from '../../src/localize.js';
|
||||||
import { localizeTearDown } from '../../test-helpers.js';
|
|
||||||
|
|
||||||
import { formatNumber } from '../../src/number/formatNumber.js';
|
import { formatNumber } from '../../src/number/formatNumber.js';
|
||||||
|
import { localizeTearDown } from '../../test-helpers.js';
|
||||||
|
|
||||||
const currencyCode = currency => ({ style: 'currency', currencyDisplay: 'code', currency });
|
const currencyCode = currency => ({ style: 'currency', currencyDisplay: 'code', currency });
|
||||||
const currencySymbol = currency => ({ style: 'currency', currencyDisplay: 'symbol', currency });
|
const currencySymbol = currency => ({ style: 'currency', currencyDisplay: 'symbol', currency });
|
||||||
|
|
@ -310,6 +309,7 @@ describe('formatNumber', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('tr-TR', () => {
|
describe('tr-TR', () => {
|
||||||
|
it('supports basics', () => {
|
||||||
localize.locale = 'tr-TR';
|
localize.locale = 'tr-TR';
|
||||||
expect(formatNumber(123456.789, currencyCode('EUR'))).to.equal('123.456,79 EUR');
|
expect(formatNumber(123456.789, currencyCode('EUR'))).to.equal('123.456,79 EUR');
|
||||||
expect(formatNumber(123456.789, currencyCode('USD'))).to.equal('123.456,79 USD');
|
expect(formatNumber(123456.789, currencyCode('USD'))).to.equal('123.456,79 USD');
|
||||||
|
|
@ -321,4 +321,5 @@ describe('formatNumber', () => {
|
||||||
expect(formatNumber(123456.789, currencySymbol('TRY'))).to.equal('₺123.456,79');
|
expect(formatNumber(123456.789, currencySymbol('TRY'))).to.equal('₺123.456,79');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -10,23 +10,24 @@ function getGlobalOverlayNodes() {
|
||||||
|
|
||||||
export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
||||||
describe(`OverlayMixin${suffix}`, () => {
|
describe(`OverlayMixin${suffix}`, () => {
|
||||||
let el;
|
it('should not be opened by default', async () => {
|
||||||
|
const el = await fixture(html`
|
||||||
beforeEach(async () => {
|
|
||||||
el = await fixture(html`
|
|
||||||
<${tag}>
|
<${tag}>
|
||||||
<div slot="content">content of the overlay</div>
|
<div slot="content">content of the overlay</div>
|
||||||
<button slot="invoker">invoker button</button>
|
<button slot="invoker">invoker button</button>
|
||||||
</${tag}>
|
</${tag}>
|
||||||
`);
|
`);
|
||||||
});
|
|
||||||
|
|
||||||
it('should not be opened by default', async () => {
|
|
||||||
expect(el.opened).to.be.false;
|
expect(el.opened).to.be.false;
|
||||||
expect(el._overlayCtrl.isShown).to.be.false;
|
expect(el._overlayCtrl.isShown).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('syncs opened to overlayController', async () => {
|
it('syncs opened to overlayController', async () => {
|
||||||
|
const el = await fixture(html`
|
||||||
|
<${tag}>
|
||||||
|
<div slot="content">content of the overlay</div>
|
||||||
|
<button slot="invoker">invoker button</button>
|
||||||
|
</${tag}>
|
||||||
|
`);
|
||||||
el.opened = true;
|
el.opened = true;
|
||||||
expect(el.opened).to.be.true;
|
expect(el.opened).to.be.true;
|
||||||
await nextFrame(); // overlayCtrl show/hide is async
|
await nextFrame(); // overlayCtrl show/hide is async
|
||||||
|
|
@ -39,6 +40,12 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('syncs OverlayController to opened', async () => {
|
it('syncs OverlayController to opened', async () => {
|
||||||
|
const el = await fixture(html`
|
||||||
|
<${tag}>
|
||||||
|
<div slot="content">content of the overlay</div>
|
||||||
|
<button slot="invoker">invoker button</button>
|
||||||
|
</${tag}>
|
||||||
|
`);
|
||||||
expect(el.opened).to.be.false;
|
expect(el.opened).to.be.false;
|
||||||
await el._overlayCtrl.show();
|
await el._overlayCtrl.show();
|
||||||
expect(el.opened).to.be.true;
|
expect(el.opened).to.be.true;
|
||||||
|
|
@ -86,7 +93,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
||||||
|
|
||||||
it('fires "opened-changed" event on hide', async () => {
|
it('fires "opened-changed" event on hide', async () => {
|
||||||
const spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
el = await fixture(html`
|
const el = await fixture(html`
|
||||||
<${tag} @opened-changed="${spy}">
|
<${tag} @opened-changed="${spy}">
|
||||||
<div slot="content">content of the overlay</div>
|
<div slot="content">content of the overlay</div>
|
||||||
<button slot="invoker">invoker button</button>
|
<button slot="invoker">invoker button</button>
|
||||||
|
|
@ -105,7 +112,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
||||||
|
|
||||||
it('fires "before-closed" event on hide', async () => {
|
it('fires "before-closed" event on hide', async () => {
|
||||||
const beforeSpy = sinon.spy();
|
const beforeSpy = sinon.spy();
|
||||||
el = await fixture(html`
|
const el = await fixture(html`
|
||||||
<${tag} @before-closed="${beforeSpy}" .opened="${true}">
|
<${tag} @before-closed="${beforeSpy}" .opened="${true}">
|
||||||
<div slot="content">content of the overlay</div>
|
<div slot="content">content of the overlay</div>
|
||||||
<button slot="invoker">invoker button</button>
|
<button slot="invoker">invoker button</button>
|
||||||
|
|
@ -121,7 +128,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
||||||
|
|
||||||
it('fires before-opened" event on show', async () => {
|
it('fires before-opened" event on show', async () => {
|
||||||
const beforeSpy = sinon.spy();
|
const beforeSpy = sinon.spy();
|
||||||
el = await fixture(html`
|
const el = await fixture(html`
|
||||||
<${tag} @before-opened="${beforeSpy}">
|
<${tag} @before-opened="${beforeSpy}">
|
||||||
<div slot="content">content of the overlay</div>
|
<div slot="content">content of the overlay</div>
|
||||||
<button slot="invoker">invoker button</button>
|
<button slot="invoker">invoker button</button>
|
||||||
|
|
@ -137,7 +144,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
||||||
function preventer(ev) {
|
function preventer(ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
}
|
}
|
||||||
el = await fixture(html`
|
const el = await fixture(html`
|
||||||
<${tag} @before-opened="${preventer}" @before-closed="${preventer}">
|
<${tag} @before-opened="${preventer}" @before-closed="${preventer}">
|
||||||
<div slot="content">content of the overlay</div>
|
<div slot="content">content of the overlay</div>
|
||||||
<button slot="invoker">invoker button</button>
|
<button slot="invoker">invoker button</button>
|
||||||
|
|
@ -164,7 +171,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
||||||
</button>
|
</button>
|
||||||
`);
|
`);
|
||||||
|
|
||||||
el = await fixture(html`
|
const el = await fixture(html`
|
||||||
<${tag} opened>
|
<${tag} opened>
|
||||||
<div slot="content">
|
<div slot="content">
|
||||||
content of the overlay
|
content of the overlay
|
||||||
|
|
@ -179,6 +186,15 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe(`OverlayMixin${suffix} nested`, () => {
|
describe(`OverlayMixin${suffix} nested`, () => {
|
||||||
|
// For some reason, globalRootNode is not cleared properly on disconnectedCallback from previous overlay test fixtures...
|
||||||
|
// Not sure why this "bug" happens...
|
||||||
|
beforeEach(() => {
|
||||||
|
const globalRootNode = document.querySelector('.global-overlays');
|
||||||
|
if (globalRootNode) {
|
||||||
|
globalRootNode.innerHTML = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('supports nested overlays', async () => {
|
it('supports nested overlays', async () => {
|
||||||
const el = await fixture(html`
|
const el = await fixture(html`
|
||||||
<${tag}>
|
<${tag}>
|
||||||
|
|
@ -216,7 +232,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
||||||
</${tag}>
|
</${tag}>
|
||||||
`);
|
`);
|
||||||
|
|
||||||
const mainEl = await fixture(html`
|
const el = await fixture(html`
|
||||||
<${tag} id="main">
|
<${tag} id="main">
|
||||||
<div slot="content" id="mainContent">
|
<div slot="content" id="mainContent">
|
||||||
open nested overlay:
|
open nested overlay:
|
||||||
|
|
@ -226,7 +242,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
||||||
</${tag}>
|
</${tag}>
|
||||||
`);
|
`);
|
||||||
|
|
||||||
if (mainEl._overlayCtrl.placementMode === 'global') {
|
if (el._overlayCtrl.placementMode === 'global') {
|
||||||
// Specifically checking the output in global root node, because the _contentOverlayNode still references
|
// Specifically checking the output in global root node, because the _contentOverlayNode still references
|
||||||
// the node that was removed in the teardown but hasn't been garbage collected due to reference to it still existing..
|
// the node that was removed in the teardown but hasn't been garbage collected due to reference to it still existing..
|
||||||
|
|
||||||
|
|
@ -240,7 +256,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
||||||
);
|
);
|
||||||
expect(lastContentNodeInContainer.firstElementChild.slot).to.equal('content');
|
expect(lastContentNodeInContainer.firstElementChild.slot).to.equal('content');
|
||||||
} else {
|
} else {
|
||||||
const contentNode = mainEl._overlayContentNode.querySelector('#nestedContent');
|
const contentNode = el._overlayContentNode.querySelector('#nestedContent');
|
||||||
expect(contentNode).to.not.be.null;
|
expect(contentNode).to.not.be.null;
|
||||||
expect(contentNode.innerText).to.equal('content of the nested overlay');
|
expect(contentNode.innerText).to.equal('content of the nested overlay');
|
||||||
}
|
}
|
||||||
|
|
@ -257,7 +273,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
||||||
const setupOverlayCtrlSpy = sinon.spy(nestedEl, '_setupOverlayCtrl');
|
const setupOverlayCtrlSpy = sinon.spy(nestedEl, '_setupOverlayCtrl');
|
||||||
const teardownOverlayCtrlSpy = sinon.spy(nestedEl, '_teardownOverlayCtrl');
|
const teardownOverlayCtrlSpy = sinon.spy(nestedEl, '_teardownOverlayCtrl');
|
||||||
|
|
||||||
const mainEl = await fixture(html`
|
const el = await fixture(html`
|
||||||
<${tag} id="main">
|
<${tag} id="main">
|
||||||
<div slot="content" id="mainContent">
|
<div slot="content" id="mainContent">
|
||||||
open nested overlay:
|
open nested overlay:
|
||||||
|
|
@ -279,7 +295,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
||||||
// And we detect this time the disconnect was 'permanent'
|
// And we detect this time the disconnect was 'permanent'
|
||||||
expect(teardownOverlayCtrlSpy.callCount).to.equal(1);
|
expect(teardownOverlayCtrlSpy.callCount).to.equal(1);
|
||||||
|
|
||||||
mainEl._overlayContentNode.appendChild(nestedEl);
|
el._overlayContentNode.appendChild(nestedEl);
|
||||||
await aTimeout();
|
await aTimeout();
|
||||||
expect(setupOverlayCtrlSpy.callCount).to.equal(1);
|
expect(setupOverlayCtrlSpy.callCount).to.equal(1);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
42
wallaby.js
42
wallaby.js
|
|
@ -1,42 +0,0 @@
|
||||||
const wallabyWebpack = require('wallaby-webpack'); // eslint-disable-line import/no-extraneous-dependencies
|
|
||||||
|
|
||||||
// filter packages, e.g. 'core' / '{radio,radio-button}' / '{form,input*}'
|
|
||||||
const packagePattern = '*';
|
|
||||||
|
|
||||||
const replaceAll = (str, oldValue, newValue) => str.split(oldValue).join(newValue);
|
|
||||||
|
|
||||||
const countOccurences = (str, subbstr) => str.split(subbstr).length - 1;
|
|
||||||
|
|
||||||
const makeLionImportsRelative = file => {
|
|
||||||
// example:
|
|
||||||
// file.path: 'packages/package-name/src/my-element.js'
|
|
||||||
// old imports: '@lion/package-name'
|
|
||||||
// new imports: '../../package-name'
|
|
||||||
const nestLevel = countOccurences(file.path, '/') - 1; // 3 - 1 = 2
|
|
||||||
return replaceAll(file.content, '@lion/', '../'.repeat(nestLevel)); // '@lion/' => '../../'
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = () => ({
|
|
||||||
files: [
|
|
||||||
{ pattern: `packages/${packagePattern}/*.js`, load: false },
|
|
||||||
{ pattern: `packages/${packagePattern}/{src,translations,test}/**/*.js`, load: false },
|
|
||||||
{ pattern: `packages/${packagePattern}/test/**/*.test.js`, ignore: true },
|
|
||||||
],
|
|
||||||
filesWithNoCoverageCalculated: [
|
|
||||||
`packages/${packagePattern}/*.js`,
|
|
||||||
`packages/${packagePattern}/test/**/*.js`,
|
|
||||||
],
|
|
||||||
tests: [{ pattern: `packages/${packagePattern}/test/**/*.test.js`, load: false }],
|
|
||||||
testFramework: 'mocha',
|
|
||||||
env: {
|
|
||||||
kind: 'chrome',
|
|
||||||
},
|
|
||||||
preprocessors: {
|
|
||||||
'**/*.js': makeLionImportsRelative,
|
|
||||||
},
|
|
||||||
postprocessor: wallabyWebpack(),
|
|
||||||
setup: () => {
|
|
||||||
// required to trigger test loading
|
|
||||||
window.__moduleBundler.loadTests();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
Loading…
Reference in a new issue