Skip to content
Snippets Groups Projects
Commit 427a788c authored by Max Frederiksen's avatar Max Frederiksen Committed by Max Frederiksen
Browse files

Refactor Cypress related files

parent eca714b2
No related branches found
No related tags found
2 merge requests!612Release 5.0.0,!590CE-3429: Convert to typescript
import { mount } from "cypress/react18";
declare global {
namespace Cypress {
interface Chainable {
mount: typeof mount;
login(): Chainable<void>;
}
}
}
...@@ -26,8 +26,13 @@ ...@@ -26,8 +26,13 @@
// Import React Testing Library commands (select by a11y role etc) // Import React Testing Library commands (select by a11y role etc)
import "@testing-library/cypress/add-commands"; import "@testing-library/cypress/add-commands";
import { mount } from "cypress/react18";
// import custom auth commands // import custom auth commands
Cypress.Commands.add("login", () => { Cypress.Commands.add("login", () => {
cy.setCookie("ce-deploy-auth", "DEADBEEF"); cy.setCookie("ce-deploy-auth", "DEADBEEF");
}); });
Cypress.Commands.add("mount", (component, options) => {
return mount(component, options);
});
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
// Import commands.js using ES2015 syntax: // Import commands.js using ES2015 syntax:
import "./commands"; import "./commands";
import { ReduxProvider } from "../../src/store/ReduxProvider";
// Alternatively you can use CommonJS syntax: // Alternatively you can use CommonJS syntax:
// require("./commands") // require("./commands")
...@@ -23,8 +22,9 @@ import { ReduxProvider } from "../../src/store/ReduxProvider"; ...@@ -23,8 +22,9 @@ import { ReduxProvider } from "../../src/store/ReduxProvider";
import { mount } from "cypress/react"; import { mount } from "cypress/react";
import { interceptAPI } from "./interceptAPI"; import { interceptAPI } from "./interceptAPI";
import configure from "./configureWindowVars"; import configure from "./configureWindowVars";
Cypress.Commands.add("mount", (component, options = {}) => { import { ReduxProvider } from "../../src/store/ReduxProvider";
Cypress.Commands.add("mount", (component, options = {}) => {
const wrappedComponent = <ReduxProvider>{component}</ReduxProvider>; const wrappedComponent = <ReduxProvider>{component}</ReduxProvider>;
return mount(wrappedComponent, options); return mount(wrappedComponent, options);
}); });
......
import { useContext } from "react"; import { useContext } from "react";
import { userContext } from "@ess-ics/ce-ui-common"; import { userContext } from "@ess-ics/ce-ui-common";
import { SnackbarProvider } from "notistack"; import { SnackbarProvider } from "notistack";
import { DeployAPIProvider } from "./APIProvider";
import { UserProvider } from "./UserProvider"; import { UserProvider } from "./UserProvider";
function AppHarness({ children }) {
return (
<SnackbarProvider
preventDuplicate
maxSnack="5"
>
<DeployAPIProvider>{children}</DeployAPIProvider>
</SnackbarProvider>
);
}
function mountIntoHarness(children) {
cy.mount(<AppHarness>{children}</AppHarness>);
}
function DisplayUserContextValue() { function DisplayUserContextValue() {
const contextValue = useContext(userContext); const contextValue = useContext(userContext);
return <pre id="display">{JSON.stringify(contextValue, null, 2)}</pre>; return <pre id="display">{JSON.stringify(contextValue, null, 2)}</pre>;
} }
...@@ -32,10 +15,15 @@ describe("UserProvider", () => { ...@@ -32,10 +15,15 @@ describe("UserProvider", () => {
}); });
it("provides the user", () => { it("provides the user", () => {
mountIntoHarness( cy.mount(
<UserProvider> <SnackbarProvider
<DisplayUserContextValue /> preventDuplicate
</UserProvider> maxSnack={5}
>
<UserProvider>
<DisplayUserContextValue />
</UserProvider>
</SnackbarProvider>
); );
cy.wait("@getUserRoles"); cy.wait("@getUserRoles");
......
...@@ -45,7 +45,7 @@ describe("IOCTable", () => { ...@@ -45,7 +45,7 @@ describe("IOCTable", () => {
.should(($el) => { .should(($el) => {
const text = $el.text().trim().toLowerCase(); const text = $el.text().trim().toLowerCase();
const expected = firstRowData[index].trim().toLowerCase(); const expected = firstRowData[index].trim().toLowerCase();
cy.expect(text).to.equal(expected); expect(text).to.equal(expected);
}); });
} }
}); });
......
...@@ -45,7 +45,7 @@ describe("HostTable", () => { ...@@ -45,7 +45,7 @@ describe("HostTable", () => {
.should(($el) => { .should(($el) => {
const text = $el.text().trim().toLowerCase(); const text = $el.text().trim().toLowerCase();
const expected = firstRowData[index].trim().toLowerCase(); const expected = firstRowData[index].trim().toLowerCase();
cy.expect(text).to.equal(expected); expect(text).to.equal(expected);
}); });
} }
}); });
......
...@@ -20,8 +20,14 @@ ...@@ -20,8 +20,14 @@
"noUnusedParameters": true, "noUnusedParameters": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"types": ["@types/react", "@types/react-dom", "vite/client"] "types": [
"cypress",
"@testing-library/cypress",
"@types/react",
"@types/react-dom",
"vite/client"
]
}, },
"include": ["src"], "include": ["src", "cypress.d.ts"],
"exclude": ["node_modules", "build"] "exclude": ["node_modules", "build"]
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment