diff --git a/src/elements/container/container/__snapshots__/container.snapshot.spec.snap.js b/src/elements/container/container/__snapshots__/container.snapshot.spec.snap.js index 58408a898b..2f06efd398 100644 --- a/src/elements/container/container/__snapshots__/container.snapshot.spec.snap.js +++ b/src/elements/container/container/__snapshots__/container.snapshot.spec.snap.js @@ -31,3 +31,39 @@ snapshots["sbb-container A11y tree Firefox"] = `; /* end snapshot sbb-container A11y tree Firefox */ +snapshots["sbb-container renders DOM"] = +` + +`; +/* end snapshot sbb-container renders DOM */ + +snapshots["sbb-container renders Shadow DOM"] = +`
+ + +
+ + +`; +/* end snapshot sbb-container renders Shadow DOM */ + +snapshots["sbb-container renders A11y tree Chrome"] = +`

+ { + "role": "WebArea", + "name": "" +} +

+`; +/* end snapshot sbb-container renders A11y tree Chrome */ + +snapshots["sbb-container renders A11y tree Firefox"] = +`

+ { + "role": "document", + "name": "" +} +

+`; +/* end snapshot sbb-container renders A11y tree Firefox */ + diff --git a/src/elements/container/container/container.snapshot.spec.ts b/src/elements/container/container/container.snapshot.spec.ts index 5ffe18e2d1..55333c091a 100644 --- a/src/elements/container/container/container.snapshot.spec.ts +++ b/src/elements/container/container/container.snapshot.spec.ts @@ -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``); + describe('renders', () => { + let element: SbbContainerElement; - expect(root).dom.to.be.equal(``); + beforeEach(async () => { + element = await fixture(html` `); + }); - await expect(root).shadowDom.to.be.equalSnapshot(); - }); + it('DOM', async () => { + await expect(element).dom.to.be.equalSnapshot(); + }); - testA11yTreeSnapshot(html``); + it('Shadow DOM', async () => { + await expect(element).shadowDom.to.be.equalSnapshot(); + }); + + testA11yTreeSnapshot(); + }); }); diff --git a/src/elements/container/container/container.visual.spec.ts b/src/elements/container/container/container.visual.spec.ts new file mode 100644 index 0000000000..8de8704e37 --- /dev/null +++ b/src/elements/container/container/container.visual.spec.ts @@ -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` + Example title +

The container component will give its content the correct spacing.

+

+ 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. +

+ See more + `; + + describeViewports({ viewportHeight: 600 }, () => { + for (const color of colorCases) { + it( + `color=${color}`, + visualDiffDefault.with(async (setup) => { + await setup.withFixture( + html` ${containerContent()} `, + { backgroundColor: 'var(--sbb-color-silver)', padding: '0' }, + ); + }), + ); + } + + it( + `expanded`, + visualDiffDefault.with(async (setup) => { + await setup.withFixture( + html` ${containerContent()} `, + { 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` + + ${containerContent()} + + `, + { backgroundColor: 'var(--sbb-color-silver)', padding: '0' }, + ); + }), + ); + } +}); diff --git a/src/elements/container/sticky-bar/__snapshots__/sticky-bar.snapshot.spec.snap.js b/src/elements/container/sticky-bar/__snapshots__/sticky-bar.snapshot.spec.snap.js index 897e73a3cf..db1885e55e 100644 --- a/src/elements/container/sticky-bar/__snapshots__/sticky-bar.snapshot.spec.snap.js +++ b/src/elements/container/sticky-bar/__snapshots__/sticky-bar.snapshot.spec.snap.js @@ -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"] = +` + +`; +/* end snapshot sbb-sticky-bar renders DOM */ + +snapshots["sbb-sticky-bar renders Shadow DOM"] = +`
+
+ + +
+
+
+
+`; +/* end snapshot sbb-sticky-bar renders Shadow DOM */ + +snapshots["sbb-sticky-bar renders A11y tree Chrome"] = +`

+ { + "role": "WebArea", + "name": "" +} +

+`; +/* end snapshot sbb-sticky-bar renders A11y tree Chrome */ + +snapshots["sbb-sticky-bar renders A11y tree Firefox"] = +`

+ { + "role": "document", + "name": "" +} +

+`; +/* end snapshot sbb-sticky-bar renders A11y tree Firefox */ + diff --git a/src/elements/container/sticky-bar/sticky-bar.snapshot.spec.ts b/src/elements/container/sticky-bar/sticky-bar.snapshot.spec.ts index 39e3eae2a3..573f5e25b9 100644 --- a/src/elements/container/sticky-bar/sticky-bar.snapshot.spec.ts +++ b/src/elements/container/sticky-bar/sticky-bar.snapshot.spec.ts @@ -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``); + describe('renders', () => { + let element: SbbStickyBarElement; - expect(root).dom.to.be.equal(``); + beforeEach(async () => { + element = await fixture(html` `); + }); - await expect(root).shadowDom.to.be.equalSnapshot(); - }); + it('DOM', async () => { + await expect(element).dom.to.be.equalSnapshot(); + }); - testA11yTreeSnapshot(html``); + it('Shadow DOM', async () => { + await expect(element).shadowDom.to.be.equalSnapshot(); + }); + + testA11yTreeSnapshot(); + }); }); diff --git a/src/elements/container/sticky-bar/sticky-bar.stories.ts b/src/elements/container/sticky-bar/sticky-bar.stories.ts index 47268cedbd..f7971333a0 100644 --- a/src/elements/container/sticky-bar/sticky-bar.stories.ts +++ b/src/elements/container/sticky-bar/sticky-bar.stories.ts @@ -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 = { diff --git a/src/elements/container/sticky-bar/sticky-bar.visual.spec.ts b/src/elements/container/sticky-bar/sticky-bar.visual.spec.ts new file mode 100644 index 0000000000..46040c894b --- /dev/null +++ b/src/elements/container/sticky-bar/sticky-bar.visual.spec.ts @@ -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` + Example title +

The container component will give its content the correct spacing.

+ See more + `; + + const actionGroup = (): TemplateResult => html` + + + Link + + Confirm + + `; + + describeViewports(() => { + describeEach(cases, ({ color, containerExpanded, scrolled }) => { + beforeEach(async function () { + const element = await visualRegressionFixture( + html` +
+ + ${containerContent()} ${containerContent()} ${containerContent()} +

Content end

+ ${actionGroup()} +
+
+ `, + { 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( + html` + ${containerContent()} + ${actionGroup()} + `, + { padding: '0' }, + ); + await setViewport({ width: SbbBreakpointMediumMin, height: 400 }); + }), + ); +});