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-stepper): add visual spec #2901

Merged
merged 6 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 32 additions & 0 deletions src/elements/stepper/step-label/step-label.visual.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { html, type TemplateResult } from 'lit';

import {
describeViewports,
visualDiffDefault,
visualDiffHover,
} from '../../core/testing/private.js';

import './step-label.js';

describe(`sbb-step-label`, () => {
const template = (disabled?: boolean): TemplateResult =>
html`<sbb-step-label icon-name="tick-small" ?disabled=${disabled}>Label</sbb-step-label>`;

describeViewports({ viewports: ['zero', 'medium'] }, () => {
for (const state of [visualDiffDefault, visualDiffHover]) {
it(
state.name,
state.with(async (setup) => {
await setup.withFixture(template());
}),
);

it(
`disabled ${state.name}`,
state.with(async (setup) => {
await setup.withFixture(template(true));
}),
);
}
});
});
92 changes: 92 additions & 0 deletions src/elements/stepper/stepper/stepper.visual.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { html, nothing, type TemplateResult } from 'lit';

import {
describeEach,
describeViewports,
visualDiffDefault,
visualDiffFocus,
visualRegressionFixture,
} from '../../core/testing/private.js';

import './stepper.js';
import '../step.js';
import '../step-label.js';

describe(`sbb-stepper`, () => {
let root: HTMLElement;

const cases = {
orientation: ['horizontal', 'vertical'],
TomMenga marked this conversation as resolved.
Show resolved Hide resolved
linear: [false, true],
};

const template = (
linear?: boolean,
orientation?: string,
longLabel?: boolean,
horizontalFrom?: string,
): TemplateResult => html`
<sbb-stepper
selected-index="0"
?linear=${linear}
orientation=${orientation || nothing}
horizontal-from=${horizontalFrom || nothing}
>
<sbb-step-label icon-name="pen-small">Step 1</sbb-step-label>
<sbb-step>
<p>Step content 1</p>
</sbb-step>
<sbb-step-label icon-name="pen-small" disabled>Step 2</sbb-step-label>
<sbb-step>
<p>Step content 2</p>
</sbb-step>
<sbb-step-label
>${longLabel
? 'Step 3 - Long label lorem ipsum dolor sit amet, consetetur sadipscing elitr'
: 'Step 3'}</sbb-step-label
>
<sbb-step>
<p>Step content 3</p>
</sbb-step>
<sbb-step-label>Step 4</sbb-step-label>
<sbb-step>
<p>Step content 4</p>
</sbb-step>
</sbb-stepper>
`;

describeViewports({ viewports: ['zero', 'medium'] }, () => {
describeEach(cases, ({ linear, orientation }) => {
beforeEach(async function () {
root = await visualRegressionFixture(template(linear, orientation));
});

for (const state of [visualDiffDefault, visualDiffFocus]) {
it(
state.name,
state.with((setup) => {
setup.withSnapshotElement(root);
}),
);
}
});

it(
`horizontal-from=medium`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(template(false, 'vertical', false, 'medium'));
}),
);
});

describeViewports({ viewports: ['medium'] }, () => {
for (const orientation of cases.orientation) {
it(
`orientation=${orientation}_long labels`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(template(false, orientation, true));
}),
);
}
});
});
Loading