Skip to content

Commit

Permalink
tests: fix flaky e2e and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karolina-siemieniuk-morawska committed Apr 15, 2024
1 parent 3f246e7 commit 9248bb1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
2 changes: 2 additions & 0 deletions e2e/cypress/e2e/references.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ describe('Reference container', () => {
.find('[data-test-id="reference-title"]')
.as('referenceTitle');

cy.wait(5000);
cy.get('@editButton').click();
cy.wait(5000);
cy.get('[data-test-id="reference-embedded-search')
.find('.ant-input-search-button')
.click();
Expand Down
16 changes: 8 additions & 8 deletions e2e/cypress/e2e/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ describe('settings', () => {
onlyOn('headless', () => {
it.skip('matches image snapshot', () => {
cy.visit('/user/settings');
cy.wait(2000);
cy.wait(10000);
cy.matchSnapshots('Settings');
});
});

it('enables submit button when email is correct', () => {
cy.visit('/user/settings');
cy.wait(2000);
cy.wait(10000);

cy.get('[data-test-id=email]')
.clear()
Expand All @@ -29,7 +29,7 @@ describe('settings', () => {

it('should display validation error when email is incorrect', () => {
cy.visit('/user/settings');
cy.wait(2000);
cy.wait(10000);

cy.get('[data-test-id=email]').clear().type('johnrellis@inspirehep').blur();

Expand All @@ -40,7 +40,7 @@ describe('settings', () => {
const recordId = 1010819;

cy.visit('/user/settings');
cy.wait(2000);
cy.wait(10000);

cy.get('[data-test-id="author-form"]').click();

Expand All @@ -49,15 +49,15 @@ describe('settings', () => {

it('exports to orcid', () => {
cy.visit('/user/settings');
cy.wait(2000);
cy.wait(10000);

cy.get('[data-test-id="orcid-switch"]').click();
cy.get('div[class~="ant-popconfirm"]')
.find('button[class~="ant-btn-primary"]')
.click();

cy.reload();
cy.wait(2000);
cy.wait(10000);

cy.get('[data-test-id="orcid-switch"]').should(
'have.attr',
Expand All @@ -68,15 +68,15 @@ describe('settings', () => {

it('unexports from orcid', () => {
cy.visit('/user/settings');
cy.wait(2000);
cy.wait(10000);

cy.get('[data-test-id="orcid-switch"]').click();
cy.get('div[class~="ant-popconfirm"]')
.find('button[class~="ant-btn-primary"]')
.click();

cy.reload();
cy.wait(2000);
cy.wait(10000);

cy.get('[data-test-id="orcid-switch"]').should(
'have.attr',
Expand Down
2 changes: 1 addition & 1 deletion e2e/cypress/support/commands/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Cypress.Commands.add(
method: 'POST',
});
cy.submitForm(formData);

cy.wait(5000);
return cy.waitForRoute(apiRoute).then(() => {
if (submissionType === 'record') {
cy.testRecord(expectedMetadata);
Expand Down
11 changes: 8 additions & 3 deletions ui/src/user/components/SignUpPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ const SignUpPage: React.FC<{
registration.
</p>
{error && (
<Row className="mb3" data-testid={error.message}>
<Row className="mb3" data-testid="error">
<Col>
<Alert message={error.message} type="error" showIcon closable />
<Alert
message={error.message || 'Something went wrong'}
type="error"
showIcon
closable
/>
</Col>
</Row>
)}
<div data-testid={loading}>
<div data-testid={loading ? 'loading' : ''}>
<SingUpForm onSignUp={onSignUp} loading={loading} />
</div>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports[`SignUpPage renders page 1`] = `
Please let us know your e-mail address to complete your account registration.
</p>
<div
data-testid="false"
data-testid=""
>
<form
action="#"
Expand Down Expand Up @@ -94,7 +94,7 @@ exports[`SignUpPage renders page with errors 1`] = `
</p>
<div
class="ant-row mb3"
data-testid="This is an error yo"
data-testid="error"
>
<div
class="ant-col"
Expand Down Expand Up @@ -161,7 +161,7 @@ exports[`SignUpPage renders page with errors 1`] = `
</div>
</div>
<div
data-testid="false"
data-testid=""
>
<form
action="#"
Expand Down Expand Up @@ -238,7 +238,7 @@ exports[`SignUpPage renders page with loading 1`] = `
Please let us know your e-mail address to complete your account registration.
</p>
<div
data-testid="true"
data-testid="loading"
>
<form
action="#"
Expand Down
23 changes: 12 additions & 11 deletions ui/src/user/containers/__tests__/SignUpPageContainer.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { render, fireEvent, waitFor } from '@testing-library/react';
import "@testing-library/jest-dom/extend-expect";
import '@testing-library/jest-dom/extend-expect';
import userEvent from '@testing-library/user-event';
import { Provider } from 'react-redux';
import { MemoryRouter } from 'react-router-dom';
Expand All @@ -24,17 +24,17 @@ describe('SignUpPageContainer', () => {
);

const emailInput = getByTestId('email');
await waitFor(() => fireEvent.change(emailInput, { target: { value: '[email protected]' } }));
await waitFor(() =>
fireEvent.change(emailInput, { target: { value: '[email protected]' } })
);
const submitButton = getByTestId('submit');
await waitFor(() => userEvent.click(submitButton));

const expectedActions = [
{
type: USER_SIGN_UP_REQUEST,
},
];
const expectedActions = {
type: USER_SIGN_UP_REQUEST,
};

await waitFor(() => expect(store.getActions()).toEqual(expectedActions));
await waitFor(() => expect(store.getActions()[0]).toEqual(expectedActions));
});

it('passes errors, onSubmit, and loading from the state', () => {
Expand All @@ -47,13 +47,14 @@ describe('SignUpPageContainer', () => {
}),
});

const { getByTestId } = render(
const { getByTestId, getByText } = render(
<Provider store={store}>
<SignUpPageContainer />
</Provider>
);

expect(getByTestId('This is an error')).toBeInTheDocument();
expect(getByTestId('true')).toBeInTheDocument();
expect(getByTestId('error')).toBeInTheDocument();
expect(getByText('This is an error')).toBeInTheDocument();
expect(getByTestId('loading')).toBeInTheDocument();
});
});

0 comments on commit 9248bb1

Please sign in to comment.