Skip to content

Commit

Permalink
test: testing radio group
Browse files Browse the repository at this point in the history
  • Loading branch information
ArmanNik committed May 13, 2022
1 parent 065fcee commit fb75512
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
26 changes: 24 additions & 2 deletions tests/unit/elements/inputRadio.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/svelte';
import { render, fireEvent } from '@testing-library/svelte';
import { InputRadio } from '../../../src/lib/elements/forms';
import radioGroup from './radioGroup.test.svelte';

const data = {
id: 'radio',
Expand Down Expand Up @@ -28,4 +29,25 @@ test('shows boolean input - disabled', () => {
expect(getByRole('radio')).toBeDisabled();
});

//TODO: create group of radio inputs and test state
test('state', async () => {
const { getByLabelText } = render(radioGroup);

const one = getByLabelText('one');
const two = getByLabelText('two');
const three = getByLabelText('three');

await fireEvent.click(one);
expect(one).toBeChecked();
expect(two).not.toBeChecked();
expect(three).not.toBeChecked();

await fireEvent.click(two);
expect(one).not.toBeChecked();
expect(two).toBeChecked();
expect(three).not.toBeChecked();

await fireEvent.click(three);
expect(one).not.toBeChecked();
expect(two).not.toBeChecked();
expect(three).toBeChecked();
});
7 changes: 7 additions & 0 deletions tests/unit/elements/radioGroup.test.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
import { InputRadio } from '../../../src/lib/elements/forms';
</script>

<InputRadio label="one" id="one" group="radio" value="1" name="radio" />
<InputRadio label="two" id="two" group="radio" value="2" name="radio" />
<InputRadio label="three" id="three" group="radio" value="3" name="radio" />

0 comments on commit fb75512

Please sign in to comment.