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

fix(atomic): actually use alt field value #4695

Merged
merged 2 commits into from
Nov 21, 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import type {Meta, StoryObj as Story} from '@storybook/web-components';
const {decorator: resultDecorator, engineConfig} = wrapInResult({
search: {
preprocessSearchResponseMiddleware: (res) => {
res.body.results.forEach(
(r) => (r.raw['randomimage'] = 'https://picsum.photos/200')
);
res.body.results.forEach((r) => {
r.raw['randomimage'] = 'https://picsum.photos/200';
r.raw['someAltField'] = 'Some alt value';
});
return res;
},
},
Expand All @@ -32,6 +33,15 @@ export default meta;
export const Default: Story = {
name: 'atomic-result-image',
args: {
field: 'randomimage',
'attributes-field': 'randomimage',
},
};

export const withAnAltTextField: Story = {
name: 'With an alt text field',
args: {
'attributes-field': 'invalid',
'attributes-fallback': 'invalid',
'attributes-image-alt-field': 'someAltField',
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class AtomicResultImage implements InitializableComponent {
if (this.imageAltField) {
const value = ResultTemplatesHelpers.getResultProperty(
this.result,
this.field
this.imageAltField
);

if (Array.isArray(value) && typeof value[0] === 'string') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable @cspell/spellchecker */
import {test, expect} from './fixture';

test.describe('with an alt text field', async () => {
test.describe('when imageAltField is a valid string & the image is not found', () => {
test.beforeEach(async ({resultImage}) => {
await resultImage.load({
story: 'with-an-alt-text-field',
});
await resultImage.hydrated.waitFor();
});

test('should be accessible', async ({makeAxeBuilder}) => {
const accessibilityResults = await makeAxeBuilder().analyze();
expect(accessibilityResults.violations.length).toEqual(0);
});

test('should use the alt text', async ({resultImage}) => {
expect(resultImage.hydrated.first().getByAltText('Some alt value'));
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {test as base} from '@playwright/test';
import {
AxeFixture,
makeAxeBuilder,
} from '../../../../../../playwright-utils/base-fixture';
import {ResultImageObject} from './page-object';

interface TestFixture {
resultImage: ResultImageObject;
}

export const test = base.extend<TestFixture & AxeFixture>({
makeAxeBuilder,
resultImage: async ({page}, use) => {
await use(new ResultImageObject(page));
},
});

export {expect} from '@playwright/test';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type {Page} from '@playwright/test';
import {BasePageObject} from '../../../../../../playwright-utils/base-page-object';

export class ResultImageObject extends BasePageObject<'atomic-result-image'> {
constructor(page: Page) {
super(page, 'atomic-result-image');
}
}
Loading