From 9cae7fd7cfdbb410c48213155a8dd8f9eac6f384 Mon Sep 17 00:00:00 2001 From: Alejandro Sanchez Date: Thu, 5 Oct 2023 16:36:10 -0700 Subject: [PATCH] Test updates --- .../common/MultiselectTextList.test.tsx | 47 +++++++++++++++++++ .../MultiselectTextList.test.tsx.snap | 46 ++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 source/frontend/src/components/common/MultiselectTextList.test.tsx create mode 100644 source/frontend/src/components/common/__snapshots__/MultiselectTextList.test.tsx.snap diff --git a/source/frontend/src/components/common/MultiselectTextList.test.tsx b/source/frontend/src/components/common/MultiselectTextList.test.tsx new file mode 100644 index 0000000000..a2eb8906ba --- /dev/null +++ b/source/frontend/src/components/common/MultiselectTextList.test.tsx @@ -0,0 +1,47 @@ +import Api_TypeCode from '@/models/api/TypeCode'; +import { render, RenderOptions } from '@/utils/test-utils'; + +import { IMultiselectTextListProps, MultiselectTextList } from './MultiselectTextList'; + +const mockOptions: Api_TypeCode[] = [ + { id: 'FOO', description: 'Foo' }, + { id: 'BAR', description: 'Bar' }, + { id: 'BAZ', description: 'Baz' }, +]; + +describe('MultiselectTextList component', () => { + const setup = ( + renderOptions?: RenderOptions & { props?: Partial }, + ) => { + renderOptions = renderOptions ?? {}; + const utils = render( + , + { + ...renderOptions, + }, + ); + + return { ...utils }; + }; + + afterEach(() => { + jest.clearAllMocks(); + }); + + it('renders as expected', () => { + const { asFragment } = setup(); + expect(asFragment()).toMatchSnapshot(); + }); + + it('displays existing values if they exist', () => { + const { getByText } = setup({ props: { values: mockOptions } }); + + expect(getByText(mockOptions[0].description!)).toBeVisible(); + expect(getByText(mockOptions[1].description!)).toBeVisible(); + expect(getByText(mockOptions[2].description!)).toBeVisible(); + }); +}); diff --git a/source/frontend/src/components/common/__snapshots__/MultiselectTextList.test.tsx.snap b/source/frontend/src/components/common/__snapshots__/MultiselectTextList.test.tsx.snap new file mode 100644 index 0000000000..78bfd6ff94 --- /dev/null +++ b/source/frontend/src/components/common/__snapshots__/MultiselectTextList.test.tsx.snap @@ -0,0 +1,46 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`MultiselectTextList component renders as expected 1`] = ` + +
+
+
+
+
+ +
+
+
    + + No Options Available + +
+
+
+
+ +`;