-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a319439
commit 59e66bb
Showing
4 changed files
with
134 additions
and
19 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './radio'; | ||
export * from './radioCard'; | ||
export * from './radioGroup'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { RadioGroup } from '..'; | ||
import { IconType } from '../../icon'; | ||
import { RadioCard, type IRadioCardProps } from './radioCard'; | ||
|
||
describe('<RadioCard/> component', () => { | ||
const createTestComponent = (props?: Partial<IRadioCardProps>) => { | ||
const completeProps = { label: 'test label', value: 'test value', description: 'test description', ...props }; | ||
|
||
return ( | ||
<RadioGroup name="Test Group"> | ||
<RadioCard {...completeProps} />; | ||
</RadioGroup> | ||
); | ||
}; | ||
|
||
const originalGlobalImage = global.Image; | ||
|
||
beforeAll(() => { | ||
(window.Image as unknown) = class MockImage { | ||
onload: () => void = () => {}; | ||
src: string = ''; | ||
constructor() { | ||
setTimeout(() => { | ||
this.onload(); | ||
}, 100); | ||
} | ||
}; | ||
}); | ||
|
||
afterAll(() => { | ||
global.Image = originalGlobalImage; | ||
}); | ||
|
||
it('renders with avatar, label, description, tag, and unchecked radio button', async () => { | ||
const avatar = 'avatar'; | ||
const description = 'Test Description'; | ||
const label = 'Test Label'; | ||
const tag = { label: 'Tag Label' }; | ||
|
||
render(createTestComponent({ avatar, description, label, tag })); | ||
|
||
const radioButton = screen.getByRole('radio'); | ||
|
||
expect(radioButton).toBeInTheDocument(); | ||
expect(radioButton).not.toBeChecked(); | ||
expect(screen.getByText(label)).toBeInTheDocument(); | ||
expect(screen.getByText(description)).toBeInTheDocument(); | ||
expect(screen.getByText(tag.label)).toBeInTheDocument(); | ||
expect(await screen.findByRole('img')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders the RADIO_DEFAULT icon when unchecked', () => { | ||
render(createTestComponent()); | ||
|
||
const uncheckedIcon = screen.getByTestId(IconType.RADIO_DEFAULT); | ||
|
||
expect(uncheckedIcon).toBeVisible(); | ||
expect(screen.getByRole('radio')).not.toBeChecked(); | ||
}); | ||
|
||
it('renders the RADIO_CHECK icon when checked', () => { | ||
render(createTestComponent()); | ||
|
||
const radioButton = screen.getByRole('radio'); | ||
|
||
fireEvent.click(radioButton); | ||
const checkedIcon = screen.getByTestId(IconType.RADIO_CHECK); | ||
|
||
expect(checkedIcon).toBeVisible(); | ||
expect(screen.getByRole('radio')).toBeChecked(); | ||
}); | ||
|
||
it('disables the radio button when disabled prop is true', () => { | ||
render(createTestComponent({ disabled: true })); | ||
|
||
expect(screen.getByRole('radio')).toBeDisabled(); | ||
}); | ||
|
||
it('sets the radio button value correctly', () => { | ||
const value = 'Test value'; | ||
|
||
render(createTestComponent({ value })); | ||
|
||
expect(screen.getByRole('radio')).toHaveValue(value); | ||
}); | ||
}); |
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