mirror of
https://github.com/jambonz/jambonz-webapp.git
synced 2026-11-09 04:48:45 +00:00
Login layout container cypress test (#136)
This commit is contained in:
1 parent
874002386c
commit
2a6181615e
4 files changed
+65
-5
No files matched your search
+39
-3
@@ -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>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user