-
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-dialog): add visual spec (#2813)
- Loading branch information
Showing
6 changed files
with
241 additions
and
22 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
50 changes: 50 additions & 0 deletions
50
src/elements/dialog/dialog-content/__snapshots__/dialog-content.snapshot.spec.snap.js
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,50 @@ | ||
/* @web/test-runner snapshot v1 */ | ||
export const snapshots = {}; | ||
|
||
snapshots["sbb-dialog-content renders DOM"] = | ||
`<sbb-dialog-content> | ||
Content | ||
</sbb-dialog-content> | ||
`; | ||
/* end snapshot sbb-dialog-content renders DOM */ | ||
|
||
snapshots["sbb-dialog-content renders Shadow DOM"] = | ||
`<div class="sbb-dialog-content"> | ||
<slot> | ||
</slot> | ||
</div> | ||
`; | ||
/* end snapshot sbb-dialog-content renders Shadow DOM */ | ||
|
||
snapshots["sbb-dialog-content renders A11y tree Chrome"] = | ||
`<p> | ||
{ | ||
"role": "WebArea", | ||
"name": "", | ||
"children": [ | ||
{ | ||
"role": "text", | ||
"name": "Content" | ||
} | ||
] | ||
} | ||
</p> | ||
`; | ||
/* end snapshot sbb-dialog-content renders A11y tree Chrome */ | ||
|
||
snapshots["sbb-dialog-content renders A11y tree Firefox"] = | ||
`<p> | ||
{ | ||
"role": "document", | ||
"name": "", | ||
"children": [ | ||
{ | ||
"role": "text leaf", | ||
"name": "Content" | ||
} | ||
] | ||
} | ||
</p> | ||
`; | ||
/* end snapshot sbb-dialog-content renders A11y tree Firefox */ | ||
|
28 changes: 19 additions & 9 deletions
28
src/elements/dialog/dialog-content/dialog-content.snapshot.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 |
---|---|---|
@@ -1,17 +1,27 @@ | ||
import { expect, fixture } from '@open-wc/testing'; | ||
import { expect } from '@open-wc/testing'; | ||
import { html } from 'lit/static-html.js'; | ||
|
||
import { fixture, testA11yTreeSnapshot } from '../../core/testing/private.js'; | ||
|
||
import type { SbbDialogContentElement } from './dialog-content.js'; | ||
import './dialog-content.js'; | ||
|
||
describe('sbb-dialog-content', () => { | ||
it('renders', async () => { | ||
const root = await fixture(html`<sbb-dialog-content>Content</sbb-dialog-content>`); | ||
describe('renders', async () => { | ||
let root: SbbDialogContentElement; | ||
|
||
beforeEach(async () => { | ||
root = await fixture(html`<sbb-dialog-content>Content</sbb-dialog-content>`); | ||
}); | ||
|
||
it('DOM', async () => { | ||
await expect(root).dom.to.be.equalSnapshot(); | ||
}); | ||
|
||
expect(root).dom.to.be.equal(`<sbb-dialog-content>Content</sbb-dialog-content>`); | ||
it('Shadow DOM', async () => { | ||
await expect(root).shadowDom.to.be.equalSnapshot(); | ||
}); | ||
|
||
expect(root).shadowDom.to.be.equal(` | ||
<div class="sbb-dialog-content"> | ||
<slot></slot> | ||
</div> | ||
`); | ||
testA11yTreeSnapshot(); | ||
}); | ||
}); |
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,113 @@ | ||
import { html, nothing, type TemplateResult } from 'lit'; | ||
|
||
import { describeViewports, visualDiffDefault } from '../../core/testing/private.js'; | ||
|
||
import './dialog.js'; | ||
import '../dialog-actions.js'; | ||
import '../dialog-content.js'; | ||
import '../dialog-title.js'; | ||
import '../../link/block-link.js'; | ||
import '../../button/button.js'; | ||
import '../../button/secondary-button.js'; | ||
|
||
describe(`sbb-dialog`, () => { | ||
const negativeCases = [false, true]; | ||
|
||
const dialogTitle = (backButton = true, hideOnScroll = false): TemplateResult => html` | ||
<sbb-dialog-title ?back-button=${backButton} ?hide-on-scroll=${hideOnScroll}> | ||
A describing title of the dialog | ||
</sbb-dialog-title> | ||
`; | ||
|
||
const dialogContent = (longContent = false): TemplateResult => html` | ||
<sbb-dialog-content> | ||
<p style="margin: 0"> | ||
“What really knocks me out is a book that, when you're all done reading it, you wish the | ||
author that wrote it was a terrific friend of yours and you could call him up on the phone | ||
whenever you felt like it. That doesn't happen much, though.” ― J.D. Salinger, The Catcher | ||
in the Rye | ||
</p> | ||
${longContent | ||
? html` | ||
<p> | ||
“What really knocks me out is a book that, when you're all done reading it, you wish | ||
the author that wrote it was a terrific friend of yours and you could call him up on | ||
the phone whenever you felt like it. That doesn't happen much, though.” ― J.D. | ||
Salinger, The Catcher in the Rye | ||
</p> | ||
` | ||
: nothing} | ||
</sbb-dialog-content> | ||
`; | ||
|
||
const dialogFooter = (negative = false): TemplateResult => html` | ||
<sbb-dialog-actions align-group="stretch" orientation="vertical" horizontal-from="medium"> | ||
<sbb-block-link | ||
align-self="start" | ||
icon-name="chevron-small-left-small" | ||
href="https://www.sbb.ch/en/" | ||
?negative=${negative} | ||
sbb-dialog-close | ||
> | ||
Link | ||
</sbb-block-link> | ||
<sbb-secondary-button sbb-dialog-close> Cancel </sbb-secondary-button> | ||
<sbb-button sbb-dialog-close> Confirm </sbb-button> | ||
</sbb-dialog-actions> | ||
`; | ||
|
||
describeViewports({ viewports: ['zero', 'medium'], viewportHeight: 600 }, () => { | ||
// Negative test | ||
for (const negative of negativeCases) { | ||
it( | ||
`negative=${negative}`, | ||
visualDiffDefault.with(async (setup) => { | ||
await setup.withFixture(html` | ||
<sbb-dialog ?negative=${negative}> | ||
${dialogTitle()} ${dialogContent()} ${dialogFooter(negative)} | ||
</sbb-dialog> | ||
`); | ||
const dialog = setup.snapshotElement.querySelector('sbb-dialog')!; | ||
setup.withSnapshotElement(dialog); | ||
dialog.open(); | ||
}), | ||
); | ||
} | ||
|
||
it( | ||
`no back button`, | ||
visualDiffDefault.with(async (setup) => { | ||
await setup.withFixture(html` | ||
<sbb-dialog> ${dialogTitle(false)} ${dialogContent()} ${dialogFooter()} </sbb-dialog> | ||
`); | ||
const dialog = setup.snapshotElement.querySelector('sbb-dialog')!; | ||
setup.withSnapshotElement(dialog); | ||
dialog.open(); | ||
}), | ||
); | ||
|
||
it( | ||
`no footer`, | ||
visualDiffDefault.with(async (setup) => { | ||
await setup.withFixture(html` | ||
<sbb-dialog> ${dialogTitle()} ${dialogContent()} </sbb-dialog> | ||
`); | ||
const dialog = setup.snapshotElement.querySelector('sbb-dialog')!; | ||
setup.withSnapshotElement(dialog); | ||
dialog.open(); | ||
}), | ||
); | ||
|
||
it( | ||
`long content`, | ||
visualDiffDefault.with(async (setup) => { | ||
await setup.withFixture(html` | ||
<sbb-dialog> ${dialogTitle()} ${dialogContent(true)} ${dialogFooter()} </sbb-dialog> | ||
`); | ||
const dialog = setup.snapshotElement.querySelector('sbb-dialog')!; | ||
setup.withSnapshotElement(dialog); | ||
dialog.open(); | ||
}), | ||
); | ||
}); | ||
}); |