-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(sbb-container, sbb-sticky-bar): add visual spec (#2798)
- Loading branch information
Showing
7 changed files
with
272 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }, | ||
); | ||
}), | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/elements/container/sticky-bar/sticky-bar.visual.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( | ||
html` <sbb-container> | ||
${containerContent()} | ||
<sbb-sticky-bar color="milk"> ${actionGroup()} </sbb-sticky-bar> | ||
</sbb-container>`, | ||
{ padding: '0' }, | ||
); | ||
await setViewport({ width: SbbBreakpointMediumMin, height: 400 }); | ||
}), | ||
); | ||
}); |