Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

129 update tests for curator UI #130

Merged
merged 38 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9900cf5
Update libraries batch-2 first part
stanislaw-zakrzewski Apr 9, 2024
7cfbfb6
Move some testing to TODO
stanislaw-zakrzewski Apr 9, 2024
a8bbb46
Update Yup when
stanislaw-zakrzewski Apr 9, 2024
e5f5a65
update set field values
stanislaw-zakrzewski Apr 9, 2024
4e84668
Update breaking changes
stanislaw-zakrzewski Apr 9, 2024
9b411df
Update comment
stanislaw-zakrzewski Apr 9, 2024
a15ae3e
Remove unused
stanislaw-zakrzewski Apr 9, 2024
d3a0982
update datepicker
stanislaw-zakrzewski Apr 10, 2024
244a601
Update libraries batch-2 second part
stanislaw-zakrzewski Apr 10, 2024
13f2eea
Update return values of the functions for countries
stanislaw-zakrzewski Apr 10, 2024
b86a7d9
update typescript
stanislaw-zakrzewski Apr 10, 2024
b236761
Update mismatched versions
stanislaw-zakrzewski Apr 11, 2024
f202235
WIP update router and eslint + vite instead of cra
stanislaw-zakrzewski Apr 15, 2024
23a758f
Update tests for new vitest library
stanislaw-zakrzewski Apr 17, 2024
ce9f2b4
Update command for test and coverage
stanislaw-zakrzewski Apr 17, 2024
fd38634
Skip tests that were blocking flow
stanislaw-zakrzewski Apr 22, 2024
dc59615
Update Location.test.tsx
stanislaw-zakrzewski Apr 22, 2024
1ea9578
Merge branch 'main' into 121-update-libraries-batch-2
stanislaw-zakrzewski Apr 23, 2024
2513917
Update varaible name
stanislaw-zakrzewski Apr 23, 2024
be295b0
Fix merging issues
stanislaw-zakrzewski Apr 23, 2024
8db3a7b
Update index.tsx
stanislaw-zakrzewski Apr 29, 2024
65b0361
Update index.tsx
stanislaw-zakrzewski Apr 29, 2024
67eb629
WIP tests for location and landing page
stanislaw-zakrzewski Apr 30, 2024
f8d1389
Fixed all landing page tests
stanislaw-zakrzewski Apr 30, 2024
05975b0
Unskip and fix verification status indicator tests
stanislaw-zakrzewski Apr 30, 2024
b488de4
Fix automated source form tests
stanislaw-zakrzewski Apr 30, 2024
5143560
WIP unmocking EditCase tests
stanislaw-zakrzewski Apr 30, 2024
92198bc
Update EditCase.test.tsx
stanislaw-zakrzewski Apr 30, 2024
5e2042e
Fix viewcase tests
stanislaw-zakrzewski Apr 30, 2024
e94e3df
Resolve warnings regarding act
stanislaw-zakrzewski Apr 30, 2024
4813f85
Update Dockerfile
stanislaw-zakrzewski Apr 30, 2024
355aa1e
Update Location.test.tsx
stanislaw-zakrzewski Apr 30, 2024
8c8355f
Fix tests failing at the first day of the month
stanislaw-zakrzewski May 1, 2024
6b4ab01
Cleanup sourcetable
stanislaw-zakrzewski May 1, 2024
f22653b
Update Users Uploads and Sources tables
stanislaw-zakrzewski May 1, 2024
687caaa
Add backfill back
stanislaw-zakrzewski May 6, 2024
ef46cd5
Merge branch 'main' into 129-update-tests-for-curator-ui
stanislaw-zakrzewski May 16, 2024
3454a25
Remove unused tests
stanislaw-zakrzewski May 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion verification/curator-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This dockerfile builds the curator API service and its UI in a single container.
# The UI is served as a static resource from the curator API service express server.
# Security best practices are followed and a trimmed down image is used for production serving.
FROM node:18.18.0 as builder
FROM node:18.20.2 as builder

# Build the curator service.
WORKDIR /usr/src/app/verification/curator-service/api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('<App />', () => {
});

render(<App />, { initialState: initialLoggedInState });
expect(axios.get).toHaveBeenCalledTimes(6);
expect(axios.get).toHaveBeenCalledTimes(5);
expect(axios.get).toHaveBeenCalledWith('/auth/profile');
expect(axios.get).toHaveBeenCalledWith('/version');
expect(axios.get).toHaveBeenCalledWith('/env');
Expand Down Expand Up @@ -184,7 +184,10 @@ describe('<App />', () => {
return Promise.resolve(axiosResponse);
}
});
render(<App />, { initialRoute: '/cases' });
render(<App />, {
initialState: initialLoggedInState,
initialRoute: '/cases',
});

fireEvent.click(await screen.findByTestId('profile-menu'));

Expand Down
7 changes: 4 additions & 3 deletions verification/curator-service/ui/src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,14 @@ function ProfileMenu(props: { user: User; version: string }): JSX.Element {
onClose={handleClose}
data-testid="profile-menu-dropdown"
>
<Link
<MenuItem
component={Link}
to="/profile"
onClick={handleClose}
className={classes.link}
>
<MenuItem>Profile</MenuItem>
</Link>
Profile
</MenuItem>

<MenuItem
onClick={() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { vi } from 'vitest';
import axios from 'axios';
import userEvent from '@testing-library/user-event';
import { act } from 'react-dom/test-utils';

import AutomatedBackfill from './AutomatedBackfill';
import { initialLoggedInState } from '../redux/store';
Expand Down Expand Up @@ -119,10 +120,14 @@ it('displays spinner and status post backfill', async () => {
);
await waitFor(() => expect(axios.get).toHaveBeenCalledTimes(1));

await user.click(
screen.getByLabelText(/Paste URL for data source or search/i),
);
await user.click(screen.getByText('https://example.com'));
await act(async () => {
await user.click(
screen.getByLabelText(/Paste URL for data source or search/i),
);
});
await act(async () => {
await user.click(screen.getByText('https://example.com'));
});

const startDate = screen.getByRole('textbox', {
name: 'First date to backfill (inclusive)',
Expand All @@ -134,13 +139,25 @@ it('displays spinner and status post backfill', async () => {
throw Error('Unable to find date selector');
}

await user.click(screen.getAllByRole('button', { name: 'Choose date' })[0]);
await user.click(screen.getByRole('gridcell', { name: '1' }));
await act(async () => {
await user.click(
screen.getAllByRole('button', { name: 'Choose date' })[0],
);
});
await act(async () => {
await user.click(screen.getByRole('gridcell', { name: '1' }));
});

await user.click(screen.getByRole('button', { name: 'Choose date' }));
await user.click(screen.getByRole('gridcell', { name: '2' }));
await act(async () => {
await user.click(screen.getByRole('button', { name: 'Choose date' }));
});
await act(async () => {
await user.click(screen.getByRole('gridcell', { name: '1' }));
});

await user.click(screen.getByTestId('submit'));
await act(async () => {
await user.click(screen.getByTestId('submit'));
});

expect(screen.getByTestId('submit')).toBeDisabled();
expect(screen.getByTestId('cancel')).toBeDisabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export default function AutomatedSourceForm(props: Props): JSX.Element {
name="excludeFromLineList"
component={CheckboxWithLabel}
type="checkbox"
helperText="Whether cases from this source can appear in the line list"
// helperText="Whether cases from this source can appear in the line list"
required
data-testid="excludeFromLineList"
Label={{
Expand All @@ -294,7 +294,7 @@ export default function AutomatedSourceForm(props: Props): JSX.Element {
name="hasStableIdentifiers"
component={CheckboxWithLabel}
type="checkbox"
helperText="Whether cases from this source have unique, unchanging identifiers"
// helperText="Whether cases from this source have unique, unchanging identifiers"
required
data-testid="hasStableIdentifiers"
Label={{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import userEvent from '@testing-library/user-event';
import { screen, render, waitFor } from './util/test-utils';
import { Button } from '@mui/material';
import { act } from 'react-dom/test-utils';
import { screen, render, waitFor } from './util/test-utils';
import DataGuideDialog from './DataGuideDialog';

const SearchGuideTestCase = ({ defaultOpen = false }): JSX.Element => {
Expand Down Expand Up @@ -34,7 +35,9 @@ it('opens properly after clicking on button', async () => {
screen.queryByText(/Welcome to Global.health Data!/i),
).not.toBeInTheDocument();

await user.click(screen.getByText('Open'));
await act(async () => {
await user.click(screen.getByText('Open'));
});

waitFor(() => {
expect(
Expand All @@ -52,15 +55,19 @@ it('closes properly after clicking on close button', async () => {
screen.queryByText(/Welcome to Global.health Data!/i),
).not.toBeInTheDocument();

await user.click(screen.getByText('Open'));
await act(async () => {
await user.click(screen.getByText('Open'));
});

waitFor(() => {
expect(
screen.queryByText(/Welcome to Global.health Data!/i),
).toBeInTheDocument();
});

await user.click(screen.getByTestId('close-search-guide-button'));
await act(async () => {
await user.click(screen.getByTestId('close-search-guide-button'));
});

expect(
screen.queryByText(/Welcome to Global.health Data!/i),
Expand Down
74 changes: 35 additions & 39 deletions verification/curator-service/ui/src/components/EditCase.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@ import { screen, render } from './util/test-utils';
import EditCase from './EditCase';
import axios from 'axios';
import { vi } from 'vitest';
import { act } from 'react-dom/test-utils';
import { initialLoggedInState } from '../redux/store';
import validateEnv from '../util/validate-env';

beforeAll(() => {
vi.mock('axios');
vi.mock('react-router-dom', async () => {
// eslint-disable-next-line @typescript-eslint/ban-types
const mod = (await vi.importActual('react-router-dom')) as {};
return {
...mod,
useParams: () => ({
id: 'abc123',
}),
};
});
});

afterAll(() => {
vi.clearAllMocks();
});
const env = validateEnv();

afterEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

const env = validateEnv();

describe('<EditCase />', () => {
it.skip('loads and displays case to edit', async () => {
const axiosCaseResponse = {
Expand Down Expand Up @@ -64,24 +76,31 @@ describe('<EditCase />', () => {
}
});

render(
<EditCase
onModalClose={(): void => {
return;
}}
diseaseName={env.VITE_APP_DISEASE_NAME}
/>,
{
initialState: initialLoggedInState,
initialRoute: '/cases/edit/abc123',
},
);
await act(() => {
render(
<EditCase
onModalClose={(): void => {
return;
}}
diseaseName={env.VITE_APP_DISEASE_NAME}
/>,
{
initialState: initialLoggedInState,
},
);
});

await waitFor(() => {
expect(
screen.getByText('Enter the details for an existing case'),
).toBeInTheDocument();
});

expect(
await screen.findByText('Enter the details for an existing case'),
).toBeInTheDocument();

expect(screen.getByText('Submit case edit')).toBeInTheDocument();
expect(await screen.getByText('Submit case edit')).toBeInTheDocument();
expect(screen.getByText(/male/)).toBeInTheDocument();
expect(screen.getByDisplayValue(/Horse breeder/)).toBeInTheDocument();
expect(screen.getByDisplayValue('France')).toBeInTheDocument();
Expand All @@ -90,32 +109,9 @@ describe('<EditCase />', () => {
expect(screen.getByDisplayValue('Moderna')).toBeInTheDocument();
expect(screen.getByDisplayValue('PCR test')).toBeInTheDocument();
expect(screen.getByText('confirmed')).toBeInTheDocument();
// TODO: These show up locally but we need to figure out how to properly
// expect(screen.getByDisplayValue('2020/01/02')).toBeInTheDocument();
// expect(screen.getByDisplayValue('2020/01/04')).toBeInTheDocument();
// expect(screen.getByDisplayValue('2020/01/03')).toBeInTheDocument();
// expect(screen.getByDisplayValue('2020/01/05')).toBeInTheDocument();
// expect(screen.getByDisplayValue('2020/02/01')).toBeInTheDocument();
// expect(screen.getByDisplayValue('2020/01/01')).toBeInTheDocument();
// query them in tests.
// expect(screen.getByDisplayValue('Paris')).toBeInTheDocument();
//expect(await findByText(/Swedish/)).toBeInTheDocument();
//expect(getByText('Severe acute respiratory')).toBeInTheDocument();
// expect(
// getByDisplayValue('The reference sequence is identical to MN908947'),
// ).toBeInTheDocument();
//expect(getByText('2.35')).toBeInTheDocument();
//expect(getByText('48.85')).toBeInTheDocument();
//expect(getByDisplayValue('Hypertension')).toBeInTheDocument();
//expect(getByDisplayValue('Plane')).toBeInTheDocument();
// expect(
// getByDisplayValue('Contact of a confirmed case at work'),
// ).toBeInTheDocument();
//expect(getByDisplayValue('Vector borne')).toBeInTheDocument();
//expect(getByDisplayValue('Gym')).toBeInTheDocument();
});

it.skip('displays API errors', async () => {
it('displays API errors', async () => {
axios.get.mockRejectedValueOnce(new Error('Request failed'));

render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { format } from 'date-fns';
import { initialLoggedInState } from '../../redux/store';
import axios from 'axios';
import { vi } from 'vitest';
import { act } from 'react-dom/test-utils';
import validateEnv from '../../util/validate-env';
import { Role } from '../../api/models/User';

Expand Down Expand Up @@ -63,7 +64,9 @@ describe('<FiltersDialog />', () => {
initialRoute: '/cases',
});

await user.click(screen.getByRole('button', { name: /FILTER/i }));
await act(async () => {
await user.click(screen.getByRole('button', { name: /FILTER/i }));
});

expect(await screen.findByText(/Apply filters/i)).toBeInTheDocument();
});
Expand All @@ -76,7 +79,9 @@ describe('<FiltersDialog />', () => {
initialRoute: '/cases',
});

await user.click(screen.getByRole('button', { name: /FILTER/i }));
await act(async () => {
await user.click(screen.getByRole('button', { name: /FILTER/i }));
});

expect(await screen.findByText(/Apply filters/i)).toBeInTheDocument();

Expand All @@ -88,10 +93,12 @@ describe('<FiltersDialog />', () => {
const toDateInput = screen.getByLabelText(/Date confirmed to/i);
const fromDateInput = screen.getByLabelText(/Date confirmed from/i);

await user.type(toDateInput, futureDate);
await user.type(fromDateInput, futureDate);
await act(async () => {
await user.type(toDateInput, futureDate);
await user.type(fromDateInput, futureDate);

await user.click(screen.getByRole('button', { name: 'Apply' }));
await user.click(screen.getByRole('button', { name: 'Apply' }));
});

// Check if the modal is still open
expect(await screen.findByText(/Apply filters/i)).toBeInTheDocument();
Expand Down
Loading
Loading