From 26fa2f96f3bbdb37421565a48e7f3e3dffb5b592 Mon Sep 17 00:00:00 2001 From: Mario Castigliano Date: Wed, 10 Jul 2024 09:03:59 +0200 Subject: [PATCH] test(sbb-radio-button, sbb-radio-button-group, sbb-radio-button-panel): implement visual spec (#2908) --- .../radio-button-group.visual.spec.ts | 118 ++++++++++++++++++ .../radio-button-panel.visual.spec.ts | 61 +++++++++ .../radio-button/radio-button.visual.spec.ts | 42 +++++++ 3 files changed, 221 insertions(+) create mode 100644 src/elements/radio-button/radio-button-group/radio-button-group.visual.spec.ts create mode 100644 src/elements/radio-button/radio-button-panel/radio-button-panel.visual.spec.ts create mode 100644 src/elements/radio-button/radio-button/radio-button.visual.spec.ts diff --git a/src/elements/radio-button/radio-button-group/radio-button-group.visual.spec.ts b/src/elements/radio-button/radio-button-group/radio-button-group.visual.spec.ts new file mode 100644 index 0000000000..93971675fc --- /dev/null +++ b/src/elements/radio-button/radio-button-group/radio-button-group.visual.spec.ts @@ -0,0 +1,118 @@ +import { html, type TemplateResult } from 'lit'; + +import { + describeEach, + describeViewports, + visualDiffDefault, + visualDiffFocus, +} from '../../core/testing/private.js'; + +import '../../card/card-badge.js'; +import '../../form-error.js'; +import '../../icon.js'; +import '../../radio-button.js'; + +const cases = { + disabled: [false, true], + orientation: ['vertical', 'horizontal'], + size: ['m', 's'], +}; + +const suffixAndSubtext = (): TemplateResult => html` + Subtext + + + CHF 8.00 + + % +`; + +const radioButtons = (): TemplateResult => html` + Value one + Value two + Value three + Value four +`; + +const radioButtonPanels = (): TemplateResult => html` + Value 1 ${suffixAndSubtext()} + Value 2 ${suffixAndSubtext()} +`; + +const variants: { name: string; template: TemplateResult }[] = [ + { name: 'radio-button', template: radioButtons() }, + { name: 'radio-button-panel', template: radioButtonPanels() }, +]; + +describe(`sbb-radio-button-group`, () => { + describeViewports({ viewports: ['small', 'medium'] }, () => { + describeEach(cases, ({ orientation, size, disabled }) => { + for (const variant of variants) { + describe(variant.name, () => { + for (const state of [visualDiffDefault, visualDiffFocus]) { + if (!(disabled && state === visualDiffFocus)) { + it( + state.name, + state.with(async (setup) => { + await setup.withFixture(html` + + ${variant.template} + + `); + }), + ); + } + } + }); + } + }); + for (const variant of variants) { + it( + `allow-empty-selection=true with ${variant.name}`, + visualDiffDefault.with(async (setup) => { + await setup.withFixture( + html` + ${variant.template} + `, + ); + }), + ); + } + + for (const variant of variants) { + it( + `horizontal-from=medium with ${variant.name}`, + visualDiffDefault.with(async (setup) => { + await setup.withFixture( + html` + ${variant.template} + `, + ); + }), + ); + } + + for (const variant of variants) { + describe(variant.name, () => { + for (const orientation of ['vertical', 'horizontal']) { + it( + `error message orientation=${orientation}`, + visualDiffDefault.with(async (setup) => { + await setup.withFixture( + html` + ${variant.template} + This is a required field. + `, + ); + }), + ); + } + }); + } + }); +}); diff --git a/src/elements/radio-button/radio-button-panel/radio-button-panel.visual.spec.ts b/src/elements/radio-button/radio-button-panel/radio-button-panel.visual.spec.ts new file mode 100644 index 0000000000..2624163107 --- /dev/null +++ b/src/elements/radio-button/radio-button-panel/radio-button-panel.visual.spec.ts @@ -0,0 +1,61 @@ +import { html, type TemplateResult } from 'lit'; + +import { describeEach, describeViewports, visualDiffDefault } from '../../core/testing/private.js'; + +import '../../icon.js'; +import '../radio-button-panel.js'; + +const cases = { + checked: [true, false], + disabled: [false, true], + size: ['m', 's'], +}; + +const suffixAndSubtext = (size: 's' | 'm' = 'm'): TemplateResult => + html`Subtext + + + CHF 40.00 + `; + +describe(`sbb-radio-button-panel`, () => { + describeViewports({ viewports: ['zero', 'medium'] }, () => { + describeEach(cases, ({ checked, disabled, size }) => { + it( + visualDiffDefault.name, + visualDiffDefault.with(async (setup) => { + await setup.withFixture(html` + + Value ${suffixAndSubtext(size as 's' | 'm')} + + `); + }), + ); + }); + + it( + 'color=milk', + visualDiffDefault.with(async (setup) => { + await setup.withFixture(html` + + Value ${suffixAndSubtext()} + + `); + }), + ); + + for (const color of ['white', 'milk']) { + it( + `color=${color} borderless=true`, + visualDiffDefault.with(async (setup) => { + await setup.withFixture(html` + + Value ${suffixAndSubtext()} + + `); + }), + ); + } + // Focus state is tested in the radio-button-group + }); +}); diff --git a/src/elements/radio-button/radio-button/radio-button.visual.spec.ts b/src/elements/radio-button/radio-button/radio-button.visual.spec.ts new file mode 100644 index 0000000000..87b24bc5ad --- /dev/null +++ b/src/elements/radio-button/radio-button/radio-button.visual.spec.ts @@ -0,0 +1,42 @@ +import { html } from 'lit'; + +import { describeEach, describeViewports, visualDiffDefault } from '../../core/testing/private.js'; + +import '../radio-button.js'; + +const cases = { + size: ['m', 's'], + checked: [true, false], + disabled: [false, true], +}; + +const longLabel = + "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s."; + +describe(`sbb-radio-button`, () => { + describeViewports({ viewports: ['zero', 'medium'] }, () => { + describeEach(cases, ({ size, checked, disabled }) => { + it( + visualDiffDefault.name, + visualDiffDefault.with(async (setup) => { + await setup.withFixture(html` + + Value + + `); + }), + ); + }); + + it( + 'long label', + visualDiffDefault.with(async (setup) => { + await setup.withFixture(html` + ${longLabel} + `); + }), + ); + + // Focus state is tested in the radio-button-group + }); +});