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-container, sbb-sticky-bar): add visual spec #2798

Merged
merged 5 commits into from
Jun 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,39 @@ snapshots["sbb-container A11y tree Firefox"] =
`;
/* end snapshot sbb-container A11y tree Firefox */

snapshots["sbb-container renders DOM"] =
`<sbb-container color="white">
</sbb-container>
`;
/* end snapshot sbb-container renders DOM */

snapshots["sbb-container renders Shadow DOM"] =
`<div class="sbb-container">
<slot>
</slot>
</div>
<slot name="sticky-bar">
</slot>
`;
/* end snapshot sbb-container renders Shadow DOM */

snapshots["sbb-container renders A11y tree Chrome"] =
`<p>
{
"role": "WebArea",
"name": ""
}
</p>
`;
/* end snapshot sbb-container renders A11y tree Chrome */

snapshots["sbb-container renders A11y tree Firefox"] =
`<p>
{
"role": "document",
"name": ""
}
</p>
`;
/* end snapshot sbb-container renders A11y tree Firefox */

22 changes: 16 additions & 6 deletions src/elements/container/container/container.snapshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@ import { expect } from '@open-wc/testing';
import { html } from 'lit/static-html.js';

import { fixture, testA11yTreeSnapshot } from '../../core/testing/private.js';

import type { SbbContainerElement } from './container.js';
import './container.js';

describe(`sbb-container`, () => {
it('renders', async () => {
const root = await fixture(html`<sbb-container></sbb-container>`);
describe('renders', () => {
let element: SbbContainerElement;

expect(root).dom.to.be.equal(`<sbb-container color="white"></sbb-container>`);
beforeEach(async () => {
element = await fixture(html` <sbb-container></sbb-container> `);
});

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

testA11yTreeSnapshot(html`<sbb-container></sbb-container>`);
it('Shadow DOM', async () => {
await expect(element).shadowDom.to.be.equalSnapshot();
});

testA11yTreeSnapshot();
});
});
70 changes: 70 additions & 0 deletions src/elements/container/container/container.visual.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { SbbBreakpointUltraMin } from '@sbb-esta/lyne-design-tokens';
import { setViewport } from '@web/test-runner-commands';
import { html, type TemplateResult } from 'lit';

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

import './container.js';
import '../../title.js';
import '../../button.js';

describe(`sbb-container`, () => {
const colorCases = ['transparent', 'white', 'milk'];

const backgroundExpandedCases = [false, true];

const containerContent = (): TemplateResult => html`
<sbb-title level="4">Example title</sbb-title>
<p class="sbb-text-s">The container component will give its content the correct spacing.</p>
<p class="sbb-text-s">
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.
</p>
<sbb-secondary-button style="margin-block-end: 3rem;">See more</sbb-secondary-button>
`;

describeViewports({ viewportHeight: 600 }, () => {
for (const color of colorCases) {
it(
`color=${color}`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(
html` <sbb-container color=${color}> ${containerContent()} </sbb-container> `,
{ backgroundColor: 'var(--sbb-color-silver)', padding: '0' },
);
}),
);
}

it(
`expanded`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(
html` <sbb-container expanded> ${containerContent()} </sbb-container> `,
{ backgroundColor: 'var(--sbb-color-silver)', padding: '0' },
);
}),
);
});

// Test very large screens
for (const backgroundExpanded of backgroundExpandedCases) {
it(
`viewport=custom_background-expanded=${backgroundExpanded}`,
visualDiffDefault.with(async (setup) => {
await setViewport({ width: SbbBreakpointUltraMin + 300, height: 600 });

await setup.withFixture(
html`
<sbb-container ?background-expanded=${backgroundExpanded}>
${containerContent()}
</sbb-container>
`,
{ backgroundColor: 'var(--sbb-color-silver)', padding: '0' },
);
}),
);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,41 @@ snapshots["sbb-sticky-bar A11y tree Firefox"] =
`;
/* end snapshot sbb-sticky-bar A11y tree Firefox */

snapshots["sbb-sticky-bar renders DOM"] =
`<sbb-sticky-bar slot="sticky-bar">
</sbb-sticky-bar>
`;
/* end snapshot sbb-sticky-bar renders DOM */

snapshots["sbb-sticky-bar renders Shadow DOM"] =
`<div class="sbb-sticky-bar__wrapper">
<div class="sbb-sticky-bar">
<slot>
</slot>
</div>
</div>
<div class="sbb-sticky-bar__intersector">
</div>
`;
/* end snapshot sbb-sticky-bar renders Shadow DOM */

snapshots["sbb-sticky-bar renders A11y tree Chrome"] =
`<p>
{
"role": "WebArea",
"name": ""
}
</p>
`;
/* end snapshot sbb-sticky-bar renders A11y tree Chrome */

snapshots["sbb-sticky-bar renders A11y tree Firefox"] =
`<p>
{
"role": "document",
"name": ""
}
</p>
`;
/* end snapshot sbb-sticky-bar renders A11y tree Firefox */

22 changes: 16 additions & 6 deletions src/elements/container/sticky-bar/sticky-bar.snapshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@ import { expect } from '@open-wc/testing';
import { html } from 'lit/static-html.js';

import { fixture, testA11yTreeSnapshot } from '../../core/testing/private.js';

import type { SbbStickyBarElement } from './sticky-bar.js';
import './sticky-bar.js';

describe(`sbb-sticky-bar`, () => {
it('renders', async () => {
const root = await fixture(html`<sbb-sticky-bar></sbb-sticky-bar>`);
describe('renders', () => {
let element: SbbStickyBarElement;

expect(root).dom.to.be.equal(`<sbb-sticky-bar slot="sticky-bar"></sbb-sticky-bar>`);
beforeEach(async () => {
element = await fixture(html` <sbb-sticky-bar></sbb-sticky-bar> `);
});

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

testA11yTreeSnapshot(html`<sbb-sticky-bar></sbb-sticky-bar>`);
it('Shadow DOM', async () => {
await expect(element).shadowDom.to.be.equalSnapshot();
});

testA11yTreeSnapshot();
});
});
2 changes: 1 addition & 1 deletion src/elements/container/sticky-bar/sticky-bar.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const Default: StoryObj = {
export const Expanded: StoryObj = {
render: DefaultTemplate,
argTypes: defaultArgTypes,
args: { ...defaultArgs, expanded: true },
args: { ...defaultArgs, containerExpanded: true },
};

export const White: StoryObj = {
Expand Down
95 changes: 95 additions & 0 deletions src/elements/container/sticky-bar/sticky-bar.visual.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { SbbBreakpointMediumMin } from '@sbb-esta/lyne-design-tokens';
import { setViewport } from '@web/test-runner-commands';
import { html, type TemplateResult } from 'lit';

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

import './sticky-bar.js';
import '../container.js';
import '../../action-group.js';
import '../../button.js';
import '../../link.js';
import '../../title.js';

describe(`sbb-sticky-bar`, () => {
let root: HTMLElement;

const cases = {
color: [undefined, 'white', 'milk'],
containerExpanded: [false, true],
scrolled: [false, true],
};

const containerContent = (): TemplateResult => html`
<sbb-title level="4">Example title</sbb-title>
<p class="sbb-text-s">The container component will give its content the correct spacing.</p>
<sbb-secondary-button style="margin-block-end: 0.75rem;" size="m"
>See more</sbb-secondary-button
>
`;

const actionGroup = (): TemplateResult => html`
<sbb-action-group align-group="stretch" orientation="vertical" style="width:100%;">
<sbb-block-link align-self="start" icon-name="chevron-small-left-small">
Link
</sbb-block-link>
<sbb-button>Confirm</sbb-button>
</sbb-action-group>
`;

describeViewports(() => {
describeEach(cases, ({ color, containerExpanded, scrolled }) => {
beforeEach(async function () {
const element = await visualRegressionFixture(
html`
<div id="scroll-container" style="overflow: auto; height: 400px;">
<sbb-container
?expanded=${containerExpanded}
style="--sbb-container-background-color: var(--sbb-color-cloud)"
>
${containerContent()} ${containerContent()} ${containerContent()}
<p>Content end</p>
<sbb-sticky-bar .color=${color}> ${actionGroup()} </sbb-sticky-bar>
</sbb-container>
</div>
`,
{ padding: '0' },
);

root = element.querySelector('#scroll-container')!;

if (scrolled) {
root.scrollTop = root.scrollHeight;
await waitForLitRender(root);
}
});

it(
visualDiffDefault.name,
visualDiffDefault.with((setup) => {
setup.withSnapshotElement(root);
}),
);
});
});

it(
`viewport=medium_short content`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(
TomMenga marked this conversation as resolved.
Show resolved Hide resolved
html` <sbb-container>
${containerContent()}
<sbb-sticky-bar color="milk"> ${actionGroup()} </sbb-sticky-bar>
</sbb-container>`,
{ padding: '0' },
);
await setViewport({ width: SbbBreakpointMediumMin, height: 400 });
}),
);
});
Loading