Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(sbb-radio-button, sbb-radio-button-group, sbb-radio-button-panel): implement visual spec #2908

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { html, type TemplateResult } from 'lit';
import { styleMap, type StyleInfo } from 'lit/directives/style-map.js';

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 suffixStyle: Readonly<StyleInfo> = {
display: 'flex',
alignItems: 'center',
marginInline: 'var(--sbb-spacing-fixed-2x)',
};

const suffixAndSubtext = (): TemplateResult => html`
<span slot="subtext">Subtext</span>
<span slot="suffix" style="margin-inline-start: auto;">
<span style=${styleMap(suffixStyle)}>
MarioCastigliano marked this conversation as resolved.
Show resolved Hide resolved
<sbb-icon name="diamond-small" style="margin-inline: var(--sbb-spacing-fixed-2x);"></sbb-icon>
<span class="sbb-text-m sbb-text--bold">CHF 8.00</span>
</span>
</span>
<sbb-card-badge>%</sbb-card-badge>
`;

const radioButtons = (): TemplateResult => html`
<sbb-radio-button value="Value one">Value one</sbb-radio-button>
<sbb-radio-button value="Value two">Value two</sbb-radio-button>
<sbb-radio-button value="Value three" disabled> Value three </sbb-radio-button>
<sbb-radio-button value="Value four">Value four</sbb-radio-button>
`;

const radioButtonPanels = (): TemplateResult => html`
<sbb-radio-button-panel value="Value one">Value 1 ${suffixAndSubtext()}</sbb-radio-button-panel>
<sbb-radio-button-panel value="Value two">Value 2 ${suffixAndSubtext()}</sbb-radio-button-panel>
`;

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) {
for (const state of [visualDiffDefault, visualDiffFocus]) {
(disabled && state === visualDiffFocus ? it.skip : it)(
MarioCastigliano marked this conversation as resolved.
Show resolved Hide resolved
`${variant.name} ${state.name}`,
MarioCastigliano marked this conversation as resolved.
Show resolved Hide resolved
state.with(async (setup) => {
await setup.withFixture(html`
<sbb-radio-button-group
orientation=${orientation}
size=${size}
?disabled=${disabled}
value="Value one"
>
${variant.template}
</sbb-radio-button-group>
`);
}),
);
}
}
});
for (const variant of variants) {
it(
`allow-empty-selection=true with ${variant.name}`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(
html`<sbb-radio-button-group allow-empty-selection>
${variant.template}
</sbb-radio-button-group>`,
);
}),
);
}

MarioCastigliano marked this conversation as resolved.
Show resolved Hide resolved
for (const variant of ['vertical', 'horizontal']) {
it(
`error message ${variant}`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(
html`<sbb-radio-button-group allow-empty-selection orientation=${variant}>
${variants[0].template}
MarioCastigliano marked this conversation as resolved.
Show resolved Hide resolved
<sbb-form-error slot="error">This is a required field.</sbb-form-error>
</sbb-radio-button-group>`,
);
}),
);
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { html } 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'],
};

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`
<sbb-radio-button-panel ?checked=${checked} ?disabled=${disabled} size=${size}>
Value
<span slot="subtext">Subtext</span>
<span slot="suffix" style="margin-inline-start: auto;">
<span style="display:flex;align-items:center;">
MarioCastigliano marked this conversation as resolved.
Show resolved Hide resolved
<sbb-icon
name="diamond-small"
style="margin-inline: var(--sbb-spacing-fixed-2x);"
data-namespace="default"
role="img"
aria-hidden="true"
></sbb-icon>
<span class="sbb-text-${size} sbb-text--bold"> CHF 40.00 </span>
</span>
</span>
</sbb-radio-button-panel>
`);
}),
);
});

it(
'color=milk',
visualDiffDefault.with(async (setup) => {
await setup.withFixture(html`
<sbb-radio-button-panel checked color="milk">
Value
<span slot="subtext">Subtext</span>
<span slot="suffix" style="margin-inline-start: auto;">
<span style="display:flex;align-items:center;">
<sbb-icon
name="diamond-small"
style="margin-inline: var(--sbb-spacing-fixed-2x);"
data-namespace="default"
role="img"
aria-hidden="true"
></sbb-icon>
<span class="sbb-text-m sbb-text--bold"> CHF 40.00 </span>
</span>
</span>
</sbb-radio-button-panel>
`);
}),
);

for (const color of ['white', 'milk']) {
it(
`color=${color} borderless=true`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(html`
<sbb-radio-button-panel borderless color=${color}>
Value
<span slot="subtext">Subtext</span>
<span slot="suffix" style="margin-inline-start: auto;">
<span style="display:flex;align-items:center;">
<sbb-icon
name="diamond-small"
style="margin-inline: var(--sbb-spacing-fixed-2x);"
></sbb-icon>
<span class="sbb-text-m sbb-text--bold"> CHF 40.00 </span>
</span>
</span>
</sbb-radio-button-panel>
`);
}),
);
}

it(
'with bold label',
visualDiffDefault.with(async (setup) => {
await setup.withFixture(
html` <sbb-radio-button-panel>
MarioCastigliano marked this conversation as resolved.
Show resolved Hide resolved
<span class="sbb-text--bold">Value</span>
<span slot="subtext">Subtext</span>
<span slot="suffix" style="margin-inline-start: auto;">
<span style="display:flex;align-items:center;">
<sbb-icon
name="diamond-small"
style="margin-inline: var(--sbb-spacing-fixed-2x);"
data-namespace="default"
role="img"
aria-hidden="true"
></sbb-icon>
<span class="sbb-text-m sbb-text--bold"> CHF 40.00 </span>
</span>
</span>
</sbb-radio-button-panel>`,
);
}),
);
// Focus state is tested in the radio-button-group
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { html, nothing } 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],
bold: [false, true],
MarioCastigliano marked this conversation as resolved.
Show resolved Hide resolved
};

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, bold }) => {
it(
visualDiffDefault.name,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(html`
<sbb-radio-button ?checked=${checked} ?disabled=${disabled} size=${size}>
<span class=${bold ? 'sbb-text--bold' : nothing}>Value</span>
</sbb-radio-button>
`);
}),
);
});

it(
'long label',
visualDiffDefault.with(async (setup) => {
await setup.withFixture(html`
<sbb-radio-button checked> ${longLabel} </sbb-radio-button>
`);
}),
);

// Focus state is tested in the radio-button-group
});
});
Loading