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-title): implement visual regression tests #2869

Merged
merged 3 commits into from
Jul 2, 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
23 changes: 23 additions & 0 deletions src/elements/title/__snapshots__/title.snapshot.spec.snap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
/* @web/test-runner snapshot v1 */
export const snapshots = {};

snapshots["sbb-title renders DOM"] =
`<sbb-title
aria-level="1"
level="1"
role="heading"
visual-level="2"
>
Sample Title Text
</sbb-title>
`;
/* end snapshot sbb-title renders DOM */

snapshots["sbb-title renders Shadow DOM"] =
`<h1
class="sbb-title"
role="presentation"
>
<slot>
</slot>
</h1>
`;
/* end snapshot sbb-title renders Shadow DOM */

snapshots["sbb-title A11y tree Chrome"] =
`<p>
{
Expand Down
31 changes: 18 additions & 13 deletions src/elements/title/title.snapshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@ import { html } from 'lit/static-html.js';

import { fixture, testA11yTreeSnapshot } from '../core/testing/private.js';

import type { SbbTitleElement } from './title.js';

import './title.js';

describe(`sbb-title`, () => {
it('renders', async () => {
const root = await fixture(
html`<sbb-title level="1" visual-level="2">Sample Title Text</sbb-title>`,
);

expect(root).dom.to.be.equal(`
<sbb-title level="1" visual-level="2" aria-level="1" role="heading">
Sample Title Text
</sbb-title>
`);
expect(root).shadowDom.to.be.equal(`
<h1 class="sbb-title" role="presentation"><slot></slot></h1>
`);
describe('renders', async () => {
let element: SbbTitleElement;

beforeEach(async () => {
element = await fixture(
html`<sbb-title level="1" visual-level="2">Sample Title Text</sbb-title>`,
);
});

it('DOM', async () => {
await expect(element).dom.to.be.equalSnapshot();
});

it('Shadow DOM', async () => {
await expect(element).shadowDom.to.be.equalSnapshot();
});
});

testA11yTreeSnapshot(html`<sbb-title level="1" visual-level="2">Sample Title Text</sbb-title>`);
Expand Down
42 changes: 42 additions & 0 deletions src/elements/title/title.visual.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { html } from 'lit';

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

import '../title.js';

describe(`sbb-title`, () => {
describeViewports({ viewports: ['zero', 'small', 'medium', 'large', 'ultra'] }, () => {
for (const level of ['1', '2', '3', '4', '5', '6']) {
jeripeierSBB marked this conversation as resolved.
Show resolved Hide resolved
it(
`level=${level}`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(
html`<sbb-title level=${level}>
Data without insights are trivial, and insights without action are pointless
</sbb-title>
<article>
Diam maecenas ultricies mi eget mauris pharetra et ultrices neque ornare aenean
euismod elementum nisi quis eleifend quam adipiscing vitae proin sagittis nisl
rhoncus mattis rhoncus urna neque viverra justo nec ultrices dui sapien eget mi
proin sed libero enim sed faucibus turpis in eu mi bibendum neque egestas congue.
</article> `,
);
}),
);
}

it(
'negative',
visualDiffDefault.with(async (setup) => {
await setup.withFixture(
html`
<sbb-title negative>
Data without insights are trivial, and insights without action are pointless
</sbb-title>
`,
{ backgroundColor: 'var(--sbb-color-charcoal)' },
);
}),
);
});
});
Loading