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: replace unit tests with visual tests #8593

Merged
merged 5 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
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
74 changes: 0 additions & 74 deletions packages/form-layout/test/form-layout.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,80 +171,6 @@ describe('form layout', () => {
});
});

describe('container overflow', () => {
let container, layout;

beforeEach(() => {
container = fixtureSync(`
<div style="width: 300px; overflow: auto;">
<vaadin-form-layout responsive-steps='[{"columns": 3}]'>
<div at-start>1 start</div>
<div>2 mid</div>
<div at-end>3 end</div>
<br>
<div style="display: none;">invisible</div>
<div at-start colspan="2">4 start</div>
<div style="display: none;">invisible</div>
<br>
<div at-start>5 start</div>
<div colspan="2" at-end>6 end</div>
<div colspan="2" at-start>7 start</div>
<div at-end>8 end</div>
<div colspan="3" at-start at-end>9 start to end</div>
</vaadin-form-layout>
</div>
`);
layout = container.firstElementChild;
});

it('should not overflow containers horizontally', () => {
expect(container.scrollWidth).to.equal(container.clientWidth);
});

it('should maintain the colspan value before the line break', () => {
const secondItemRect = layout.children[1].getBoundingClientRect();
const fourthItemRect = layout.children[5].getBoundingClientRect();
expect(secondItemRect.right).to.be.closeTo(fourthItemRect.right, 0.5);
});

describe('no spacing on edges', () => {
it('should not have spacing on the left edge', () => {
const containerRect = container.getBoundingClientRect();
Array.from(layout.querySelectorAll('[at-start]')).forEach((child) => {
expect(child.getBoundingClientRect().left).to.be.closeTo(containerRect.left, 0.5);
});
});

it('should not have spacing on the right edge', () => {
const containerRect = container.getBoundingClientRect();
Array.from(layout.querySelectorAll('[at-end]')).forEach((child) => {
expect(child.getBoundingClientRect().right).to.be.closeTo(containerRect.right, 0.5);
});
});
});

describe('no spacing on edges (rtl)', () => {
beforeEach(async () => {
container.dir = 'rtl';
await aTimeout(100);
});

it('should not have spacing on the right edge', () => {
const containerRect = container.getBoundingClientRect();
Array.from(layout.querySelectorAll('[at-start]')).forEach((child) => {
expect(child.getBoundingClientRect().right).to.be.closeTo(containerRect.right, 0.5);
});
});

it('should not have spacing on the left edge', () => {
const containerRect = container.getBoundingClientRect();
Array.from(layout.querySelectorAll('[at-end]')).forEach((child) => {
expect(child.getBoundingClientRect().left).to.be.closeTo(containerRect.left, 0.5);
});
});
});
});

describe('responsiveSteps property', () => {
let layout;

Expand Down
52 changes: 52 additions & 0 deletions packages/form-layout/test/visual/lumo/form-layout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,56 @@ describe('form-layout', () => {
await visualDiff(element, 'required-indicator-labels-on-top');
});
});

['ltr', 'rtl'].forEach((dir) => {
describe(dir, () => {
before(() => {
document.documentElement.setAttribute('dir', dir);
});

after(() => {
document.documentElement.removeAttribute('dir');
});

describe('container overflow', () => {
beforeEach(() => {
element = fixtureSync(`
<div style="display: inline-block; padding: 10px">
<style>
vaadin-form-layout > div:nth-child(even) {
background: var(--lumo-contrast-10pct);
}

vaadin-form-layout > div:nth-child(odd) {
background: var(--lumo-contrast-50pct);
}
</style>

<div style="width: 300px; overflow: auto; border: 1px solid;">
<vaadin-form-layout responsive-steps='[{"columns": 3}]'>
<div>1/3</div>
<div>1/3</div>
<div>1/3</div>
<br>
<div style="display: none;">hidden</div>
<div colspan="2">2/3</div>
<div style="display: none;">hidden</div>
<br>
<div>1/3</div>
<div colspan="2">2/3</div>
<div colspan="2">2/3</div>
<div>1/3</div>
<div colspan="3">3/3</div>
</vaadin-form-layout>
</div>
</div>
`);
});

it('basic', async () => {
await visualDiff(element, `${dir}-container-overflow`);
});
});
});
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.