From 10a79b6220f604d8dc8aaea6471956695b6dc41c Mon Sep 17 00:00:00 2001 From: Alyssa Wang Date: Tue, 27 Jun 2023 19:07:47 -0400 Subject: [PATCH] add testsession and actionmodal tests --- .../TestSuite/__tests__/TestSession.test.tsx | 21 ++++++++- .../__tests__/SelectionPanel.test.tsx | 2 + .../_common/__tests__/ActionModal.test.tsx | 45 +++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 client/src/components/_common/__tests__/ActionModal.test.tsx diff --git a/client/src/components/TestSuite/__tests__/TestSession.test.tsx b/client/src/components/TestSuite/__tests__/TestSession.test.tsx index 0f94037ee..e591dbd5d 100644 --- a/client/src/components/TestSuite/__tests__/TestSession.test.tsx +++ b/client/src/components/TestSuite/__tests__/TestSession.test.tsx @@ -1,11 +1,30 @@ import React from 'react'; import { BrowserRouter } from 'react-router-dom'; -import { render, screen } from '@testing-library/react'; import { SnackbarProvider } from 'notistack'; +import { render, screen } from '@testing-library/react'; +import { vi } from 'vitest'; +import * as versionsApi from '~/api/VersionsApi'; import ThemeProvider from 'components/ThemeProvider'; import TestSessionComponent from '../TestSession'; +import TestSessionWrapper from '../TestSessionWrapper'; import { mockedTestSession, mockedResultsList } from '../__mocked_data__/mockData'; +test('renders TestSessionWrapper', () => { + const getCoreVersion = vi.spyOn(versionsApi, 'getCoreVersion'); + + render( + + + + + + + + ); + + expect(getCoreVersion).toBeCalledTimes(1); +}); + test('renders TestSession', () => { let drawerOpen = true; diff --git a/client/src/components/_common/SelectionPanel/__tests__/SelectionPanel.test.tsx b/client/src/components/_common/SelectionPanel/__tests__/SelectionPanel.test.tsx index 81713508b..8b8849983 100644 --- a/client/src/components/_common/SelectionPanel/__tests__/SelectionPanel.test.tsx +++ b/client/src/components/_common/SelectionPanel/__tests__/SelectionPanel.test.tsx @@ -71,10 +71,12 @@ describe('SelectionPanel component', () => { const submitButton = screen.getByText('Submit'); userEvent.click(submitButton); + expect(submitButton).toBeDisabled(); expect(submitAction).toBeCalledTimes(0); // should be disabled with no selection const options = screen.getAllByTestId('list-option'); userEvent.click(options[0]); // select first option + expect(submitButton).toBeEnabled(); userEvent.click(submitButton); await waitFor(() => expect(submitAction).toBeCalled()); }); diff --git a/client/src/components/_common/__tests__/ActionModal.test.tsx b/client/src/components/_common/__tests__/ActionModal.test.tsx new file mode 100644 index 000000000..025c1f2b3 --- /dev/null +++ b/client/src/components/_common/__tests__/ActionModal.test.tsx @@ -0,0 +1,45 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import ThemeProvider from 'components/ThemeProvider'; +import { SnackbarProvider } from 'notistack'; + +import { vi } from 'vitest'; +import ActionModal from '../ActionModal'; + +const cancelTestRunMock = vi.fn(); + +test('Modal visible and inputs are shown', () => { + render( + + + + + + ); + + const messageText = screen.getByText('Mock action message'); + expect(messageText).toBeVisible(); +}); + +test('Pressing cancel hides the modal', () => { + render( + + + + + + ); + + const cancelButton = screen.getByTestId('cancel-button'); + userEvent.click(cancelButton); + expect(cancelTestRunMock).toHaveBeenCalled(); +});