Skip to content

Commit

Permalink
add testsession and actionmodal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlyssaWang committed Jun 27, 2023
1 parent e8a5023 commit 10a79b6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
21 changes: 20 additions & 1 deletion client/src/components/TestSuite/__tests__/TestSession.test.tsx
Original file line number Diff line number Diff line change
@@ -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(
<BrowserRouter>
<ThemeProvider>
<SnackbarProvider>
<TestSessionWrapper />
</SnackbarProvider>
</ThemeProvider>
</BrowserRouter>
);

expect(getCoreVersion).toBeCalledTimes(1);
});

test('renders TestSession', () => {
let drawerOpen = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
Expand Down
45 changes: 45 additions & 0 deletions client/src/components/_common/__tests__/ActionModal.test.tsx
Original file line number Diff line number Diff line change
@@ -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(
<ThemeProvider>
<SnackbarProvider>
<ActionModal
modalVisible={true}
message="Mock action message"
cancelTestRun={cancelTestRunMock}
/>
</SnackbarProvider>
</ThemeProvider>
);

const messageText = screen.getByText('Mock action message');
expect(messageText).toBeVisible();
});

test('Pressing cancel hides the modal', () => {
render(
<ThemeProvider>
<SnackbarProvider>
<ActionModal
modalVisible={true}
message="Mock action message"
cancelTestRun={cancelTestRunMock}
/>
</SnackbarProvider>
</ThemeProvider>
);

const cancelButton = screen.getByTestId('cancel-button');
userEvent.click(cancelButton);
expect(cancelTestRunMock).toHaveBeenCalled();
});

0 comments on commit 10a79b6

Please sign in to comment.