From a6ff5eee45215effb3344cb5d631a27a7c0369aa Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 22 Sep 2023 19:34:01 +0200 Subject: refactor(components): rewrite form components --- .../molecules/forms/switch/switch.test.tsx | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/components/molecules/forms/switch/switch.test.tsx (limited to 'src/components/molecules/forms/switch/switch.test.tsx') diff --git a/src/components/molecules/forms/switch/switch.test.tsx b/src/components/molecules/forms/switch/switch.test.tsx new file mode 100644 index 0000000..6ccd525 --- /dev/null +++ b/src/components/molecules/forms/switch/switch.test.tsx @@ -0,0 +1,49 @@ +import { render, screen } from '../../../../../tests/utils'; +import { Legend } from '../../../atoms'; +import { Switch, SwitchOption } from './switch'; + +const doNothing = () => { + /* Do nothing. */ +}; + +const items: [SwitchOption, SwitchOption] = [ + { id: 'item-1', label: 'Option 1', value: 'option-1' }, + { id: 'item-2', label: 'Option 2', value: 'option-2' }, +]; + +describe('Switch', () => { + it('renders a radio group with two choices', () => { + const legend = 'Options:'; + + render( + {legend}} + name="possimus" + onSwitch={doNothing} + value={items[0].value} + /> + ); + + expect( + screen.getByRole('radiogroup', { name: legend }) + ).toBeInTheDocument(); + expect(screen.getAllByRole('radio')).toHaveLength(items.length); + }); + + it('can render a disabled switch', () => { + render( + + ); + + const radios = screen.getAllByRole('radio'); + expect(radios.every((radio) => radio.disabled)).toBe(true); + expect(screen.getByRole('radiogroup')).toBeDisabled(); + }); +}); -- cgit v1.2.3