Update Upload form tests with mocked provider
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
jest.mock("../Contexts/UserContext");
|
||||
jest.mock("../Contexts/FileUploadContext");
|
||||
|
||||
import { render, screen, cleanup, waitForElementToBeRemoved, waitFor } from "@testing-library/react"
|
||||
import { setToken } from "../Contexts/UserContext";
|
||||
|
||||
@@ -16,6 +16,9 @@ exports[`App Route / authenticated 1`] = `
|
||||
>
|
||||
Upload file
|
||||
</h1>
|
||||
<div
|
||||
data-testid="mocked-fileuploadprovider"
|
||||
>
|
||||
<form
|
||||
class="makeStyles-form-27"
|
||||
novalidate=""
|
||||
@@ -52,6 +55,8 @@ exports[`App Route / authenticated 1`] = `
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div
|
||||
class="MuiGrid-root MuiGrid-container"
|
||||
>
|
||||
@@ -74,7 +79,6 @@ exports[`App Route / authenticated 1`] = `
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
@@ -245,6 +249,9 @@ exports[`App Route /home authenticated 1`] = `
|
||||
>
|
||||
Upload file
|
||||
</h1>
|
||||
<div
|
||||
data-testid="mocked-fileuploadprovider"
|
||||
>
|
||||
<form
|
||||
class="makeStyles-form-35"
|
||||
novalidate=""
|
||||
@@ -281,6 +288,8 @@ exports[`App Route /home authenticated 1`] = `
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div
|
||||
class="MuiGrid-root MuiGrid-container"
|
||||
>
|
||||
@@ -303,7 +312,6 @@ exports[`App Route /home authenticated 1`] = `
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
@@ -474,6 +482,9 @@ exports[`App Route /signup authenticated 1`] = `
|
||||
>
|
||||
Upload file
|
||||
</h1>
|
||||
<div
|
||||
data-testid="mocked-fileuploadprovider"
|
||||
>
|
||||
<form
|
||||
class="makeStyles-form-31"
|
||||
novalidate=""
|
||||
@@ -510,6 +521,8 @@ exports[`App Route /signup authenticated 1`] = `
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div
|
||||
class="MuiGrid-root MuiGrid-container"
|
||||
>
|
||||
@@ -532,7 +545,6 @@ exports[`App Route /signup authenticated 1`] = `
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@@ -21,7 +21,7 @@ const SiteRoutes = () => {
|
||||
<Switch>
|
||||
<AuthRoute path="/" exact render={() => <SignInForm />} type={TYPES.GUEST} token={token} />
|
||||
<AuthRoute path="/signup" exact render={() => <SignUpForm />} type={TYPES.GUEST} token={token} />
|
||||
<AuthRoute path="/home" render={() => <FileUploadForm />} type={TYPES.PUBLIC} token={token} />
|
||||
<AuthRoute path="/home" render={() => <FileUploadForm />} type={TYPES.PROTECTED} token={token} />
|
||||
</Switch>
|
||||
</BrowserRouter>
|
||||
</Suspense>
|
||||
|
||||
21
src/components/contexts/__mocks__/FileUploadContext.jsx
Normal file
21
src/components/contexts/__mocks__/FileUploadContext.jsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from "react";
|
||||
|
||||
let uploading = false;
|
||||
let progress = 0;
|
||||
let status = null;
|
||||
|
||||
export const FileUploadProvider = ({ children }) => {
|
||||
return (
|
||||
<div data-testid="mocked-fileuploadprovider">
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const useFileUploadContext = () => ({
|
||||
uploading,
|
||||
progress,
|
||||
status,
|
||||
upload: jest.fn(),
|
||||
cancel: jest.fn(),
|
||||
});
|
||||
Reference in New Issue
Block a user