diff --git a/src/elements/teaser/teaser.visual.spec.ts b/src/elements/teaser/teaser.visual.spec.ts new file mode 100644 index 0000000000..333707296d --- /dev/null +++ b/src/elements/teaser/teaser.visual.spec.ts @@ -0,0 +1,137 @@ +import { html, nothing } from 'lit'; +import { repeat } from 'lit/directives/repeat.js'; + +import { + describeEach, + describeViewports, + visualDiffDefault, + visualDiffFocus, + visualDiffHover, +} from '../core/testing/private.js'; +import { waitForImageReady } from '../core/testing.js'; + +import './teaser.js'; + +const imageUrl = import.meta.resolve('../core/testing/assets/placeholder-image.png'); + +describe(`sbb-teaser`, () => { + const loremIpsum: string = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer enim elit, ultricies in tincidunt + quis, mattis eu quam. Nulla sit amet lorem fermentum, molestie nunc ut, hendrerit risus. Vestibulum rutrum elit et + lacus sollicitudin, quis malesuada lorem vehicula. Suspendisse at augue quis tellus vulputate tempor. Vivamus urna + velit, varius nec est ac, mollis efficitur lorem. Quisque non nisl eget massa interdum tempus. Praesent vel feugiat + metus. Donec pharetra odio at turpis bibendum, vel commodo dui vulputate. Aenean congue nec nisl vel bibendum. + Praesent sit amet lorem augue. Suspendisse ornare a justo sagittis fermentum.`; + const longChip: string = + 'This is a chip which has a very long content and should receive ellipsis.'; + + const visualStates = { + hasChip: [false, true], + withLongContent: [false, true], + }; + + const screenCombinations = [ + { viewport: 'micro' as const, alignments: ['below'] }, + { viewport: 'medium' as const, alignments: ['after-centered', 'after', 'below'] }, + ]; + + for (const screenCombination of screenCombinations) { + describeViewports({ viewports: [screenCombination.viewport] }, () => { + for (const alignment of screenCombination.alignments) { + describe(`alignment=${alignment}`, () => { + for (const visualDiffStandardState of [ + visualDiffDefault, + visualDiffFocus, + visualDiffHover, + ]) { + it( + `state=${visualDiffStandardState.name}`, + visualDiffStandardState.with(async (setup) => { + await setup.withFixture( + html` + + + This is a paragraph + + `, + { maxWidth: '760px' }, + ); + await waitForImageReady(setup.snapshotElement.querySelector('img')!); + }), + ); + } + + describeEach(visualStates, ({ hasChip, withLongContent }) => { + it( + '', + visualDiffDefault.with(async (setup) => { + await setup.withFixture( + html` + + + ${withLongContent ? loremIpsum : 'This is a paragraph'} + + `, + { maxWidth: '760px' }, + ); + await waitForImageReady(setup.snapshotElement.querySelector('img')!); + }), + ); + }); + + it( + `longChip=true`, + visualDiffDefault.with(async (setup) => { + await setup.withFixture( + html` + + + This is a paragraph + + `, + { maxWidth: '760px' }, + ); + await waitForImageReady(setup.snapshotElement.querySelector('img')!); + }), + ); + + it( + `list=true`, + visualDiffDefault.with(async (setup) => { + await setup.withFixture(html` + + `); + await waitForImageReady(setup.snapshotElement.querySelector('img')!); + }), + ); + }); + } + }); + } +});