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
Expand Up @@ -10,7 +10,7 @@ export function imageName(test: Mocha.Runnable): string {
return test!.fullTitle().replaceAll(', ', '-').replaceAll(' ', '_').replaceAll('.', '_');
}

class VisualDiffSetupBuilder {
export class VisualDiffSetupBuilder {
private _snapshotElement?: HTMLElement;
private _stateElement?: HTMLElement;
private _postSetupAction?: () => void | Promise<void>;
Expand Down
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();
});
80 changes: 80 additions & 0 deletions src/elements/overlay/overlay.visual.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { html, type TemplateResult } from 'lit';
DavideMininni-Fincons marked this conversation as resolved.
Show resolved Hide resolved
import { repeat } from 'lit/directives/repeat.js';

import type { VisualDiffSetupBuilder } from '../core/testing/private.js';
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,
numberOfBlocks: 1,
};

const template = ({
expanded,
backButton,
negative,
numberOfBlocks,
}: typeof defaultArgs): TemplateResult => html`
<sbb-overlay ?negative=${negative} ?expanded=${expanded} ?back-button=${backButton}>
${repeat(
new Array(numberOfBlocks),
() => html`
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. <br />
`,
)}
</sbb-overlay>
`;

const openOverlay = (setup: VisualDiffSetupBuilder): void => {
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.with(async (setup) => {
await setup.withFixture(template({ ...defaultArgs, negative }));
openOverlay(setup);
}),
);

it(
`negative=${negative} backButton`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(template({ ...defaultArgs, negative, backButton: true }));
openOverlay(setup);
}),
);

it(
`negative=${negative} expanded`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(template({ ...defaultArgs, negative, expanded: true }));
openOverlay(setup);
}),
);

it(
`negative=${negative} long content`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(template({ ...defaultArgs, negative, numberOfBlocks: 7 }));
openOverlay(setup);
}),
);
}
});
});
Loading