From 690f17d13854bffcf71e3ed96499a74080c6f14a Mon Sep 17 00:00:00 2001 From: Rae Chen Date: Mon, 11 Sep 2023 12:02:33 -0700 Subject: [PATCH 1/3] add one component test --- .../component_test/date_input.test.tsx | 33 +++++++++++++++++++ .../{ => util_test}/pathToId.test.tsx | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/__tests__/component_test/date_input.test.tsx rename src/__tests__/{ => util_test}/pathToId.test.tsx (93%) diff --git a/src/__tests__/component_test/date_input.test.tsx b/src/__tests__/component_test/date_input.test.tsx new file mode 100644 index 00000000..64ee61b4 --- /dev/null +++ b/src/__tests__/component_test/date_input.test.tsx @@ -0,0 +1,33 @@ +import React from 'react'; +import { render, fireEvent } from '@testing-library/react'; +import '@testing-library/jest-dom/extend-expect'; + +// Import the DateInputWrapper component +import DateInputWrapper from '../../components/date_input_wrapper'; +import { pathToId } from '../../utilities/paths_utils'; + +jest.mock('../../components/store', () => ({ + StoreContext: { + Consumer: ({ children }) => children({ data: {}, upsertData: jest.fn() }), // Mock context values + }, +})); + +describe('DateInputWrapper', () => { + it('renders with correct props and handles value change', () => { + // Arrange + const label = 'Test Label'; + const path = 'test.path'; + + // Render the DateInputWrapper component + const { getByLabelText } = render(); + + const inputElement = getByLabelText(label); + + expect(inputElement).toHaveAttribute('id', 'input-test-path'); + expect(inputElement).toHaveValue(''); + + fireEvent.change(inputElement, { target: { value: '2020-05-24' } }); + + expect(inputElement).toHaveValue('2020-05-24'); + }); +}); diff --git a/src/__tests__/pathToId.test.tsx b/src/__tests__/util_test/pathToId.test.tsx similarity index 93% rename from src/__tests__/pathToId.test.tsx rename to src/__tests__/util_test/pathToId.test.tsx index 7c366c4c..cf6c7292 100644 --- a/src/__tests__/pathToId.test.tsx +++ b/src/__tests__/util_test/pathToId.test.tsx @@ -1,4 +1,4 @@ -import { pathToId } from '../utilities/paths_utils' +import { pathToId } from '../../utilities/paths_utils' describe('pathToId', () => { test('converts path to id with default prefix and separator', () => { From dde86a3316f0711bfb49f6e79ed10d6b0469a18f Mon Sep 17 00:00:00 2001 From: Rae Chen Date: Mon, 11 Sep 2023 12:08:36 -0700 Subject: [PATCH 2/3] 1 --- src/__tests__/component_test/date_input.test.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/__tests__/component_test/date_input.test.tsx b/src/__tests__/component_test/date_input.test.tsx index 64ee61b4..7c868f38 100644 --- a/src/__tests__/component_test/date_input.test.tsx +++ b/src/__tests__/component_test/date_input.test.tsx @@ -8,17 +8,15 @@ import { pathToId } from '../../utilities/paths_utils'; jest.mock('../../components/store', () => ({ StoreContext: { - Consumer: ({ children }) => children({ data: {}, upsertData: jest.fn() }), // Mock context values + Consumer: ({ children }) => children({ data: {}, upsertData: jest.fn() }), }, })); describe('DateInputWrapper', () => { it('renders with correct props and handles value change', () => { - // Arrange const label = 'Test Label'; const path = 'test.path'; - // Render the DateInputWrapper component const { getByLabelText } = render(); const inputElement = getByLabelText(label); From 35aca2f367213c28a2e7f99413efef512893eb27 Mon Sep 17 00:00:00 2001 From: Rae Chen Date: Mon, 11 Sep 2023 12:28:22 -0700 Subject: [PATCH 3/3] adding tests --- .../component_test/figure_wrapper.test.tsx | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/__tests__/component_test/figure_wrapper.test.tsx diff --git a/src/__tests__/component_test/figure_wrapper.test.tsx b/src/__tests__/component_test/figure_wrapper.test.tsx new file mode 100644 index 00000000..25d44e6f --- /dev/null +++ b/src/__tests__/component_test/figure_wrapper.test.tsx @@ -0,0 +1,21 @@ +import React from 'react'; +import { getByRole, render } from '@testing-library/react'; +import '@testing-library/jest-dom/extend-expect'; + +import FigureWrapper from '../../components/figure_wrapper'; + +describe('FigureWrapper', () => { + it('renders with children and src', () => { + + const children = 'This is the caption text'; + const src = ''; + + const { getByText, getByAltText } = render( + {children} + ); + + const captionElement = getByText(children); + + expect(captionElement).toBeInTheDocument(); + }); +}); \ No newline at end of file