From 5fc0634a7869d2a6315db3e1441e3269c842acfe Mon Sep 17 00:00:00 2001 From: Tommaso Menga Date: Mon, 16 Dec 2024 11:53:47 +0100 Subject: [PATCH] fix(sbb-teaser-hero): fix image size on custom width (#3295) --- src/elements/core/styles/core.scss | 3 +- src/elements/teaser-hero/teaser-hero.scss | 6 +- .../teaser-hero/teaser-hero.visual.spec.ts | 97 +++++++++++-------- 3 files changed, 61 insertions(+), 45 deletions(-) diff --git a/src/elements/core/styles/core.scss b/src/elements/core/styles/core.scss index b7b340de22..673a47c12e 100644 --- a/src/elements/core/styles/core.scss +++ b/src/elements/core/styles/core.scss @@ -266,8 +266,9 @@ sbb-teaser :is(sbb-image, img) { } img { - width: 100%; display: block; + align-self: stretch; + width: 100%; } } diff --git a/src/elements/teaser-hero/teaser-hero.scss b/src/elements/teaser-hero/teaser-hero.scss index 321075ddce..4c1331818d 100644 --- a/src/elements/teaser-hero/teaser-hero.scss +++ b/src/elements/teaser-hero/teaser-hero.scss @@ -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; diff --git a/src/elements/teaser-hero/teaser-hero.visual.spec.ts b/src/elements/teaser-hero/teaser-hero.visual.spec.ts index 5423b4eeee..38077cdc31 100644 --- a/src/elements/teaser-hero/teaser-hero.visual.spec.ts +++ b/src/elements/teaser-hero/teaser-hero.visual.spec.ts @@ -2,7 +2,6 @@ import { html } from 'lit'; import { describeViewports, - loadAssetAsBase64, visualDiffDefault, visualDiffFocus, visualDiffHover, @@ -13,38 +12,61 @@ 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``, + }, + { + title: 'with img tag', + imgSelector: 'img', + imgTemplate: () => html``, + }, + { + title: 'with figure_sbb-image', + imgSelector: 'sbb-image', + imgTemplate: () => + html`
+ + AI generated +
`, + }, + { + title: 'with figure_img', + imgSelector: 'img', + imgTemplate: () => + html`
+ + AI generated +
`, + }, +]; 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` - - Break out and explore castles and palaces. - -
- - - Label - -
-
- `); + for (const testCase of imgTestCases) { + it( + `${testCase.title} ${state.name}`, + visualDiffDefault.with(async (setup) => { + await setup.withFixture(html` + + Break out and explore castles and palaces. ${testCase.imgTemplate()} + + `); - 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` - Break out and explore castles and palaces. - Find out more `); @@ -52,32 +74,21 @@ describe(`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` - - Break out and explore castles and palaces. - Find out more - - - `); - - 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` - - + + Break out and explore castles and palaces. ${testCase.imgTemplate()} `); - await waitForImageReady(setup.snapshotElement.querySelector('sbb-image')!); + await waitForImageReady(setup.snapshotElement.querySelector(testCase.imgSelector)!); }), ); }