Skip to content

Commit

Permalink
test: add visual tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideMininni-Fincons committed Jun 26, 2024
1 parent 2bbe23d commit 2bdd05c
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { html, nothing } from 'lit';

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

import './block-link-button.js';

describe(`sbb-block-link-button`, () => {
const iconState = {
iconPlacement: ['start', 'end'],
slotted: [false, true],
};

describeViewports({ viewports: ['zero', 'medium'] }, () => {
for (const negative of [true, false]) {
for (const state of visualDiffStandardStates) {
it(
state.name,
state.with((setup) => {
setup.withFixture(
html`<sbb-block-link-button ?negative=${negative}
>Travelcards & tickets</sbb-block-link-button
>`,
{
backgroundColor: negative ? 'var(--sbb-color-charcoal)' : undefined,
},
);
}),
);
}
}

describeEach(iconState, ({ iconPlacement, slotted }) => {
it(
visualDiffDefault.name,
visualDiffDefault.with((setup) => {
setup.withFixture(html`
<sbb-block-link-button
icon-name=${slotted ? nothing : 'chevron-small-right-small'}
icon-placement=${iconPlacement}
>
${slotted
? html`<sbb-icon slot="icon" name="chevron-small-left-small"></sbb-icon>`
: nothing}
Travelcards & tickets
</sbb-block-link-button>
`);
}),
);
});

for (const size of ['xs', 's', 'm']) {
it(
`size=${size} ${visualDiffDefault.name}`,
visualDiffDefault.with((setup) => {
setup.withFixture(
html`<sbb-block-link-button size=${size}>Travelcards & tickets</sbb-block-link-button>`,
);
}),
);
}

it(
`width=fixed ${visualDiffDefault.name}`,
visualDiffDefault.with((setup) => {
setup.withFixture(
html`<sbb-block-link-button icon-name="chevron-small-right-small" style="width: 200px;">
A lot of link text to show what happens if there is not enough space.
</sbb-block-link-button>`,
);
}),
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { html, nothing } from 'lit';

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

import './block-link-static.js';

describe(`sbb-block-link-static`, () => {
const iconState = {
iconPlacement: ['start', 'end'],
slotted: [false, true],
};

describeViewports({ viewports: ['zero', 'medium'] }, () => {
for (const negative of [true, false]) {
for (const state of [visualDiffDefault, visualDiffActive, visualDiffHover]) {
it(
state.name,
state.with((setup) => {
setup.withFixture(
html` <sbb-block-link-static ?negative="${negative}"
>Travelcards & tickets</sbb-block-link-static
>`,
{
backgroundColor: negative ? 'var(--sbb-color-charcoal)' : undefined,
},
);
}),
);
}
}

describeEach(iconState, ({ iconPlacement, slotted }) => {
it(
visualDiffDefault.name,
visualDiffDefault.with((setup) => {
setup.withFixture(html`
<sbb-block-link-static
icon-name="${slotted ? nothing : 'chevron-small-right-small'}"
icon-placement="${iconPlacement}"
>
${slotted
? html` <sbb-icon slot="icon" name="chevron-small-left-small"></sbb-icon>`
: nothing}
Travelcards & tickets
</sbb-block-link-static>
`);
}),
);
});

for (const size of ['xs', 's', 'm']) {
it(
`size=${size} ${visualDiffDefault.name}`,
visualDiffDefault.with((setup) => {
setup.withFixture(
html` <sbb-block-link-static size="${size}"
>Travelcards & tickets</sbb-block-link-static
>`,
);
}),
);
}

it(
`width=fixed ${visualDiffDefault.name}`,
visualDiffDefault.with((setup) => {
setup.withFixture(
html` <sbb-block-link-static icon-name="chevron-small-right-small" style="width: 200px;">
A lot of link text to show what happens if there is not enough space.
</sbb-block-link-static>`,
);
}),
);
});
});
79 changes: 79 additions & 0 deletions src/elements/link/block-link/block-link.visual.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { html, nothing } from 'lit';

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

import './block-link.js';

describe(`sbb-block-link`, () => {
const iconState = {
iconPlacement: ['start', 'end'],
slotted: [false, true],
};

describeViewports({ viewports: ['zero', 'medium'] }, () => {
for (const negative of [true, false]) {
for (const state of visualDiffStandardStates) {
it(
state.name,
state.with((setup) => {
setup.withFixture(
html`<sbb-block-link href="#" ?negative=${negative}
>Travelcards & tickets</sbb-block-link
>`,
{
backgroundColor: negative ? 'var(--sbb-color-charcoal)' : undefined,
},
);
}),
);
}
}

describeEach(iconState, ({ iconPlacement, slotted }) => {
it(
visualDiffDefault.name,
visualDiffDefault.with((setup) => {
setup.withFixture(html`
<sbb-block-link
href="#"
icon-name=${slotted ? nothing : 'chevron-small-right-small'}
icon-placement=${iconPlacement}
>
${slotted
? html`<sbb-icon slot="icon" name="chevron-small-left-small"></sbb-icon>`
: nothing}
Travelcards & tickets
</sbb-block-link>
`);
}),
);
});

for (const size of ['xs', 's', 'm']) {
it(
`size=${size} ${visualDiffDefault.name}`,
visualDiffDefault.with((setup) => {
setup.withFixture(
html`<sbb-block-link href="#" size=${size}>Travelcards & tickets</sbb-block-link>`,
);
}),
);
}

it(
`width=fixed ${visualDiffDefault.name}`,
visualDiffDefault.with((setup) => {
setup.withFixture(
html`<sbb-block-link href="#" icon-name="chevron-small-right-small" style="width: 200px;">
A lot of link text to show what happens if there is not enough space.
</sbb-block-link>`,
);
}),
);
});
});

0 comments on commit 2bdd05c

Please sign in to comment.