Optimize car update status progress control Remove car update status page test Replace with individual component tests
182 lines
5.4 KiB
JavaScript
182 lines
5.4 KiB
JavaScript
jest.mock("../Contexts/CarUpdatesContext");
|
|
jest.mock("../Contexts/FileUploadContext");
|
|
jest.mock("../Contexts/VehicleContext");
|
|
jest.mock("../Contexts/ManifestCreateContext");
|
|
jest.mock("../Contexts/ManifestsContext");
|
|
jest.mock("../Contexts/UserContext");
|
|
jest.mock("../../services/grafanaAPI");
|
|
jest.mock("../../services/monitoring");
|
|
jest.mock("../../services/vehiclesAPI");
|
|
|
|
import {
|
|
render,
|
|
screen,
|
|
cleanup,
|
|
waitFor,
|
|
waitForElementToBeRemoved,
|
|
} from "@testing-library/react";
|
|
import { setToken } from "../Contexts/UserContext";
|
|
import { TEST_AUTH_OBJECT } from "../../utils/testing";
|
|
import App from ".";
|
|
|
|
const LOADING_STATUS = "Loading...";
|
|
|
|
const renderRoute = async (route) => {
|
|
window.history.pushState({}, "", route);
|
|
const { container } = render(<App />);
|
|
if (screen.queryByText(LOADING_STATUS)) {
|
|
await waitForElementToBeRemoved(() => screen.getByText(LOADING_STATUS));
|
|
}
|
|
return container;
|
|
};
|
|
|
|
const check = async (path, selector, compare) => {
|
|
const container = await renderRoute(path);
|
|
expect(container.querySelector(selector).innerHTML).toEqual(compare);
|
|
expect(container).toMatchSnapshot();
|
|
};
|
|
|
|
const sleepAndCheck = async (path, selector, compare) => {
|
|
const container = await renderRoute(path);
|
|
await waitFor(() => {});
|
|
expect(container.querySelector(selector).innerHTML).toEqual(compare);
|
|
expect(container).toMatchSnapshot();
|
|
};
|
|
|
|
describe("App", () => {
|
|
beforeAll(() => {
|
|
// Stablize Table Pagination control ids
|
|
expect.addSnapshotSerializer({
|
|
test: function (val) {
|
|
return val && typeof val === "string" && val.indexOf("mui-") >= 0;
|
|
},
|
|
print: function (val) {
|
|
let str = val;
|
|
str = str.replace(/mui-\d*/g, "mui-00000");
|
|
|
|
return `"${str}"`;
|
|
},
|
|
});
|
|
}, 60000);
|
|
|
|
afterEach(() => {
|
|
setToken(null);
|
|
cleanup();
|
|
});
|
|
|
|
it("Route / unauthenticated", async () => {
|
|
await sleepAndCheck("/", "span.MuiButton-label", "Sign In");
|
|
});
|
|
|
|
it("Route /home unauthenticated", async () => {
|
|
await sleepAndCheck("/home", "span.MuiButton-label", "Sign In");
|
|
});
|
|
|
|
it("Route /datascope unauthenticated", async () => {
|
|
await sleepAndCheck("/datascope", "span.MuiButton-label", "Sign In");
|
|
});
|
|
|
|
it("Route /datascope/battery unauthenticated", async () => {
|
|
await check("/datascope/battery", "span.MuiButton-label", "Sign In");
|
|
});
|
|
|
|
it("Route /packages unauthenticated", async () => {
|
|
await check("/packages", "span.MuiButton-label", "Sign In");
|
|
});
|
|
|
|
it("Route /package-status unauthenticated", async () => {
|
|
await check("/package-status/1", "span.MuiButton-label", "Sign In");
|
|
});
|
|
|
|
it("Route /package-deploy unauthenticated", async () => {
|
|
await check("/package-deploy/1", "span.MuiButton-label", "Sign In");
|
|
});
|
|
|
|
it("Route /package-create unauthenticated", async () => {
|
|
await check("/package-create", "span.MuiButton-label", "Sign In");
|
|
});
|
|
|
|
it("Route /vehicle-add unauthenticated", async () => {
|
|
await check("/vehicle-add", "span.MuiButton-label", "Sign In");
|
|
});
|
|
|
|
it("Route /vehicles unauthenticated", async () => {
|
|
await check("/vehicles", "span.MuiButton-label", "Sign In");
|
|
});
|
|
|
|
it("Route /vehicle-status unauthenticated", async () => {
|
|
await check("/vehicle-status/FISKER123", "span.MuiButton-label", "Sign In");
|
|
});
|
|
|
|
it("Route /vehicle-status/vin/carupdateid unauthenticated", async () => {
|
|
await check(
|
|
"/vehicle-status/1G1FP87S3GN100062/283",
|
|
"span.MuiButton-label",
|
|
"Sign In"
|
|
);
|
|
});
|
|
|
|
it("Route /page-not-found unauthenticated", async () => {
|
|
await check("/page-not-found", "h1", "Page Not Found");
|
|
});
|
|
it("Route / authenticated", async () => {
|
|
setToken(TEST_AUTH_OBJECT);
|
|
await sleepAndCheck("/", "h6", "Home");
|
|
});
|
|
|
|
it("Route /home authenticated", async () => {
|
|
setToken(TEST_AUTH_OBJECT);
|
|
await sleepAndCheck("/home", "h6", "Home");
|
|
});
|
|
|
|
it("Route /page-not-found authenticated", async () => {
|
|
setToken(TEST_AUTH_OBJECT);
|
|
await check("/page-not-found", "h1", "Page Not Found");
|
|
});
|
|
|
|
it("Route /datascope authenticated", async () => {
|
|
setToken(TEST_AUTH_OBJECT);
|
|
await sleepAndCheck("/datascope", "h6", "Datascope");
|
|
});
|
|
|
|
it("Route /datascope/battery authenticated", async () => {
|
|
setToken(TEST_AUTH_OBJECT);
|
|
await check("/datascope/battery", "h6", "Battery");
|
|
});
|
|
|
|
it("Route /packages authenticated", async () => {
|
|
setToken(TEST_AUTH_OBJECT);
|
|
await check("/packages", "h6", "Deployments");
|
|
});
|
|
|
|
it("Route /package-status authenticated", async () => {
|
|
setToken(TEST_AUTH_OBJECT);
|
|
await check("/package-status/1", "h6", "Manifest Test Manifest 1.0");
|
|
});
|
|
|
|
it("Route /package-deploy authenticated", async () => {
|
|
setToken(TEST_AUTH_OBJECT);
|
|
await check("/package-deploy/1", "h6", "Deploy Test Manifest 1.0");
|
|
});
|
|
|
|
it("Route /package-create authenticated", async () => {
|
|
setToken(TEST_AUTH_OBJECT);
|
|
await check("/package-create", "h6", "Create Deployments");
|
|
});
|
|
|
|
it("Route /vehicle-add authenticated", async () => {
|
|
setToken(TEST_AUTH_OBJECT);
|
|
await check("/vehicle-add", "h6", "Add Vehicle");
|
|
});
|
|
|
|
it("Route /vehicles authenticated", async () => {
|
|
setToken(TEST_AUTH_OBJECT);
|
|
await check("/vehicles", "h6", "Vehicles");
|
|
});
|
|
|
|
it("Route /vehicle-status authenticated", async () => {
|
|
setToken(TEST_AUTH_OBJECT);
|
|
await check("/vehicle-status/FISKER123", "h6", "Vehicle FISKER123 Details");
|
|
});
|
|
});
|