Skip to content

Commit

Permalink
test: refactor tests to avoid relying on implementation details (#8634)
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen authored Feb 4, 2025
1 parent a69ec93 commit ecd418f
Showing 1 changed file with 8 additions and 9 deletions.
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 @@ -6,6 +6,13 @@ import '../vaadin-form-layout.js';
import '../vaadin-form-item.js';
import '@polymer/polymer/lib/elements/dom-repeat.js';

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 @@ -235,13 +242,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 @@ -437,8 +437,7 @@ describe('form layout', () => {
container.hidden = false;
await nextResize(layout);

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

0 comments on commit ecd418f

Please sign in to comment.