Update Upload form tests with mocked provider
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
jest.mock("../Contexts/UserContext");
|
jest.mock("../Contexts/UserContext");
|
||||||
|
jest.mock("../Contexts/FileUploadContext");
|
||||||
|
|
||||||
import { render, screen, cleanup, waitForElementToBeRemoved, waitFor } from "@testing-library/react"
|
import { render, screen, cleanup, waitForElementToBeRemoved, waitFor } from "@testing-library/react"
|
||||||
import { setToken } from "../Contexts/UserContext";
|
import { setToken } from "../Contexts/UserContext";
|
||||||
|
|||||||
@@ -16,65 +16,69 @@ exports[`App Route / authenticated 1`] = `
|
|||||||
>
|
>
|
||||||
Upload file
|
Upload file
|
||||||
</h1>
|
</h1>
|
||||||
<form
|
<div
|
||||||
class="makeStyles-form-27"
|
data-testid="mocked-fileuploadprovider"
|
||||||
novalidate=""
|
>
|
||||||
|
<form
|
||||||
|
class="makeStyles-form-27"
|
||||||
|
novalidate=""
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="MuiDropzoneArea-root"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
accept=""
|
||||||
|
autocomplete="off"
|
||||||
|
multiple=""
|
||||||
|
style="display: none;"
|
||||||
|
tabindex="-1"
|
||||||
|
type="file"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
class="MuiDropzoneArea-textContainer"
|
||||||
|
>
|
||||||
|
<p
|
||||||
|
class="MuiTypography-root MuiDropzoneArea-text MuiTypography-h5"
|
||||||
|
>
|
||||||
|
Drag and drop a file here or click
|
||||||
|
</p>
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
class="MuiSvgIcon-root MuiDropzoneArea-icon"
|
||||||
|
focusable="false"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM14 13v4h-4v-4H7l5-5 5 5h-3z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="MuiGrid-root MuiGrid-container"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="MuiDropzoneArea-root"
|
class="MuiGrid-root MuiGrid-item"
|
||||||
tabindex="0"
|
|
||||||
>
|
>
|
||||||
<input
|
<button
|
||||||
accept=""
|
class="MuiButtonBase-root MuiButton-root MuiButton-text"
|
||||||
autocomplete="off"
|
tabindex="0"
|
||||||
multiple=""
|
type="button"
|
||||||
style="display: none;"
|
|
||||||
tabindex="-1"
|
|
||||||
type="file"
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
class="MuiDropzoneArea-textContainer"
|
|
||||||
>
|
>
|
||||||
<p
|
<span
|
||||||
class="MuiTypography-root MuiDropzoneArea-text MuiTypography-h5"
|
class="MuiButton-label"
|
||||||
>
|
>
|
||||||
Drag and drop a file here or click
|
Sign Out
|
||||||
</p>
|
</span>
|
||||||
<svg
|
<span
|
||||||
aria-hidden="true"
|
class="MuiTouchRipple-root"
|
||||||
class="MuiSvgIcon-root MuiDropzoneArea-icon"
|
/>
|
||||||
focusable="false"
|
</button>
|
||||||
viewBox="0 0 24 24"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
d="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM14 13v4h-4v-4H7l5-5 5 5h-3z"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div
|
</div>
|
||||||
class="MuiGrid-root MuiGrid-container"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="MuiGrid-root MuiGrid-item"
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
class="MuiButtonBase-root MuiButton-root MuiButton-text"
|
|
||||||
tabindex="0"
|
|
||||||
type="button"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
class="MuiButton-label"
|
|
||||||
>
|
|
||||||
Sign Out
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
class="MuiTouchRipple-root"
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
@@ -245,65 +249,69 @@ exports[`App Route /home authenticated 1`] = `
|
|||||||
>
|
>
|
||||||
Upload file
|
Upload file
|
||||||
</h1>
|
</h1>
|
||||||
<form
|
<div
|
||||||
class="makeStyles-form-35"
|
data-testid="mocked-fileuploadprovider"
|
||||||
novalidate=""
|
>
|
||||||
|
<form
|
||||||
|
class="makeStyles-form-35"
|
||||||
|
novalidate=""
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="MuiDropzoneArea-root"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
accept=""
|
||||||
|
autocomplete="off"
|
||||||
|
multiple=""
|
||||||
|
style="display: none;"
|
||||||
|
tabindex="-1"
|
||||||
|
type="file"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
class="MuiDropzoneArea-textContainer"
|
||||||
|
>
|
||||||
|
<p
|
||||||
|
class="MuiTypography-root MuiDropzoneArea-text MuiTypography-h5"
|
||||||
|
>
|
||||||
|
Drag and drop a file here or click
|
||||||
|
</p>
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
class="MuiSvgIcon-root MuiDropzoneArea-icon"
|
||||||
|
focusable="false"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM14 13v4h-4v-4H7l5-5 5 5h-3z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="MuiGrid-root MuiGrid-container"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="MuiDropzoneArea-root"
|
class="MuiGrid-root MuiGrid-item"
|
||||||
tabindex="0"
|
|
||||||
>
|
>
|
||||||
<input
|
<button
|
||||||
accept=""
|
class="MuiButtonBase-root MuiButton-root MuiButton-text"
|
||||||
autocomplete="off"
|
tabindex="0"
|
||||||
multiple=""
|
type="button"
|
||||||
style="display: none;"
|
|
||||||
tabindex="-1"
|
|
||||||
type="file"
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
class="MuiDropzoneArea-textContainer"
|
|
||||||
>
|
>
|
||||||
<p
|
<span
|
||||||
class="MuiTypography-root MuiDropzoneArea-text MuiTypography-h5"
|
class="MuiButton-label"
|
||||||
>
|
>
|
||||||
Drag and drop a file here or click
|
Sign Out
|
||||||
</p>
|
</span>
|
||||||
<svg
|
<span
|
||||||
aria-hidden="true"
|
class="MuiTouchRipple-root"
|
||||||
class="MuiSvgIcon-root MuiDropzoneArea-icon"
|
/>
|
||||||
focusable="false"
|
</button>
|
||||||
viewBox="0 0 24 24"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
d="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM14 13v4h-4v-4H7l5-5 5 5h-3z"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div
|
</div>
|
||||||
class="MuiGrid-root MuiGrid-container"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="MuiGrid-root MuiGrid-item"
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
class="MuiButtonBase-root MuiButton-root MuiButton-text"
|
|
||||||
tabindex="0"
|
|
||||||
type="button"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
class="MuiButton-label"
|
|
||||||
>
|
|
||||||
Sign Out
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
class="MuiTouchRipple-root"
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
@@ -474,65 +482,69 @@ exports[`App Route /signup authenticated 1`] = `
|
|||||||
>
|
>
|
||||||
Upload file
|
Upload file
|
||||||
</h1>
|
</h1>
|
||||||
<form
|
<div
|
||||||
class="makeStyles-form-31"
|
data-testid="mocked-fileuploadprovider"
|
||||||
novalidate=""
|
>
|
||||||
|
<form
|
||||||
|
class="makeStyles-form-31"
|
||||||
|
novalidate=""
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="MuiDropzoneArea-root"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
accept=""
|
||||||
|
autocomplete="off"
|
||||||
|
multiple=""
|
||||||
|
style="display: none;"
|
||||||
|
tabindex="-1"
|
||||||
|
type="file"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
class="MuiDropzoneArea-textContainer"
|
||||||
|
>
|
||||||
|
<p
|
||||||
|
class="MuiTypography-root MuiDropzoneArea-text MuiTypography-h5"
|
||||||
|
>
|
||||||
|
Drag and drop a file here or click
|
||||||
|
</p>
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
class="MuiSvgIcon-root MuiDropzoneArea-icon"
|
||||||
|
focusable="false"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM14 13v4h-4v-4H7l5-5 5 5h-3z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="MuiGrid-root MuiGrid-container"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="MuiDropzoneArea-root"
|
class="MuiGrid-root MuiGrid-item"
|
||||||
tabindex="0"
|
|
||||||
>
|
>
|
||||||
<input
|
<button
|
||||||
accept=""
|
class="MuiButtonBase-root MuiButton-root MuiButton-text"
|
||||||
autocomplete="off"
|
tabindex="0"
|
||||||
multiple=""
|
type="button"
|
||||||
style="display: none;"
|
|
||||||
tabindex="-1"
|
|
||||||
type="file"
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
class="MuiDropzoneArea-textContainer"
|
|
||||||
>
|
>
|
||||||
<p
|
<span
|
||||||
class="MuiTypography-root MuiDropzoneArea-text MuiTypography-h5"
|
class="MuiButton-label"
|
||||||
>
|
>
|
||||||
Drag and drop a file here or click
|
Sign Out
|
||||||
</p>
|
</span>
|
||||||
<svg
|
<span
|
||||||
aria-hidden="true"
|
class="MuiTouchRipple-root"
|
||||||
class="MuiSvgIcon-root MuiDropzoneArea-icon"
|
/>
|
||||||
focusable="false"
|
</button>
|
||||||
viewBox="0 0 24 24"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
d="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM14 13v4h-4v-4H7l5-5 5 5h-3z"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div
|
</div>
|
||||||
class="MuiGrid-root MuiGrid-container"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="MuiGrid-root MuiGrid-item"
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
class="MuiButtonBase-root MuiButton-root MuiButton-text"
|
|
||||||
tabindex="0"
|
|
||||||
type="button"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
class="MuiButton-label"
|
|
||||||
>
|
|
||||||
Sign Out
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
class="MuiTouchRipple-root"
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const SiteRoutes = () => {
|
|||||||
<Switch>
|
<Switch>
|
||||||
<AuthRoute path="/" exact render={() => <SignInForm />} type={TYPES.GUEST} token={token} />
|
<AuthRoute path="/" exact render={() => <SignInForm />} type={TYPES.GUEST} token={token} />
|
||||||
<AuthRoute path="/signup" exact render={() => <SignUpForm />} 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>
|
</Switch>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
</Suspense>
|
</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