Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cristinecula committed Feb 28, 2024
1 parent 40b2748 commit 36de096
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 26 deletions.
10 changes: 9 additions & 1 deletion test/autocomplete.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/* eslint-disable max-lines */
import { assert, html, nextFrame } from '@open-wc/testing';

import { setupOmnitableFixture } from './helpers/utils';
import {
ignoreResizeObserverLoopErrors,
rowVisible,
setupOmnitableFixture,
} from './helpers/utils';

import '../cosmoz-omnitable.js';
import { getComparableValue } from '../cosmoz-omnitable-column-autocomplete.js';
Expand Down Expand Up @@ -422,10 +427,12 @@ const basicFixture = html`
`;

suite('autocomplete unit tests', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
let omnitable;

setup(async () => {
omnitable = await setupOmnitableFixture(basicFixture, data.slice(0));
await rowVisible();
});

test('basic render test', async () => {
Expand Down Expand Up @@ -454,6 +461,7 @@ suite('autocomplete unit tests', () => {
});

suite('values as function', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
test('displays values from a source function', async () => {
const data = [
{
Expand Down
13 changes: 12 additions & 1 deletion test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { assert, expect, html, nextFrame } from '@open-wc/testing';
import { assert as sinonAssert, spy } from 'sinon';

import '../demo/helpers/cosmoz-translations';
import { setupOmnitableFixture } from './helpers/utils';
import { ignoreResizeObserverLoopErrors, rowVisible, setupOmnitableFixture } from './helpers/utils';
import { generateTableDemoData } from '../demo/table-demo-helper';
import { flush } from '@polymer/polymer/lib/utils/flush';

Expand All @@ -16,6 +16,7 @@ import { columnSymbol } from '../lib/use-dom-columns';
sinonAssert.expose(assert, { prefix: '' });

suite('basic', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
let omnitable, columnWithoutGroupOn;

setup(async () => {
Expand Down Expand Up @@ -140,6 +141,7 @@ suite('basic', () => {
});

suite('default-config', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
test('default valuePath is name', async () => {
const omnitable = await setupOmnitableFixture(
html`
Expand Down Expand Up @@ -169,6 +171,7 @@ suite('default-config', () => {
});

suite('item update effects', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
let omnitable;

setup(async () => {
Expand Down Expand Up @@ -217,6 +220,7 @@ suite('item update effects', () => {
});

suite('render cell function', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
let omnitable;

setup(async () => {
Expand Down Expand Up @@ -297,6 +301,7 @@ suite('render cell function', () => {
});

suite('render header function', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
let omnitable;

const getRows = () =>
Expand Down Expand Up @@ -381,6 +386,7 @@ suite('render header function', () => {
});

suite('fit columns behaviour', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
let omnitable;

setup(async () => {
Expand Down Expand Up @@ -422,6 +428,7 @@ suite('fit columns behaviour', () => {
`,
data,
);
await rowVisible();
});

test('it adjusts the visible columns based on the available width', async () => {
Expand All @@ -436,6 +443,7 @@ suite('fit columns behaviour', () => {
await nextFrame();
await nextFrame();
await nextFrame();
await nextFrame();

assert.deepEqual(
Array.from(omnitable.shadowRoot.querySelectorAll('.header-cell')).map(
Expand All @@ -448,6 +456,7 @@ suite('fit columns behaviour', () => {
await nextFrame();
await nextFrame();
await nextFrame();
await nextFrame();

assert.deepEqual(
Array.from(omnitable.shadowRoot.querySelectorAll('.header-cell')).map(
Expand All @@ -459,6 +468,7 @@ suite('fit columns behaviour', () => {
});

suite('render group function', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
let omnitable;

setup(async () => {
Expand Down Expand Up @@ -497,6 +507,7 @@ suite('render group function', () => {
});

suite('enabled columns', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
test('displays only enabled columns', async () => {
const omnitable = await setupOmnitableFixture(
html` <cosmoz-omnitable
Expand Down
3 changes: 2 additions & 1 deletion test/boolean.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert, html } from '@open-wc/testing';

import { spy } from 'sinon';
import { setupOmnitableFixture } from './helpers/utils';
import { ignoreResizeObserverLoopErrors, setupOmnitableFixture } from './helpers/utils';

import '../cosmoz-omnitable.js';
import '../cosmoz-omnitable-columns.js';
Expand All @@ -17,6 +17,7 @@ import { serializeFilter } from '../cosmoz-omnitable-column-mixin';
import { columnSymbol } from '../lib/use-dom-columns';

suite('boolean', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
test('initializes boolean column', async () => {
const data = [
{ boolean: true },
Expand Down
2 changes: 2 additions & 0 deletions test/expand-line.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { fixture, html, assert } from '@open-wc/testing';
import '../cosmoz-omnitable-item-expand-line';
import { ignoreResizeObserverLoopErrors } from './helpers/utils';

suite('cosmoz-omnitable-item-expand-line', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
test('initializes correctly', async () => {
const el = await fixture(
html`<cosmoz-omnitable-item-expand-line
Expand Down
5 changes: 4 additions & 1 deletion test/group.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { assert, html, nextFrame } from '@open-wc/testing';

import { setupOmnitableFixture } from './helpers/utils';
import { ignoreResizeObserverLoopErrors, setupOmnitableFixture } from './helpers/utils';
import { generateTableDemoData } from '../demo/table-demo-helper';

import '../cosmoz-omnitable.js';
import '../cosmoz-omnitable-columns.js';

suite('id', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
let omnitable, data;

setup(async () => {
Expand Down Expand Up @@ -62,6 +63,7 @@ suite('id', () => {
});

suite('bool', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
let omnitable, data;

setup(async () => {
Expand Down Expand Up @@ -118,6 +120,7 @@ suite('bool', () => {
});

suite('amount', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
let omnitable, data;

setup(async () => {
Expand Down
7 changes: 3 additions & 4 deletions test/hash-param-read.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, html, nextFrame } from '@open-wc/testing';
import { assert, html } from '@open-wc/testing';

import { setupOmnitableFixture } from './helpers/utils';
import { ignoreResizeObserverLoopErrors, setupOmnitableFixture } from './helpers/utils';

import '../cosmoz-omnitable.js';
import '../cosmoz-omnitable-column-autocomplete.js';
Expand Down Expand Up @@ -31,7 +31,6 @@ const data = [
],
location = window.location,
instantiate = async () => {
await nextFrame();
omnitable = await setupOmnitableFixture(
html`
<cosmoz-omnitable
Expand Down Expand Up @@ -69,10 +68,10 @@ const data = [
`,
data,
);
await nextFrame();
};

suite('basic-read', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
setup(() => {
location.hash = '#!/';
});
Expand Down
3 changes: 2 additions & 1 deletion test/hash-param-write.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, html, nextFrame } from '@open-wc/testing';

import { setupOmnitableFixture } from './helpers/utils';
import { ignoreResizeObserverLoopErrors, setupOmnitableFixture } from './helpers/utils';

import '../cosmoz-omnitable.js';
import '../cosmoz-omnitable-column-autocomplete.js';
Expand Down Expand Up @@ -73,6 +73,7 @@ const data = [
};

suite('basic-write', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
setup(async () => {
location.hash = '#!/';
await instantiate();
Expand Down
41 changes: 36 additions & 5 deletions test/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
import { fixture, nextFrame } from '@open-wc/testing';
import { flush } from '@polymer/polymer/lib/utils/flush';
import { fixture } from '@open-wc/testing';
import { perform } from '@neovici/cfg/web/perform.js';

export const setupOmnitableFixture = async (omnitableFixture, data) => {
const omnitable = await fixture(omnitableFixture);

await perform(async ({ page, expect }) => {
await expect(page.locator('cosmoz-omnitable-header-row')).toBeVisible();

Check warning on line 8 in test/helpers/utils.js

View check run for this annotation

Codecov / codecov/patch

test/helpers/utils.js#L8

Added line #L8 was not covered by tests
});

omnitable.data = data;
await nextFrame();
flush();
await nextFrame();
return omnitable;
};

export const rowVisible = async () => {
await perform(async ({ page, expect }) => {
await expect(page.locator('.itemRow').first()).toBeVisible();

Check warning on line 17 in test/helpers/utils.js

View check run for this annotation

Codecov / codecov/patch

test/helpers/utils.js#L17

Added line #L17 was not covered by tests
});
};

export const ignoreResizeObserverLoopErrors = (setup, teardown) => {
// called before any tests are run
const e = window.onerror;

setup(() => {
window.onerror = function (err) {
if (
err === 'ResizeObserver loop limit exceeded' ||
err === 'ResizeObserver loop completed with undelivered notifications.'
) {
// eslint-disable-next-line no-console
console.warn('Ignored:', err);
return false;
}
return e(...arguments);

Check warning on line 35 in test/helpers/utils.js

View check run for this annotation

Codecov / codecov/patch

test/helpers/utils.js#L35

Added line #L35 was not covered by tests
};
});

teardown(() => {
window.onerror = e;
});
};
5 changes: 4 additions & 1 deletion test/list.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, html } from '@open-wc/testing';

import { setupOmnitableFixture } from './helpers/utils';
import { ignoreResizeObserverLoopErrors, rowVisible, setupOmnitableFixture } from './helpers/utils';

import '../cosmoz-omnitable.js';
import '../cosmoz-omnitable-columns.js';
Expand All @@ -12,6 +12,7 @@ import {
import { columnSymbol } from '../lib/use-dom-columns';

suite('basic', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
let omnitable, column, data;

setup(async () => {
Expand Down Expand Up @@ -43,6 +44,7 @@ suite('basic', () => {
});

suite('horizontal', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
let omnitable, column, data;

setup(async () => {
Expand All @@ -69,6 +71,7 @@ suite('horizontal', () => {
});

test('basic render', async () => {
await rowVisible();
const cells = Array.from(
omnitable.shadowRoot.querySelectorAll('.itemRow-cell'),
);
Expand Down
8 changes: 7 additions & 1 deletion test/range-amount.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { assert, html, nextFrame } from '@open-wc/testing';

import { assert as sinonAssert } from 'sinon';

import { setupOmnitableFixture } from './helpers/utils';
import {
ignoreResizeObserverLoopErrors,
setupOmnitableFixture,
} from './helpers/utils';
import { flush } from '@polymer/polymer/lib/utils/flush';

import '../cosmoz-omnitable.js';
Expand Down Expand Up @@ -92,6 +95,7 @@ const data = [
sinonAssert.expose(assert, { prefix: '' });

suite('amount', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
const rates = undefined;
let omnitable, column, columnHeaderInput;

Expand Down Expand Up @@ -383,6 +387,7 @@ suite('amount', () => {
});

suite('currency rates', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
let omnitable, column, columnHeaderInput;

const rates = {
Expand Down Expand Up @@ -875,6 +880,7 @@ suite('currency rates', () => {
});

suite('default currency', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
let omnitable, column, columnHeaderInput;

setup(async () => {
Expand Down
14 changes: 9 additions & 5 deletions test/range-date.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { assert, html, nextFrame } from '@open-wc/testing';
import { assert as sinonAssert } from 'sinon';

import { setupOmnitableFixture } from './helpers/utils';
import { ignoreResizeObserverLoopErrors, rowVisible, setupOmnitableFixture } from './helpers/utils';
import { flush as polymerFlush } from '@polymer/polymer/lib/utils/flush';

import '../cosmoz-omnitable.js';
Expand Down Expand Up @@ -99,17 +99,21 @@ const data = [
sinonAssert.expose(assert, { prefix: '' });

suite('render', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
test('basic render', async () => {
const omnitable = await setupOmnitableFixture(rangeFixture, data),
cells = Array.from(
omnitable.shadowRoot.querySelectorAll('.itemRow-cell'),
);
const omnitable = await setupOmnitableFixture(rangeFixture, data);
await rowVisible();

const cells = Array.from(
omnitable.shadowRoot.querySelectorAll('.itemRow-cell'),
);
assert.isAtLeast(cells.length, 20);
assert.equal(cells[0].innerText, '17');
});
});

suite('date', () => {
ignoreResizeObserverLoopErrors(setup, teardown);
let omnitable, column, columnHeaderInput;

setup(async () => {
Expand Down
Loading

0 comments on commit 36de096

Please sign in to comment.