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

#2954 curator api disease agnostic #2

Merged
merged 32 commits into from
Mar 14, 2023
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
fixed bugs and tests
  • Loading branch information
Maciej Zarzeczny committed Jan 4, 2023
commit a306eaa6c19e499cc09eabdf19cc259c776399b7
28 changes: 14 additions & 14 deletions verification/curator-service/ui/cypress/e2e/components/All.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// import './AcknowledgmentsPage.spec';
// import './AppTest.spec';
// import './AutomatedSourceForm.spec';
// import './BulkCaseForm.spec';
// import './Curator.spec';
// import './EditCase.spec';
// import './LandingPage.spec';
// import './LinelistTableTest.spec';
// import './NewCaseForm.spec';
// import './ProfileTest.spec';
// import './SourceTableTest.spec';
// import './UploadsTableTest.spec';
// import './UsersTest.spec';
// import './ViewCase.spec';
import './AcknowledgmentsPage.spec';
import './AppTest.spec';
import './AutomatedSourceForm.spec';
import './BulkCaseForm.spec';
import './Curator.spec';
import './EditCase.spec';
import './LandingPage.spec';
import './LinelistTableTest.spec';
import './NewCaseForm.spec';
import './ProfileTest.spec';
import './SourceTableTest.spec';
import './UploadsTableTest.spec';
import './UsersTest.spec';
import './ViewCase.spec';
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ describe('App', function () {
cy.contains('Line list').click();

cy.get('.filter-button').click();
cy.get('#dateconfirmedafter').type('2020-04-30');
cy.get('#dateConfirmedFrom').type('2020-04-30');

cy.get('body').then(($body) => {
if ($body.find('.iubenda-cs-accept-btn').length) {
@@ -51,50 +51,6 @@ describe('App', function () {
cy.contains('2020-02-15').should('not.exist');
});

it('allows the user to search by nationality', function () {
cy.login({
roles: ['curator'],
name: 'testName',
email: 'test@example.com',
});
cy.visit('/');
cy.contains('Line list').click();

cy.addCase({
country: 'Russia',
nationalities: ['American', 'Filipino', 'Polish'],
});

cy.get('.filter-button').click();
cy.get('#nationality').type('filipino');
cy.get('[data-test-id="search-by-filter-button"]').click();

cy.contains('American, Filipino, Polish');
});

it('allows the user to search by variant', function () {
cy.login({
roles: ['curator'],
name: 'testName',
email: 'test@example.com',
});
cy.visit('/');
cy.contains('Line list').click();

cy.addCase({
country: 'Peru',
variant: 'B.1.351',
sourceUrl: 'www.variantb1351.com',
});

cy.contains('Line list').click();

cy.get('.filter-button').click();
cy.get('#variant').type('B.1.351{Enter}');

cy.contains('www.variantb1351.com');
});

it('allows the user to search by not provided gender', function () {
cy.login({
roles: ['curator'],
89 changes: 26 additions & 63 deletions verification/curator-service/ui/src/components/CaseForm.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { fireEvent, render, waitFor, screen } from '@testing-library/react';

import { fireEvent, render, waitFor, screen } from './util/test-utils';
import CaseForm from './CaseForm';
import { MemoryRouter } from 'react-router-dom';
import axios from 'axios';
import { ThemeProvider } from '@mui/material/styles';
import { theme } from '../theme/theme';
import { initialLoggedInState } from '../redux/store';

jest.mock('axios');
const mockedAxios = axios as jest.Mocked<typeof axios>;
@@ -33,14 +33,6 @@ beforeEach(() => {
headers: {},
};
mockedAxios.get.mockResolvedValueOnce(axiosSymptomsResponse);
const axiosPlacesOfTransmissionResponse = {
data: { placesOfTransmission: [] },
status: 200,
statusText: 'OK',
config: {},
headers: {},
};
mockedAxios.get.mockResolvedValueOnce(axiosPlacesOfTransmissionResponse);
const axiosOccupationResponse = {
data: { occupations: [] },
status: 200,
@@ -57,72 +49,43 @@ afterEach(() => {

it('renders form', async () => {
render(
<MemoryRouter>
<ThemeProvider theme={theme}>
<CaseForm
onModalClose={(): void => {
return;
}}
diseaseName="COVID-19"
/>
</ThemeProvider>
</MemoryRouter>,
<CaseForm
onModalClose={(): void => {
return;
}}
diseaseName="COVID-19"
/>,
{
initialState: initialLoggedInState,
initialRoute: '/cases/new',
},
);
await waitFor(() => expect(mockedAxios.get).toHaveBeenCalledTimes(4));
await waitFor(() => expect(mockedAxios.get).toHaveBeenCalledTimes(3));
expect(
screen.getByText('Enter the details for a new case'),
).toBeInTheDocument();
expect(screen.getByText(/Submit case/i)).toBeInTheDocument();
expect(screen.getAllByText(/Demographics/i)).toHaveLength(1);
expect(screen.getAllByText(/Location/i)).toHaveLength(3);
expect(screen.getAllByText(/Location/i)).toHaveLength(4);
expect(screen.getAllByText(/Events/i)).toHaveLength(1);
expect(screen.getByTestId('caseReference')).toBeInTheDocument();
expect(screen.getByLabelText(/Nationalities/i)).toBeInTheDocument();
expect(screen.getByText(/Variant of Concern/i)).toBeInTheDocument();
});

test('Check location error message to become red on submit', () => {
const { getByText } = render(
<MemoryRouter>
<ThemeProvider theme={theme}>
<CaseForm
onModalClose={(): void => {
return;
}}
diseaseName="COVID-19"
/>
</ThemeProvider>
</MemoryRouter>,
render(
<CaseForm
onModalClose={(): void => {
return;
}}
diseaseName="COVID-19"
/>,
{ initialState: initialLoggedInState, initialRoute: '/cases/new' },
);

const mandatoryLocationMessage = getByText('A location must be provided');
const submittButton = getByText(/Submit case/i);
const mandatoryLocationMessage = screen.getByText(
'A location must be provided',
);
const submittButton = screen.getByText(/Submit case/i);
fireEvent.click(submittButton);
expect(mandatoryLocationMessage).toHaveClass('Mui-error');
});

it('can add and remove genome sequencing sections', async () => {
const { queryByTestId, getByTestId, getByText } = render(
<MemoryRouter>
<ThemeProvider theme={theme}>
<CaseForm
onModalClose={(): void => {
return;
}}
diseaseName="COVID-19"
/>
</ThemeProvider>
</MemoryRouter>,
);
await waitFor(() => expect(mockedAxios.get).toHaveBeenCalledTimes(4));

expect(queryByTestId('genome-sequence-section')).not.toBeInTheDocument();
await waitFor(() => {
fireEvent.click(getByText(/Add genome sequence/));
});
expect(queryByTestId('genome-sequence-section')).toBeInTheDocument();
await waitFor(() => {
fireEvent.click(getByTestId('remove-genome-sequence-button'));
});
expect(queryByTestId('genome-sequence-section')).not.toBeInTheDocument();
});
20 changes: 16 additions & 4 deletions verification/curator-service/ui/src/components/CaseForm.tsx
Original file line number Diff line number Diff line change
@@ -57,7 +57,21 @@ const FormSection = styled(Paper)(() => ({
margin: '2em 0',
}));

const initialValuesFromCase = (pathogen: string, c?: ParsedCase) => {
const parseAge = (age?: string) => {
if (!age) return null;

const ageArr = age.split('-');
if (ageArr.length === 2) {
return { minAge: ageArr[0], maxAge: ageArr[1] };
}

return { age };
};

const initialValuesFromCase = (
pathogen: string,
c?: ParsedCase,
): ParsedCase => {
if (!c) {
return {
id: undefined,
@@ -124,7 +138,7 @@ const initialValuesFromCase = (pathogen: string, c?: ParsedCase) => {
};
}

return c;
return { ...c, ...parseAge(c.age) };
};

interface Props {
@@ -300,9 +314,7 @@ export default function CaseForm(props: Props): JSX.Element {
newCaseId = postResponse.data._id;
}
setErrorMessage('');
console.log('success');
} catch (e) {
console.log('error');
setErrorMessage(e.response?.data?.message || e.toString());
return;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { render, screen } from '../util/test-utils';
import userEvent from '@testing-library/user-event';
import FiltersDialog from './index';
import App from '../App';
import { MemoryRouter } from 'react-router-dom';
import { format } from 'date-fns';
import { initialLoggedInState } from '../../redux/store';
import axios from 'axios';
@@ -74,11 +72,11 @@ describe('<FiltersDialog />', () => {
date.setDate(date.getDate() + 1);
const futureDate = format(date, 'yyyy-MM-dd');

const dateBeforeInput = screen.getByLabelText(/Date confirmed before/i);
const dateAfterInput = screen.getByLabelText(/Date confirmed after/i);
const toDateInput = screen.getByLabelText(/Date confirmed to/i);
const fromDateInput = screen.getByLabelText(/Date confirmed from/i);

await user.type(dateBeforeInput, futureDate);
await user.type(dateAfterInput, futureDate);
await user.type(toDateInput, futureDate);
await user.type(fromDateInput, futureDate);

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

Loading