From 759a79916db9894d31dabd47647329dd781a4824 Mon Sep 17 00:00:00 2001 From: Meis Date: Tue, 7 Nov 2023 15:33:19 -0700 Subject: [PATCH] test: [Select] Add unit tests --- src/components/Select/Select.stories.tsx | 11 +--- src/components/Select/Select.test.tsx | 82 ++++++++++++++++++++++++ src/components/Select/testUtils.ts | 12 ++++ 3 files changed, 95 insertions(+), 10 deletions(-) create mode 100644 src/components/Select/Select.test.tsx create mode 100644 src/components/Select/testUtils.ts diff --git a/src/components/Select/Select.stories.tsx b/src/components/Select/Select.stories.tsx index 3cad60cd..23b94a6f 100644 --- a/src/components/Select/Select.stories.tsx +++ b/src/components/Select/Select.stories.tsx @@ -1,5 +1,6 @@ import type { Meta, StoryObj } from '@storybook/react'; import { Select } from '~/src/index'; +import { DemoOptions } from './testUtils'; const meta: Meta = { title: 'Components (Verified)/Select', @@ -14,16 +15,6 @@ export default meta; type Story = StoryObj; -const DemoOptions = [ - { value: 'option1', label: 'Option 1' }, - { value: 'option2', label: 'Option 2' }, - { value: 'option3', label: 'Option 3' }, - { value: 'option4', label: 'Option 4' }, - { value: 'option5', label: 'Option 5' }, - { value: 'option6', label: 'Option 6' }, - { value: 'option7', label: 'Option 7' } -]; - export const SingleSelect: Story = { name: 'Single select', args: { diff --git a/src/components/Select/Select.test.tsx b/src/components/Select/Select.test.tsx new file mode 100644 index 00000000..8b5d77af --- /dev/null +++ b/src/components/Select/Select.test.tsx @@ -0,0 +1,82 @@ +import { jest } from '@storybook/jest'; +import '@testing-library/jest-dom'; +import { act, render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { Select } from './Select'; +import { DemoOptions } from './testUtils'; + +describe('', () => { + it('renders Single select with default value', () => { + render( + ); + + await user.selectOptions(screen.getByRole('combobox'), 'option3'); + expect(screen.getByRole('combobox')).toHaveValue('option3'); + expect(onChange).toHaveBeenCalledWith(DemoOptions[3]); + }); +}); + +describe('', () => { + it('Is interactable', async () => { + const id = 'multi'; + const label = 'MultiLabel'; + const maxSelections = 2; + const user = userEvent.setup(); + const onChange = jest.fn(); + + render( +