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

Fix a whole bunch of frontend test issues #3028

Merged
merged 25 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bb1922b
Remove pending org edit tests for now
nickclyde Nov 19, 2021
620f5cd
Merge branch 'main' into nick/add-missing-mocks
nickclyde Nov 23, 2021
a02bce4
Add eslint-plugin-testing-library
nickclyde Nov 23, 2021
76106d3
Fix lint errors for PendingOrganizationsContainer.test.tsx
nickclyde Nov 23, 2021
40e8eee
Start fixing new lint errors
nickclyde Nov 23, 2021
2d25b3c
Add eslint-plugin-unused-imports
nickclyde Nov 24, 2021
740fbab
Continue fixing lint errors
nickclyde Nov 24, 2021
4a71b05
Merge branch 'main' into nick/add-missing-mocks
nickclyde Nov 29, 2021
71557f3
Continue fixing lint rules
nickclyde Nov 29, 2021
d5a0802
Finish fixing lints
nickclyde Nov 30, 2021
f65ac8f
Replace react-test-renderer with testing-library everywhere
nickclyde Nov 30, 2021
b4a49f1
Clean up some console warnings
nickclyde Nov 30, 2021
cfe511a
Keep working at AddPatient.test.tsx
nickclyde Nov 30, 2021
b6caebf
Clean up unused vars
nickclyde Nov 30, 2021
063b8f7
Replace unused vars for i18n constants
nickclyde Nov 30, 2021
b6fb3bb
Suppress moment deprecation warning in setupTests.js
nickclyde Nov 30, 2021
efe42a5
Fix AddPatient.test.tsx
nickclyde Nov 30, 2021
28c402f
Suppress DOMException in QueueItem.test.tsx
nickclyde Nov 30, 2021
d5678d6
Merge branch 'main' into nick/add-missing-mocks
nickclyde Nov 30, 2021
3a76134
Remove remaining act() calls
nickclyde Nov 30, 2021
da2aa18
Bump up Jest timeout globally to prevent 'createEvent' TypeError
nickclyde Nov 30, 2021
6e3d685
Exclude frontend test setup file from sonar coverage
nickclyde Nov 30, 2021
9539ed9
Remove unnecessary cleanup calls
nickclyde Nov 30, 2021
63b9087
Add eslint-plugin-jest-dom
nickclyde Nov 30, 2021
76cbd1b
Merge branch 'main' into nick/add-missing-mocks
nickclyde Nov 30, 2021
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
1 change: 1 addition & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ sonarqube {
// In order to get both the frontend and backend code to report, we need to set the sonar project to the root directory.
property "sonar.sources", "backend/src/main/java,frontend/src,ops/services/app_functions/"
property "sonar.exclusions", "backend/src/**/*Config*.java,frontend/src/**/*.test.*,frontend/src/stories/**/*,frontend/src/**/*.stories.tsx,frontend/src/generated/*.tsx,ops/services/app_functions/**/*.test.*,ops/services/app_functions/**/*config*"
property "sonar.coverage.exclusions", "frontend/src/setupTests.js"
property "sonar.cpd.exclusions", "frontend/src/lang/*.ts"
property "sonar.javascript.lcov.reportPaths", "frontend/coverage/lcov.info,ops/services/app_functions/report_stream_batched_publisher/functions/coverage/lcov.info"
}
Expand Down
44 changes: 39 additions & 5 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@
"plugin:import/warnings"
],
"plugins": [
"graphql"
"graphql",
"testing-library",
"unused-imports",
"jest-dom"
],
"rules": {
"graphql/template-strings": [
Expand All @@ -124,7 +127,18 @@
}
],
"import/newline-after-import": 1,
"import/no-commonjs": 0
"import/no-commonjs": 0,
"no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"warn",
{
"vars": "all",
"varsIgnorePattern": "^_",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, does this mean I can prefix unused variables with an underscore and the linter won't yell at me for it? 😁

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!! 🎉

"args": "after-used",
"argsIgnorePattern": "^_"
}
]
},
"overrides": [
{
Expand All @@ -134,6 +148,25 @@
"rules": {
"import/no-anonymous-default-export": "off"
}
},
{
"files": [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[jt]s?(x)"
],
"extends": [
"plugin:testing-library/react",
"plugin:jest-dom/recommended"
],
"rules": {
"testing-library/no-render-in-setup": [
"error",
{
"allowTestingFrameworkSetupHook": "beforeEach"
}
],
"testing-library/no-node-access": "off"
}
}
]
},
Expand Down Expand Up @@ -169,7 +202,6 @@
"@types/react-dom": "^17.0.0",
"@types/react-modal": "^3.10.6",
"@types/react-redux": "^7.1.11",
"@types/react-test-renderer": "^17.0.1",
"@types/redux-mock-store": "^1.0.2",
"@types/smartystreets-javascript-sdk": "^1.6.2",
"@types/uuid": "^8.3.0",
Expand All @@ -181,6 +213,9 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-graphql": "^4.0.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest-dom": "^3.9.2",
"eslint-plugin-testing-library": "^5.0.0",
"eslint-plugin-unused-imports": "1.1.5",
"faker": "^5.5.3",
"geckodriver": "^1.22.3",
"jest-fetch-mock": "^3.0.3",
Expand All @@ -190,7 +225,6 @@
"nightwatch": "^1.5.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.2.1",
"react-test-renderer": "^17.0.1",
"redux-mock-store": "^1.5.4",
"stylelint": "^13.12.0",
"stylelint-config-standard": "^21.0.0",
Expand All @@ -207,4 +241,4 @@
"\\.(css|less|sass|scss)$": "<rootDir>/__mocks__/styleMock.js"
}
}
}
}
17 changes: 10 additions & 7 deletions frontend/src/app/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { BrowserRouter as Router, MemoryRouter, Route } from "react-router-dom";
import { Provider } from "react-redux";
import createMockStore, { MockStoreEnhanced } from "redux-mock-store";
import { MockedProvider, MockedResponse } from "@apollo/client/testing";
import { render, screen, waitFor } from "@testing-library/react";
import {
render,
screen,
waitForElementToBeRemoved,
} from "@testing-library/react";
import userEvent from "@testing-library/user-event";

import { GetTopLevelDashboardMetricsNewDocument } from "../generated/graphql";
Expand Down Expand Up @@ -234,9 +238,10 @@ describe("App", () => {
facilityQueryMock,
getAnalyticsQueryMock(),
]);
await waitFor(() => {
userEvent.click(screen.getByText("Testing Site", { exact: false }));
});
await waitForElementToBeRemoved(() =>
screen.queryByText("Loading account information...")
);
userEvent.click(screen.getAllByText("Testing Site", { exact: false })[0]);
expect(
await screen.findByText("COVID-19 testing data")
).toBeInTheDocument();
Expand All @@ -260,9 +265,7 @@ describe("App", () => {
exact: false,
});
expect(trainingWelcome).toBeInTheDocument();
await waitFor(() => {
userEvent.click(screen.getByText("Got it", { exact: false }));
});
userEvent.click(screen.getByText("Got it", { exact: false }));
expect(trainingWelcome).not.toBeInTheDocument();
});
it("does not display training notifications outside the training environment", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { useState } from "react";
import {
fireEvent,
render,
screen,
waitFor,
within,
} from "@testing-library/react";
import { fireEvent, render, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

import ManageDevices from "./ManageDevices";
Expand Down Expand Up @@ -140,14 +134,14 @@ describe("ManageDevices", () => {
it("allows user to change the device type on an existing device", async () => {
const [deviceDropdown] = await screen.findAllByRole("combobox");

await waitFor(() => {
userEvent.selectOptions(deviceDropdown, "device-c");
});
userEvent.selectOptions(deviceDropdown, "device-c");

expect(
(screen.getAllByRole("option", {
name: "Device C",
})[0] as HTMLOptionElement).selected
((
await screen.findAllByRole("option", {
name: "Device C",
})
)[0] as HTMLOptionElement).selected
).toBeTruthy();
});

Expand All @@ -157,14 +151,14 @@ describe("ManageDevices", () => {
"combobox"
);

await waitFor(() => {
userEvent.selectOptions(swabDropdown, "fake-specimen-id-2");
});
userEvent.selectOptions(swabDropdown, "fake-specimen-id-2");

expect(
(screen.getAllByRole("option", {
name: "Fake Specimen 2",
})[0] as HTMLOptionElement).selected
((
await screen.findAllByRole("option", {
name: "Fake Specimen 2",
})
)[0] as HTMLOptionElement).selected
).toBeTruthy();
});

Expand All @@ -180,9 +174,7 @@ describe("ManageDevices", () => {

expect(dropdowns.length).toBe(4);

await waitFor(() => {
fireEvent.click(screen.getByText("Add device", { exact: false }));
});
fireEvent.click(screen.getByText("Add device", { exact: false }));

const updatedDropdowns = await screen.findAllByRole("combobox");
expect(updatedDropdowns.length).toBe(6);
Expand All @@ -193,11 +185,9 @@ describe("ManageDevices", () => {

expect(dropdowns.length).toBe(4);

await waitFor(() => {
fireEvent.click(
screen.getAllByLabelText("Delete device", { exact: false })[0]
);
});
fireEvent.click(
screen.getAllByLabelText("Delete device", { exact: false })[0]
);

const updatedDropdowns = await screen.findAllByRole("combobox");
expect(updatedDropdowns.length).toBe(2);
Expand All @@ -217,14 +207,14 @@ describe("ManageDevices", () => {
).toBeTruthy();

// Change device to one with _different_ configured swab types
await waitFor(() => {
userEvent.selectOptions(deviceDropdownElement, "device-b");
});
userEvent.selectOptions(deviceDropdownElement, "device-b");

expect(
(screen.getAllByRole("option", {
name: "Fake Specimen 1",
})[0] as HTMLOptionElement).selected
((
await screen.findAllByRole("option", {
name: "Fake Specimen 1",
})
)[0] as HTMLOptionElement).selected
).toBeTruthy();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const ManageDevices: React.FC<Props> = ({
updateDefaultDevice,
deviceSpecimenTypeOptions,
errors,
validateField,
}) => {
const deviceErrors: React.ReactNode[] = [];
if (errors.deviceTypes) {
Expand Down
24 changes: 11 additions & 13 deletions frontend/src/app/Settings/Facility/FacilityFormContainer.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { render, screen, act } from "@testing-library/react";
import {
render,
screen,
waitForElementToBeRemoved,
} from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { MockedProvider } from "@apollo/client/testing";
import { Provider } from "react-redux";
Expand Down Expand Up @@ -232,20 +236,14 @@ describe("FacilityFormContainer", () => {
});

it("redirects on successful save", async () => {
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 0));
await userEvent.click(screen.getByRole("button"));
await new Promise((resolve) => setTimeout(resolve, 0));
expect(await screen.findByText("Redirected")).toBeDefined();
});
await waitForElementToBeRemoved(() => screen.queryByText("Loading..."));
userEvent.click(screen.getByRole("button"));
expect(await screen.findByText("Redirected")).toBeInTheDocument();
});

it("tracks custom telemetry event on successful save", async () => {
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 0));
await userEvent.click(screen.getByRole("button"));
await new Promise((resolve) => setTimeout(resolve, 0));
expect(trackEventMock).toBeCalledWith({ name: "Save Settings" });
});
await waitForElementToBeRemoved(() => screen.queryByText("Loading..."));
userEvent.click(screen.getByRole("button"));
expect(trackEventMock).toBeCalledWith({ name: "Save Settings" });
});
});
Loading