Skip to content

Commit

Permalink
Merge pull request #1372 from City-of-Helsinki/hds-2448-logo-testid
Browse files Browse the repository at this point in the history
HDS-2448: Fix data-test-id with Logo
  • Loading branch information
NikoHelle authored Oct 8, 2024
2 parents 4cfc78e + c20fbe8 commit cd22523
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
#### Changed

Changes that are not related to specific components

- [Component] What has been changed

#### Fixed

- [Component] What bugs/typos are fixed?
- [Logo] Fixed data-testid attribute not being set with native props

### Core

Expand All @@ -39,6 +40,7 @@ Changes that are not related to specific components
#### Changed

Changes that are not related to specific components

- [Component] What has been changed

#### Fixed
Expand All @@ -58,6 +60,7 @@ Changes that are not related to specific components
#### Changed

Changes that are not related to specific components

- [Component] What has been changed

#### Fixed
Expand All @@ -77,6 +80,7 @@ Changes that are not related to specific components
#### Changed

Changes that are not related to specific components

- [Component] What has been changed

#### Fixed
Expand All @@ -96,6 +100,7 @@ Changes that are not related to specific components
#### Changed

Changes that are not related to specific components

- [Component] What has been changed

#### Fixed
Expand All @@ -115,6 +120,7 @@ Changes that are not related to specific components
#### Changed

Changes that are not related to specific components

- [Component] What has been changed

#### Fixed
Expand All @@ -134,6 +140,7 @@ Changes that are not related to specific components
#### Changed

Changes that are not related to specific components

- [Component] What has been changed

#### Fixed
Expand Down
17 changes: 17 additions & 0 deletions packages/react/src/components/logo/Logo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ describe('<Logo /> spec', () => {
getElementAttributesMisMatches(element, {
...imgProps,
dataTestId: undefined,
'data-testid': imgProps.dataTestId,
} as HTMLAttributes<HTMLImageElement>),
).toHaveLength(0);
});
it('The data-testid works and overrides dataTestId', async () => {
const propsWithDataTestId = {
'data-testid': 'data-testid',
dataTestId: 'dataTestId',
};
const { getByTestId } = render(
<Logo {...propsWithDataTestId} src="dummyPath" alt="logo" title="Helsingin kaupunki" />,
);
const element = getByTestId(propsWithDataTestId['data-testid']);
expect(
getElementAttributesMisMatches(element, {
...propsWithDataTestId,
dataTestId: undefined,
} as HTMLAttributes<HTMLImageElement>),
).toHaveLength(0);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/logo/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ export type LogoProps = AllElementPropsWithoutRef<'img'> &

export const Logo = ({ alt, className, dataTestId, size = 'full', style, ...rest }: LogoProps) => {
const props = {
'data-testid': dataTestId,
...rest,
alt,
size,
className: classNames(styles.logo, size !== 'full' && styles[size], className),
style,
'data-testid': dataTestId,
};

return <img alt={alt} {...props} />;
Expand Down

0 comments on commit cd22523

Please sign in to comment.