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';
|
||||
|
||||
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', () => {
|
||||
const tagString = 'lion-dialog';
|
||||
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-date/lion-input-date';
|
||||
import '@lion/textarea/lion-textarea';
|
||||
import '@lion/input-datepicker/lion-input-datepicker';
|
||||
import '@lion/input-email/lion-input-email';
|
||||
import '@lion/input-iban/lion-input-iban';
|
||||
import '@lion/input-range/lion-input-range';
|
||||
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-group';
|
||||
import '@lion/select/lion-select';
|
||||
import '@lion/switch/lion-switch';
|
||||
import '@lion/form/lion-form';
|
||||
import '@lion/button/lion-button';
|
||||
import { Required, MinLength } from '@lion/form-core';
|
||||
import '@lion/textarea/lion-textarea';
|
||||
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
|
||||
|
||||
describe(`Submitting/Resetting Form`, async () => {
|
||||
let el;
|
||||
|
|
@ -127,8 +126,6 @@ describe(`Submitting/Resetting Form`, async () => {
|
|||
el.querySelector('#submit_button').click();
|
||||
await elementUpdated(el);
|
||||
el.formElements.forEach(field => {
|
||||
console.log(field);
|
||||
console.log(field.submitted);
|
||||
expect(field.submitted).to.be.true;
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import { expect } from '@open-wc/testing';
|
||||
import { localize } from '../../src/localize.js';
|
||||
import { localizeTearDown } from '../../test-helpers.js';
|
||||
|
||||
import { formatNumber } from '../../src/number/formatNumber.js';
|
||||
import { localizeTearDown } from '../../test-helpers.js';
|
||||
|
||||
const currencyCode = currency => ({ style: 'currency', currencyDisplay: 'code', currency });
|
||||
const currencySymbol = currency => ({ style: 'currency', currencyDisplay: 'symbol', currency });
|
||||
|
|
@ -310,15 +309,17 @@ describe('formatNumber', () => {
|
|||
});
|
||||
|
||||
describe('tr-TR', () => {
|
||||
localize.locale = 'tr-TR';
|
||||
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('JPY'))).to.equal('123.457 JPY');
|
||||
expect(formatNumber(123456.789, currencyCode('TRY'))).to.equal('123.456,79 TL');
|
||||
expect(formatNumber(123456.789, currencySymbol('EUR'))).to.equal('€123.456,79');
|
||||
expect(formatNumber(123456.789, currencySymbol('USD'))).to.equal('$123.456,79');
|
||||
expect(formatNumber(123456.789, currencySymbol('JPY'))).to.equal('¥123.457');
|
||||
expect(formatNumber(123456.789, currencySymbol('TRY'))).to.equal('₺123.456,79');
|
||||
it('supports basics', () => {
|
||||
localize.locale = 'tr-TR';
|
||||
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('JPY'))).to.equal('123.457 JPY');
|
||||
expect(formatNumber(123456.789, currencyCode('TRY'))).to.equal('123.456,79 TL');
|
||||
expect(formatNumber(123456.789, currencySymbol('EUR'))).to.equal('€123.456,79');
|
||||
expect(formatNumber(123456.789, currencySymbol('USD'))).to.equal('$123.456,79');
|
||||
expect(formatNumber(123456.789, currencySymbol('JPY'))).to.equal('¥123.457');
|
||||
expect(formatNumber(123456.789, currencySymbol('TRY'))).to.equal('₺123.456,79');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,23 +10,24 @@ function getGlobalOverlayNodes() {
|
|||
|
||||
export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
||||
describe(`OverlayMixin${suffix}`, () => {
|
||||
let el;
|
||||
|
||||
beforeEach(async () => {
|
||||
el = await fixture(html`
|
||||
it('should not be opened by default', async () => {
|
||||
const el = await fixture(html`
|
||||
<${tag}>
|
||||
<div slot="content">content of the overlay</div>
|
||||
<button slot="invoker">invoker button</button>
|
||||
</${tag}>
|
||||
`);
|
||||
});
|
||||
|
||||
it('should not be opened by default', async () => {
|
||||
expect(el.opened).to.be.false;
|
||||
expect(el._overlayCtrl.isShown).to.be.false;
|
||||
});
|
||||
|
||||
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;
|
||||
expect(el.opened).to.be.true;
|
||||
await nextFrame(); // overlayCtrl show/hide is async
|
||||
|
|
@ -39,6 +40,12 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
|||
});
|
||||
|
||||
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;
|
||||
await el._overlayCtrl.show();
|
||||
expect(el.opened).to.be.true;
|
||||
|
|
@ -86,7 +93,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
|||
|
||||
it('fires "opened-changed" event on hide', async () => {
|
||||
const spy = sinon.spy();
|
||||
el = await fixture(html`
|
||||
const el = await fixture(html`
|
||||
<${tag} @opened-changed="${spy}">
|
||||
<div slot="content">content of the overlay</div>
|
||||
<button slot="invoker">invoker button</button>
|
||||
|
|
@ -105,7 +112,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
|||
|
||||
it('fires "before-closed" event on hide', async () => {
|
||||
const beforeSpy = sinon.spy();
|
||||
el = await fixture(html`
|
||||
const el = await fixture(html`
|
||||
<${tag} @before-closed="${beforeSpy}" .opened="${true}">
|
||||
<div slot="content">content of the overlay</div>
|
||||
<button slot="invoker">invoker button</button>
|
||||
|
|
@ -121,7 +128,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
|||
|
||||
it('fires before-opened" event on show', async () => {
|
||||
const beforeSpy = sinon.spy();
|
||||
el = await fixture(html`
|
||||
const el = await fixture(html`
|
||||
<${tag} @before-opened="${beforeSpy}">
|
||||
<div slot="content">content of the overlay</div>
|
||||
<button slot="invoker">invoker button</button>
|
||||
|
|
@ -137,7 +144,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
|||
function preventer(ev) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
el = await fixture(html`
|
||||
const el = await fixture(html`
|
||||
<${tag} @before-opened="${preventer}" @before-closed="${preventer}">
|
||||
<div slot="content">content of the overlay</div>
|
||||
<button slot="invoker">invoker button</button>
|
||||
|
|
@ -164,7 +171,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
|||
</button>
|
||||
`);
|
||||
|
||||
el = await fixture(html`
|
||||
const el = await fixture(html`
|
||||
<${tag} opened>
|
||||
<div slot="content">
|
||||
content of the overlay
|
||||
|
|
@ -179,6 +186,15 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
|||
});
|
||||
|
||||
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 () => {
|
||||
const el = await fixture(html`
|
||||
<${tag}>
|
||||
|
|
@ -216,7 +232,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
|||
</${tag}>
|
||||
`);
|
||||
|
||||
const mainEl = await fixture(html`
|
||||
const el = await fixture(html`
|
||||
<${tag} id="main">
|
||||
<div slot="content" id="mainContent">
|
||||
open nested overlay:
|
||||
|
|
@ -226,7 +242,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
|||
</${tag}>
|
||||
`);
|
||||
|
||||
if (mainEl._overlayCtrl.placementMode === 'global') {
|
||||
if (el._overlayCtrl.placementMode === 'global') {
|
||||
// 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..
|
||||
|
||||
|
|
@ -240,7 +256,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
|||
);
|
||||
expect(lastContentNodeInContainer.firstElementChild.slot).to.equal('content');
|
||||
} else {
|
||||
const contentNode = mainEl._overlayContentNode.querySelector('#nestedContent');
|
||||
const contentNode = el._overlayContentNode.querySelector('#nestedContent');
|
||||
expect(contentNode).to.not.be.null;
|
||||
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 teardownOverlayCtrlSpy = sinon.spy(nestedEl, '_teardownOverlayCtrl');
|
||||
|
||||
const mainEl = await fixture(html`
|
||||
const el = await fixture(html`
|
||||
<${tag} id="main">
|
||||
<div slot="content" id="mainContent">
|
||||
open nested overlay:
|
||||
|
|
@ -279,7 +295,7 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
|
|||
// And we detect this time the disconnect was 'permanent'
|
||||
expect(teardownOverlayCtrlSpy.callCount).to.equal(1);
|
||||
|
||||
mainEl._overlayContentNode.appendChild(nestedEl);
|
||||
el._overlayContentNode.appendChild(nestedEl);
|
||||
await aTimeout();
|
||||
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