From 8cae3052d1d5a7ffe7476165fdac6a6fdcc03e41 Mon Sep 17 00:00:00 2001 From: Tommmaso Menga Date: Thu, 20 Jun 2024 08:41:08 +0200 Subject: [PATCH] test(sbb-clock): add visual spec (#2795) --- .../__snapshots__/clock.snapshot.spec.snap.js | 48 ++++++++++++------- src/elements/clock/clock.snapshot.spec.ts | 39 +++++++++------ src/elements/clock/clock.visual.spec.ts | 27 +++++++++++ 3 files changed, 84 insertions(+), 30 deletions(-) create mode 100644 src/elements/clock/clock.visual.spec.ts diff --git a/src/elements/clock/__snapshots__/clock.snapshot.spec.snap.js b/src/elements/clock/__snapshots__/clock.snapshot.spec.snap.js index 8023e1b212..259b9de222 100644 --- a/src/elements/clock/__snapshots__/clock.snapshot.spec.snap.js +++ b/src/elements/clock/__snapshots__/clock.snapshot.spec.snap.js @@ -1,7 +1,13 @@ /* @web/test-runner snapshot v1 */ export const snapshots = {}; -snapshots["sbb-clock renders"] = +snapshots["sbb-clock renders DOM"] = +` + +`; +/* end snapshot sbb-clock renders DOM */ + +snapshots["sbb-clock renders Shadow DOM"] = `
@@ -13,9 +19,29 @@ snapshots["sbb-clock renders"] =
`; -/* end snapshot sbb-clock renders */ +/* end snapshot sbb-clock renders Shadow DOM */ + +snapshots["sbb-clock renders A11y tree Chrome"] = +`

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

+`; +/* end snapshot sbb-clock renders A11y tree Chrome */ -snapshots["sbb-clock renders with a fixed time"] = +snapshots["sbb-clock renders with fixed time DOM"] = +` + +`; +/* end snapshot sbb-clock renders with fixed time DOM */ + +snapshots["sbb-clock renders with fixed time Shadow DOM"] = `
@@ -30,19 +56,9 @@ snapshots["sbb-clock renders with a fixed time"] =
`; -/* end snapshot sbb-clock renders with a fixed time */ - -snapshots["sbb-clock A11y tree Chrome"] = -`

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

-`; -/* end snapshot sbb-clock A11y tree Chrome */ +/* end snapshot sbb-clock renders with fixed time Shadow DOM */ -snapshots["sbb-clock A11y tree Firefox"] = +snapshots["sbb-clock renders A11y tree Firefox"] = `

{ "role": "document", @@ -50,5 +66,5 @@ snapshots["sbb-clock A11y tree Firefox"] = }

`; -/* end snapshot sbb-clock A11y tree Firefox */ +/* end snapshot sbb-clock renders A11y tree Firefox */ diff --git a/src/elements/clock/clock.snapshot.spec.ts b/src/elements/clock/clock.snapshot.spec.ts index a068cbd2ce..7e55f11d1f 100644 --- a/src/elements/clock/clock.snapshot.spec.ts +++ b/src/elements/clock/clock.snapshot.spec.ts @@ -1,30 +1,41 @@ -import { assert, expect } 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 { SbbClockElement } from './clock.js'; +import type { SbbClockElement } from './clock.js'; +import './clock.js'; describe(`sbb-clock`, () => { let element: SbbClockElement; - it('renders', async () => { - element = await fixture(html``); - assert.instanceOf(element, SbbClockElement); + describe('renders', () => { + beforeEach(async () => { + element = await fixture(html``); + }); - expect(element).dom.to.be.equal(``); + it('DOM', async () => { + await expect(element).dom.to.be.equalSnapshot(); + }); - await expect(element).shadowDom.to.be.equalSnapshot(); + it('Shadow DOM', async () => { + await expect(element).shadowDom.to.be.equalSnapshot(); + }); + + testA11yTreeSnapshot(); }); - it('renders with a fixed time', async () => { - element = await fixture(html``); - assert.instanceOf(element, SbbClockElement); + describe('renders with fixed time', () => { + beforeEach(async () => { + element = await fixture(html``); + }); - expect(element).to.have.attribute('data-initialized'); + it('DOM', async () => { + await expect(element).dom.to.be.equalSnapshot(); + }); - await expect(element).shadowDom.to.be.equalSnapshot(); + it('Shadow DOM', async () => { + await expect(element).shadowDom.to.be.equalSnapshot(); + }); }); - - testA11yTreeSnapshot(html``); }); diff --git a/src/elements/clock/clock.visual.spec.ts b/src/elements/clock/clock.visual.spec.ts new file mode 100644 index 0000000000..7847bf82df --- /dev/null +++ b/src/elements/clock/clock.visual.spec.ts @@ -0,0 +1,27 @@ +import { html } from 'lit'; + +import { describeViewports, visualDiffDefault } from '../core/testing/private.js'; + +import './clock.js'; + +describe(`sbb-clock`, () => { + const timeCases = [ + { hours: '0', minutes: '0', seconds: '0' }, + { hours: '7', minutes: '32', seconds: '15' }, + { hours: '16', minutes: '15', seconds: '0' }, + { hours: '11', minutes: '60', seconds: '60' }, + ]; + + describeViewports({ viewports: ['medium'] }, () => { + for (const time of timeCases) { + const timeStamp = `${time.hours}:${time.minutes}:${time.seconds}`; + + it( + `time=${timeStamp.replaceAll(':', '-')}`, + visualDiffDefault.with(async (setup) => { + await setup.withFixture(html``); + }), + ); + } + }); +});