Login layout container cypress test (#136)

This commit is contained in:
Brandon Lee Kitajchuk
2022-10-18 08:45:44 -07:00
committed by GitHub
parent 874002386c
commit 2a6181615e
4 changed files with 65 additions and 5 deletions
+24
View File
@@ -0,0 +1,24 @@
import React from "react";
import { Layout } from "./layout";
import { LayoutProvider } from "src/test";
const LayoutTestWrapper = () => {
return (
<LayoutProvider Layout={Layout} outlet={<div className="outlet-div" />} />
);
};
describe("<Layout/>", () => {
it("mounts", () => {
cy.mount(<LayoutTestWrapper />);
});
it("has required elements", () => {
cy.mount(<LayoutTestWrapper />);
cy.get("header").should("exist");
cy.get("footer").should("exist");
cy.get(".outlet-div").should("exist");
});
});
+2
View File
@@ -4,6 +4,8 @@ import { MXS } from "jambonz-ui";
import { Icons } from "src/components";
import "./styles.scss";
export const Layout = () => (
<main className="login bg--dark">
<header>
-2
View File
@@ -11,8 +11,6 @@ import {
ROUTE_CREATE_PASSWORD,
} from "src/router/routes";
import "./styles.scss";
export const Login = () => {
const { signin, authorized } = useAuth();
const location = useLocation();
+39 -3
View File
@@ -9,9 +9,14 @@ import type { AuthStateContext } from "src/router/auth";
import userLogin from "../../cypress/fixtures/userLogin.json";
interface TestProviderProps extends Partial<AuthStateContext> {
children: React.ReactNode;
}
type TestProviderProps = Partial<AuthStateContext> & {
children?: React.ReactNode;
};
type LayoutProviderProps = TestProviderProps & {
outlet: JSX.Element;
Layout: React.ElementType;
};
export const signinError = () => Promise.reject(MSG_SOMETHING_WRONG);
export const signinSuccess = () => Promise.resolve(userLogin);
@@ -23,6 +28,9 @@ export const authProps: AuthStateContext = {
authorized: false,
};
/**
* Use this when you simply need to wrap with state and auth
*/
export const TestProvider = ({ children, ...restProps }: TestProviderProps) => {
return (
<StateProvider>
@@ -41,3 +49,31 @@ export const TestProvider = ({ children, ...restProps }: TestProviderProps) => {
</StateProvider>
);
};
/**
* Use this when you also need to test the react-router-dom layouts
*/
export const LayoutProvider = ({
Layout,
outlet,
...restProps
}: LayoutProviderProps) => {
return (
<StateProvider>
<AuthContext.Provider
value={{
...authProps,
...restProps,
}}
>
<BrowserRouter>
<Routes>
<Route path="*" element={<Layout />}>
<Route path="*" element={outlet} />
</Route>
</Routes>
</BrowserRouter>
</AuthContext.Provider>
</StateProvider>
);
};