Skip to content

Commit

Permalink
fix(sbb-teaser-hero): fix image size on custom width (#3295)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomMenga authored Dec 16, 2024
1 parent 11cc853 commit 9fe9ae8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 45 deletions.
3 changes: 2 additions & 1 deletion src/elements/core/styles/core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,9 @@ sbb-teaser :is(sbb-image, img) {
}

img {
width: 100%;
display: block;
align-self: stretch;
width: 100%;
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/elements/teaser-hero/teaser-hero.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
}
}

::slotted([slot='image']) {
width: 100%;
}

.sbb-teaser-hero {
position: relative;
display: block;
display: flex;
min-height: var(--sbb-panel-height);
text-decoration: none;

Expand Down
97 changes: 54 additions & 43 deletions src/elements/teaser-hero/teaser-hero.visual.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { html } from 'lit';

import {
describeViewports,
loadAssetAsBase64,
visualDiffDefault,
visualDiffFocus,
visualDiffHover,
Expand All @@ -13,71 +12,83 @@ import '../image.js';
import '../chip-label.js';

const imageUrl = import.meta.resolve('../core/testing/assets/placeholder-image.png');
const imageBase64 = await loadAssetAsBase64(imageUrl);

const imgTestCases = [
{
title: 'with sbb-image',
imgSelector: 'sbb-image',
imgTemplate: () => html`<sbb-image slot="image" image-src=${imageUrl}></sbb-image>`,
},
{
title: 'with img tag',
imgSelector: 'img',
imgTemplate: () => html`<img slot="image" src=${imageUrl} alt="" />`,
},
{
title: 'with figure_sbb-image',
imgSelector: 'sbb-image',
imgTemplate: () =>
html`<figure class="sbb-figure" slot="image">
<sbb-image image-src=${imageUrl}></sbb-image>
<sbb-chip-label class="sbb-figure-overlap-start-end">AI generated</sbb-chip-label>
</figure>`,
},
{
title: 'with figure_img',
imgSelector: 'img',
imgTemplate: () =>
html`<figure class="sbb-figure" slot="image">
<img slot="image" src=${imageUrl} alt="" />
<sbb-chip-label class="sbb-figure-overlap-start-end">AI generated</sbb-chip-label>
</figure>`,
},
];

describe(`sbb-teaser-hero`, () => {
describeViewports({ viewports: ['zero', 'micro', 'small', 'medium', 'wide'] }, () => {
for (const state of [visualDiffDefault, visualDiffHover, visualDiffFocus]) {
it(
state.name,
state.with(async (setup) => {
await setup.withFixture(html`
<sbb-teaser-hero href="#" link-content="Find out more">
Break out and explore castles and palaces.
<figure class="sbb-figure" slot="image">
<sbb-image image-src=${imageUrl}></sbb-image>
<sbb-chip-label class="sbb-figure-overlap-start-start" style="z-index: 1">
Label
</sbb-chip-label>
</figure>
</sbb-teaser-hero>
`);
for (const testCase of imgTestCases) {
it(
`${testCase.title} ${state.name}`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(html`
<sbb-teaser-hero href="#" link-content="Find out more">
Break out and explore castles and palaces. ${testCase.imgTemplate()}
</sbb-teaser-hero>
`);

await waitForImageReady(setup.snapshotElement.querySelector('sbb-image')!);
}),
);
await waitForImageReady(setup.snapshotElement.querySelector(testCase.imgSelector)!);
}),
);
}

it(
`slotted ${state.name}`,
`without content ${state.name}`,
state.with(async (setup) => {
await setup.withFixture(html`
<sbb-teaser-hero href="#">
Break out and explore castles and palaces.
<span slot="link-content">Find out more</span>
<sbb-image slot="image" image-src=${imageUrl}></sbb-image>
</sbb-teaser-hero>
`);

await waitForImageReady(setup.snapshotElement.querySelector('sbb-image')!);
}),
);
}
});

describeViewports({ viewports: ['large'] }, () => {
for (const testCase of imgTestCases) {
it(
`slotted-image ${state.name}`,
state.with(async (setup) => {
await setup.withFixture(html`
<sbb-teaser-hero href="#">
Break out and explore castles and palaces.
<span slot="link-content">Find out more</span>
<img slot="image" src=${imageBase64} alt="" />
</sbb-teaser-hero>
`);

await waitForImageReady(setup.snapshotElement.querySelector('img')!);
}),
);

it(
`without content ${state.name}`,
state.with(async (setup) => {
`custom width ${testCase.title}`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(html`
<sbb-teaser-hero href="#">
<sbb-image slot="image" image-src=${imageUrl}></sbb-image>
<sbb-teaser-hero href="#" link-content="Find out more" style="width: 700px">
Break out and explore castles and palaces. ${testCase.imgTemplate()}
</sbb-teaser-hero>
`);

await waitForImageReady(setup.snapshotElement.querySelector('sbb-image')!);
await waitForImageReady(setup.snapshotElement.querySelector(testCase.imgSelector)!);
}),
);
}
Expand Down

0 comments on commit 9fe9ae8

Please sign in to comment.