diff --git a/src/elements/divider/__snapshots__/divider.snapshot.spec.snap.js b/src/elements/divider/__snapshots__/divider.snapshot.spec.snap.js index b3cf5e47fa..54d75c85c1 100644 --- a/src/elements/divider/__snapshots__/divider.snapshot.spec.snap.js +++ b/src/elements/divider/__snapshots__/divider.snapshot.spec.snap.js @@ -1,7 +1,23 @@ /* @web/test-runner snapshot v1 */ export const snapshots = {}; -snapshots["sbb-divider A11y tree Chrome"] = +snapshots["sbb-divider renders DOM"] = +` + +`; +/* end snapshot sbb-divider renders DOM */ + +snapshots["sbb-divider renders Shadow DOM"] = +`
+
+`; +/* end snapshot sbb-divider renders Shadow DOM */ + +snapshots["sbb-divider renders A11y tree Chrome"] = `

{ "role": "WebArea", @@ -9,9 +25,41 @@ snapshots["sbb-divider A11y tree Chrome"] = }

`; -/* end snapshot sbb-divider A11y tree Chrome */ +/* end snapshot sbb-divider renders A11y tree Chrome */ + +snapshots["sbb-divider renders horizontal DOM"] = +` + +`; +/* end snapshot sbb-divider renders horizontal DOM */ + +snapshots["sbb-divider renders horizontal Shadow DOM"] = +`
+
+`; +/* end snapshot sbb-divider renders horizontal Shadow DOM */ + +snapshots["sbb-divider renders vertical DOM"] = +` + +`; +/* end snapshot sbb-divider renders vertical DOM */ + +snapshots["sbb-divider renders vertical Shadow DOM"] = +`
+
+`; +/* end snapshot sbb-divider renders vertical Shadow DOM */ -snapshots["sbb-divider A11y tree Firefox"] = +snapshots["sbb-divider renders A11y tree Firefox"] = `

{ "role": "document", @@ -19,5 +67,5 @@ snapshots["sbb-divider A11y tree Firefox"] = }

`; -/* end snapshot sbb-divider A11y tree Firefox */ +/* end snapshot sbb-divider renders A11y tree Firefox */ diff --git a/src/elements/divider/divider.snapshot.spec.ts b/src/elements/divider/divider.snapshot.spec.ts index 14e6cc5bf7..ae79e81d89 100644 --- a/src/elements/divider/divider.snapshot.spec.ts +++ b/src/elements/divider/divider.snapshot.spec.ts @@ -2,48 +2,58 @@ import { expect } from '@open-wc/testing'; import { html } from 'lit/static-html.js'; import { fixture, testA11yTreeSnapshot } from '../core/testing/private.js'; -import { waitForLitRender } from '../core/testing.js'; import type { SbbDividerElement } from './divider.js'; - import './divider.js'; describe(`sbb-divider`, () => { - it('should render with default values', async () => { - const element: SbbDividerElement = await fixture(html``); - expect(element).dom.to.be.equal( - ``, - ); - expect(element).shadowDom.to.be.equal(`
`); - }); + describe('renders', () => { + let element: SbbDividerElement; - it('should render with orientation horizontal', async () => { - const element: SbbDividerElement = await fixture( - html``, - ); - expect(element).dom.to.be.equal( - ``, - ); - expect(element).shadowDom.to.be.equal(`
`); - }); + beforeEach(async () => { + element = await fixture(html``); + }); - it('should render with orientation vertical', async () => { - const element: SbbDividerElement = await fixture( - html``, - ); - expect(element).dom.to.be.equal( - ``, - ); - expect(element).shadowDom.to.be.equal(`
`); + it('DOM', async () => { + await expect(element).dom.to.be.equalSnapshot(); + }); + + it('Shadow DOM', async () => { + await expect(element).shadowDom.to.be.equalSnapshot(); + }); + + testA11yTreeSnapshot(); }); - it('should react to change of orientation', async () => { - const element: SbbDividerElement = await fixture(html``); + describe('renders horizontal', () => { + let element: SbbDividerElement; + + beforeEach(async () => { + element = await fixture(html``); + }); - element.orientation = 'vertical'; - await waitForLitRender(element); - expect(element).to.have.attribute('aria-orientation', 'vertical'); + it('DOM', async () => { + await expect(element).dom.to.be.equalSnapshot(); + }); + + it('Shadow DOM', async () => { + await expect(element).shadowDom.to.be.equalSnapshot(); + }); }); - testA11yTreeSnapshot(html``); + describe('renders vertical', () => { + let element: SbbDividerElement; + + beforeEach(async () => { + element = await fixture(html``); + }); + + it('DOM', async () => { + await expect(element).dom.to.be.equalSnapshot(); + }); + + it('Shadow DOM', async () => { + await expect(element).shadowDom.to.be.equalSnapshot(); + }); + }); }); diff --git a/src/elements/divider/divider.spec.ts b/src/elements/divider/divider.spec.ts index 7760df6cda..cf2ddeb47a 100644 --- a/src/elements/divider/divider.spec.ts +++ b/src/elements/divider/divider.spec.ts @@ -1,7 +1,8 @@ -import { assert } from '@open-wc/testing'; +import { assert, expect } from '@open-wc/testing'; import { html } from 'lit/static-html.js'; import { fixture } from '../core/testing/private.js'; +import { waitForLitRender } from '../core/testing.js'; import { SbbDividerElement } from './divider.js'; @@ -10,4 +11,13 @@ describe(`sbb-divider`, () => { const element: SbbDividerElement = await fixture(html``); assert.instanceOf(element, SbbDividerElement); }); + + it('should react to change of orientation', async () => { + const element: SbbDividerElement = await fixture(html``); + expect(element).to.have.attribute('aria-orientation', 'horizontal'); + + element.orientation = 'vertical'; + await waitForLitRender(element); + expect(element).to.have.attribute('aria-orientation', 'vertical'); + }); }); diff --git a/src/elements/divider/divider.visual.spec.ts b/src/elements/divider/divider.visual.spec.ts new file mode 100644 index 0000000000..c0a4a5caf6 --- /dev/null +++ b/src/elements/divider/divider.visual.spec.ts @@ -0,0 +1,41 @@ +import { html, nothing } from 'lit'; + +import { + describeEach, + describeViewports, + visualDiffDefault, + visualRegressionFixture, +} from '../core/testing/private.js'; + +import './divider.js'; + +describe(`sbb-divider`, () => { + let root: HTMLElement; + + const cases = { + orientation: ['horizontal', 'vertical'], + negative: [false, true], + }; + + describeViewports({ viewports: ['zero'] }, () => { + describeEach(cases, ({ negative, orientation }) => { + beforeEach(async function () { + root = await visualRegressionFixture( + html` +
+ +
+ `, + { backgroundColor: negative ? 'var(--sbb-color-charcoal)' : undefined }, + ); + }); + + it( + visualDiffDefault.name, + visualDiffDefault.with((setup) => { + setup.withSnapshotElement(root); + }), + ); + }); + }); +});