Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor tests to avoid relying on implementation details #8634

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions packages/form-layout/test/form-layout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ customElements.define(
},
);

function estimateEffectiveColumnCount(layout) {
const offsets = [...layout.children]
.filter((child) => getComputedStyle(child).display !== 'none')
.map((child) => child.offsetLeft);
return new Set(offsets).size;
}

function getParsedWidth(el) {
const width = el.style.getPropertyValue('width');
const components = width.replace(/^calc\((.*)\)$/u, '$1').split(/ [+-] /u);
Expand Down Expand Up @@ -271,13 +278,6 @@ describe('form layout', () => {
document.body.style.removeProperty('min-width');
});

function estimateEffectiveColumnCount(layout) {
const offsets = [...layout.children]
.filter((child) => getComputedStyle(child).display !== 'none')
.map((child) => child.offsetLeft);
return new Set(offsets).size;
}

it('should be responsive by default', async () => {
document.body.style.width = '10em';
await nextResize(layout);
Expand Down Expand Up @@ -490,8 +490,7 @@ describe('form layout', () => {
await nextFrame();
await nextFrame();

expect(parseFloat(getParsedWidth(layout.children[0]).percentage)).to.be.closeTo(100, 0.1);
expect(parseFloat(getParsedWidth(layout.children[1]).percentage)).to.be.closeTo(100, 0.1);
expect(estimateEffectiveColumnCount(layout)).to.equal(1);
});

it('should change layout opacity when its parent becomes visible', async () => {
Expand Down