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(sbb-overlay): add visual tests #2864

Merged
merged 8 commits into from
Jul 3, 2024
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* @web/test-runner snapshot v1 */
export const snapshots = {};

snapshots["sbb-overlay renders - DOM"] =
snapshots["sbb-overlay renders DOM"] =
`<sbb-overlay data-state="opening">
</sbb-overlay>
`;
/* end snapshot sbb-overlay renders - DOM */
/* end snapshot sbb-overlay renders DOM */

snapshots["sbb-overlay renders - Shadow DOM"] =
snapshots["sbb-overlay renders Shadow DOM"] =
`<div class="sbb-overlay__container">
<div class="sbb-overlay">
<div class="sbb-overlay__wrapper">
Expand Down Expand Up @@ -43,9 +43,9 @@ snapshots["sbb-overlay renders - Shadow DOM"] =
<sbb-screen-reader-only aria-live="polite">
</sbb-screen-reader-only>
`;
/* end snapshot sbb-overlay renders - Shadow DOM */
/* end snapshot sbb-overlay renders Shadow DOM */

snapshots["sbb-overlay A11y tree Chrome"] =
snapshots["sbb-overlay renders A11y tree Chrome"] =
`<p>
{
"role": "WebArea",
Expand All @@ -64,9 +64,9 @@ snapshots["sbb-overlay A11y tree Chrome"] =
}
</p>
`;
/* end snapshot sbb-overlay A11y tree Chrome */
/* end snapshot sbb-overlay renders A11y tree Chrome */

snapshots["sbb-overlay A11y tree Firefox"] =
snapshots["sbb-overlay renders A11y tree Firefox"] =
`<p>
{
"role": "document",
Expand All @@ -85,5 +85,5 @@ snapshots["sbb-overlay A11y tree Firefox"] =
}
</p>
`;
/* end snapshot sbb-overlay A11y tree Firefox */
/* end snapshot sbb-overlay renders A11y tree Firefox */

30 changes: 18 additions & 12 deletions src/elements/overlay/overlay.snapshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ import type { SbbOverlayElement } from './overlay.js';
import './overlay.js';

describe('sbb-overlay', () => {
let root: SbbOverlayElement;
beforeEach(async () => {
root = await fixture(html`<sbb-overlay></sbb-overlay>`);
root.open();
await waitForLitRender(root);
});
it('renders - DOM', async () => {
await expect(root).dom.to.be.equalSnapshot();
});
it('renders - Shadow DOM', async () => {
await expect(root).shadowDom.to.be.equalSnapshot();
describe('renders', () => {
let root: SbbOverlayElement;

beforeEach(async () => {
root = await fixture(html`<sbb-overlay></sbb-overlay>`);
root.open();
await waitForLitRender(root);
});

it('DOM', async () => {
await expect(root).dom.to.be.equalSnapshot();
});

it('Shadow DOM', async () => {
await expect(root).shadowDom.to.be.equalSnapshot();
});

testA11yTreeSnapshot();
});
testA11yTreeSnapshot();
});
60 changes: 60 additions & 0 deletions src/elements/overlay/overlay.visual.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { html, type TemplateResult } from 'lit';
DavideMininni-Fincons marked this conversation as resolved.
Show resolved Hide resolved

import { describeViewports, visualDiffDefault } from '../core/testing/private.js';

import './overlay.js';
import type { SbbOverlayElement } from './overlay.js';

describe(`sbb-overlay`, () => {
const defaultArgs = {
expanded: false,
backButton: false,
negative: false,
};

const template = ({ expanded, backButton, negative }: typeof defaultArgs): TemplateResult => html`
<sbb-overlay ?negative=${negative} ?expanded=${expanded} ?back-button=${backButton}>
<div class="overlay-content">
jeripeierSBB marked this conversation as resolved.
Show resolved Hide resolved
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</sbb-overlay>
`;

const openOverlay = (setup: any): void => {
jeripeierSBB marked this conversation as resolved.
Show resolved Hide resolved
const overlay: SbbOverlayElement = setup.snapshotElement.querySelector('sbb-overlay')!;
setup.withSnapshotElement(overlay);
DavideMininni-Fincons marked this conversation as resolved.
Show resolved Hide resolved
setup.withPostSetupAction(() => overlay.open());
};

describeViewports({ viewportHeight: 600 }, () => {
jeripeierSBB marked this conversation as resolved.
Show resolved Hide resolved
for (const negative of [false, true]) {
it(
`negative=${negative} ${visualDiffDefault.name}`,
DavideMininni-Fincons marked this conversation as resolved.
Show resolved Hide resolved
visualDiffDefault.with(async (setup) => {
await setup.withFixture(template({ ...defaultArgs, negative }));
openOverlay(setup);
}),
);

it(
`negative=${negative} backButton ${visualDiffDefault.name}`,
DavideMininni-Fincons marked this conversation as resolved.
Show resolved Hide resolved
visualDiffDefault.with(async (setup) => {
await setup.withFixture(template({ ...defaultArgs, negative, backButton: true }));
openOverlay(setup);
}),
);

it(
`negative=${negative} expanded ${visualDiffDefault.name}`,
DavideMininni-Fincons marked this conversation as resolved.
Show resolved Hide resolved
visualDiffDefault.with(async (setup) => {
await setup.withFixture(template({ ...defaultArgs, negative, expanded: true }));
openOverlay(setup);
}),
);
}
});
});
Loading