-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix(web-react): Pass aria props rel and target based on elemen type t…
…o the dom element
- Loading branch information
Showing
3 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
packages/web-react/src/components/ButtonLink/__tests__/useButtonLinkAriaProps.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { UseButtonLinkAriaProps, useButtonLinkAriaProps } from '../useButtonLinkAriaProps'; | ||
|
||
describe('useButtonAriaProps', () => { | ||
it('should return aria props for anchor tag', () => { | ||
const props = { | ||
elementType: 'a', | ||
href: '/', | ||
isDisabled: false, | ||
target: '_blank', | ||
rel: 'noopener', | ||
} as UseButtonLinkAriaProps; | ||
const { result } = renderHook(() => useButtonLinkAriaProps(props)); | ||
|
||
expect(result.current.buttonLinkProps).toEqual({ | ||
'aria-label': undefined, | ||
disabled: undefined, | ||
href: '/', | ||
onClick: expect.any(Function), | ||
rel: 'noopener', | ||
role: 'button', | ||
target: '_blank', | ||
}); | ||
}); | ||
|
||
it('should return aria props for disabled anchor tag', () => { | ||
const props = { | ||
elementType: 'a', | ||
href: '/', | ||
isDisabled: true, | ||
target: '_blank', | ||
rel: 'noopener', | ||
} as UseButtonLinkAriaProps; | ||
const { result } = renderHook(() => useButtonLinkAriaProps(props)); | ||
|
||
expect(result.current.buttonLinkProps).toEqual({ | ||
'aria-label': undefined, | ||
disabled: true, | ||
href: undefined, | ||
onClick: expect.any(Function), | ||
rel: 'noopener', | ||
role: 'button', | ||
target: '_blank', | ||
}); | ||
}); | ||
|
||
it('should return aria props for button tag', () => { | ||
const props = { | ||
elementType: 'button', | ||
href: '/', | ||
isDisabled: false, | ||
target: '_blank', | ||
rel: 'noopener', | ||
} as unknown as UseButtonLinkAriaProps; | ||
const { result } = renderHook(() => useButtonLinkAriaProps(props)); | ||
|
||
expect(result.current.buttonLinkProps).toEqual({ | ||
'aria-label': undefined, | ||
disabled: undefined, | ||
href: '/', | ||
onClick: expect.any(Function), | ||
rel: undefined, | ||
role: 'button', | ||
target: undefined, | ||
}); | ||
}); | ||
|
||
it('should return aria props for disabled button tag', () => { | ||
const props = { | ||
elementType: 'button', | ||
href: '/', | ||
isDisabled: true, | ||
target: '_blank', | ||
rel: 'noopener', | ||
} as unknown as UseButtonLinkAriaProps; | ||
const { result } = renderHook(() => useButtonLinkAriaProps(props)); | ||
|
||
expect(result.current.buttonLinkProps).toEqual({ | ||
'aria-label': undefined, | ||
disabled: true, | ||
href: '/', | ||
onClick: expect.any(Function), | ||
rel: undefined, | ||
role: 'button', | ||
target: undefined, | ||
}); | ||
}); | ||
}); |