mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-09-11 22:06:29 +02:00
Fix tests & improve pre-register
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
import { render } from "@testing-library/react"
|
||||
import { MemoryRouter } from "react-router-dom"
|
||||
|
||||
import { fetchJeuJavListIfNeed } from "../../../store/jeuJavList"
|
||||
import mockStore from "../../../utils/mockStore"
|
||||
import Home from "../Home"
|
||||
|
||||
describe("<Home />", () => {
|
||||
const renderHelper = (reducer = { readyStatus: "idle" }) => {
|
||||
const { dispatch, ProviderWithStore } = mockStore({ jeuJavList: reducer })
|
||||
const { container } = render(
|
||||
<ProviderWithStore>
|
||||
<MemoryRouter>
|
||||
{/*
|
||||
@ts-expect-error */}
|
||||
<Home />
|
||||
</MemoryRouter>
|
||||
</ProviderWithStore>
|
||||
)
|
||||
|
||||
return { dispatch, firstChild: container.firstChild }
|
||||
}
|
||||
|
||||
it("should fetch data when page loaded", () => {
|
||||
const { dispatch } = renderHelper()
|
||||
|
||||
expect(dispatch).toHaveBeenCalledTimes(1)
|
||||
expect(dispatch.mock.calls[0][0].toString()).toBe(fetchJeuJavListIfNeed().toString())
|
||||
})
|
||||
|
||||
it("renders the loading status if data invalid", () => {
|
||||
expect(renderHelper().firstChild).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it("renders the loading status if requesting data", () => {
|
||||
const reducer = { readyStatus: "request" }
|
||||
|
||||
expect(renderHelper(reducer).firstChild).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it("renders an error if loading failed", () => {
|
||||
const reducer = { readyStatus: "failure" }
|
||||
|
||||
expect(renderHelper(reducer).firstChild).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it("renders the <List /> if loading was successful", () => {
|
||||
const reducer = {
|
||||
readyStatus: "success",
|
||||
ids: [5],
|
||||
entities: {
|
||||
"5": {
|
||||
id: 5,
|
||||
titre: "6 qui prend!",
|
||||
auteur: "Wolfgang Kramer",
|
||||
editeur: "(uncredited) , Design Edge , B",
|
||||
minJoueurs: 2,
|
||||
maxJoueurs: 10,
|
||||
duree: 45,
|
||||
type: "Ambiance",
|
||||
poufpaf: "0-9-2/6-qui-prend-6-nimmt",
|
||||
photo: "https://cf.geekdo-images.com/thumb/img/lzczxR5cw7an7tRWeHdOrRtLyes=/fit-in/200x150/pic772547.jpg",
|
||||
bggPhoto: "",
|
||||
bggId: 432,
|
||||
exemplaires: 1,
|
||||
dispoPret: 1,
|
||||
nonRangee: 0,
|
||||
horodatage: "0000-00-00",
|
||||
ean: "3421272101313",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expect(renderHelper(reducer).firstChild).toMatchSnapshot()
|
||||
})
|
||||
})
|
@@ -1,313 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`<Home /> renders an error if loading failed 1`] = `
|
||||
<div
|
||||
class="home"
|
||||
>
|
||||
<section
|
||||
class="EnvieList"
|
||||
>
|
||||
<h2>
|
||||
Ajouter une nouvelle envie
|
||||
</h2>
|
||||
<form>
|
||||
<label
|
||||
for="postDomaine"
|
||||
>
|
||||
Domaine:
|
||||
<input
|
||||
id="postDomaine"
|
||||
name="postDomaine"
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postEnvies"
|
||||
>
|
||||
Envies:
|
||||
<textarea
|
||||
id="postEnvies"
|
||||
name="postEnvies"
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postPrecisions"
|
||||
>
|
||||
Precisions:
|
||||
<textarea
|
||||
id="postPrecisions"
|
||||
name="postPrecisions"
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postEquipes"
|
||||
>
|
||||
Equipes:
|
||||
<input
|
||||
id="postEquipes"
|
||||
name="postEquipes"
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postDateAjout"
|
||||
>
|
||||
DateAjout:
|
||||
<input
|
||||
id="postDateAjout"
|
||||
name="postDateAjout"
|
||||
type="date"
|
||||
value=""
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
>
|
||||
Save Post
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
<p>
|
||||
Oops, Failed to load list!
|
||||
</p>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<Home /> renders the <List /> if loading was successful 1`] = `
|
||||
<div
|
||||
class="home"
|
||||
>
|
||||
<section
|
||||
class="EnvieList"
|
||||
>
|
||||
<h2>
|
||||
Ajouter une nouvelle envie
|
||||
</h2>
|
||||
<form>
|
||||
<label
|
||||
for="postDomaine"
|
||||
>
|
||||
Domaine:
|
||||
<input
|
||||
id="postDomaine"
|
||||
name="postDomaine"
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postEnvies"
|
||||
>
|
||||
Envies:
|
||||
<textarea
|
||||
id="postEnvies"
|
||||
name="postEnvies"
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postPrecisions"
|
||||
>
|
||||
Precisions:
|
||||
<textarea
|
||||
id="postPrecisions"
|
||||
name="postPrecisions"
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postEquipes"
|
||||
>
|
||||
Equipes:
|
||||
<input
|
||||
id="postEquipes"
|
||||
name="postEquipes"
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postDateAjout"
|
||||
>
|
||||
DateAjout:
|
||||
<input
|
||||
id="postDateAjout"
|
||||
name="postDateAjout"
|
||||
type="date"
|
||||
value=""
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
>
|
||||
Save Post
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
<div
|
||||
class="JeuJavList"
|
||||
>
|
||||
<h4>
|
||||
Jeux JAV
|
||||
</h4>
|
||||
<ul>
|
||||
<li>
|
||||
6 qui prend!
|
||||
- [
|
||||
432
|
||||
]
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<Home /> renders the loading status if data invalid 1`] = `
|
||||
<div
|
||||
class="home"
|
||||
>
|
||||
<section
|
||||
class="EnvieList"
|
||||
>
|
||||
<h2>
|
||||
Ajouter une nouvelle envie
|
||||
</h2>
|
||||
<form>
|
||||
<label
|
||||
for="postDomaine"
|
||||
>
|
||||
Domaine:
|
||||
<input
|
||||
id="postDomaine"
|
||||
name="postDomaine"
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postEnvies"
|
||||
>
|
||||
Envies:
|
||||
<textarea
|
||||
id="postEnvies"
|
||||
name="postEnvies"
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postPrecisions"
|
||||
>
|
||||
Precisions:
|
||||
<textarea
|
||||
id="postPrecisions"
|
||||
name="postPrecisions"
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postEquipes"
|
||||
>
|
||||
Equipes:
|
||||
<input
|
||||
id="postEquipes"
|
||||
name="postEquipes"
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postDateAjout"
|
||||
>
|
||||
DateAjout:
|
||||
<input
|
||||
id="postDateAjout"
|
||||
name="postDateAjout"
|
||||
type="date"
|
||||
value=""
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
>
|
||||
Save Post
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
<p>
|
||||
Loading...
|
||||
</p>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<Home /> renders the loading status if requesting data 1`] = `
|
||||
<div
|
||||
class="home"
|
||||
>
|
||||
<section
|
||||
class="EnvieList"
|
||||
>
|
||||
<h2>
|
||||
Ajouter une nouvelle envie
|
||||
</h2>
|
||||
<form>
|
||||
<label
|
||||
for="postDomaine"
|
||||
>
|
||||
Domaine:
|
||||
<input
|
||||
id="postDomaine"
|
||||
name="postDomaine"
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postEnvies"
|
||||
>
|
||||
Envies:
|
||||
<textarea
|
||||
id="postEnvies"
|
||||
name="postEnvies"
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postPrecisions"
|
||||
>
|
||||
Precisions:
|
||||
<textarea
|
||||
id="postPrecisions"
|
||||
name="postPrecisions"
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postEquipes"
|
||||
>
|
||||
Equipes:
|
||||
<input
|
||||
id="postEquipes"
|
||||
name="postEquipes"
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postDateAjout"
|
||||
>
|
||||
DateAjout:
|
||||
<input
|
||||
id="postDateAjout"
|
||||
name="postDateAjout"
|
||||
type="date"
|
||||
value=""
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
>
|
||||
Save Post
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
<p>
|
||||
Loading...
|
||||
</p>
|
||||
</div>
|
||||
`;
|
@@ -1,72 +0,0 @@
|
||||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
import { render } from "@testing-library/react"
|
||||
import { MemoryRouter } from "react-router-dom"
|
||||
|
||||
import { fetchMembreIfNeed } from "../../../store/membre"
|
||||
import mockStore from "../../../utils/mockStore"
|
||||
import MembrePage from "../MembrePage"
|
||||
|
||||
describe("<MembrePage />", () => {
|
||||
const mockData = {
|
||||
id: 1,
|
||||
nom: "Aupeix",
|
||||
prenom: "Amélie",
|
||||
mail: "pakouille.lakouille@yahoo.fr",
|
||||
telephone: "0675650392",
|
||||
photo: "images/membres/$taille/amélie_aupeix.jpg",
|
||||
alimentation: "Végétarien",
|
||||
majeur: 1,
|
||||
privilege: 0,
|
||||
actif: 0,
|
||||
commentaire: "",
|
||||
horodatage: "0000-00-00",
|
||||
passe: "$2y$10$fSxY9AIuxSiEjwF.J3eXGubIxUPlobkyRrNIal8ASimSjNj4SR.9O",
|
||||
}
|
||||
const { id } = mockData
|
||||
|
||||
const renderHelper = (reducer = {}) => {
|
||||
const { dispatch, ProviderWithStore } = mockStore({ membre: reducer })
|
||||
const { container } = render(
|
||||
<ProviderWithStore>
|
||||
<MemoryRouter>
|
||||
{/*
|
||||
@ts-expect-error */}
|
||||
<MembrePage match={{ params: { id } }} />
|
||||
</MemoryRouter>
|
||||
</ProviderWithStore>
|
||||
)
|
||||
|
||||
return { dispatch, firstChild: container.firstChild }
|
||||
}
|
||||
|
||||
it("should fetch data when page loaded", () => {
|
||||
const { dispatch } = renderHelper()
|
||||
|
||||
expect(dispatch).toHaveBeenCalledTimes(1)
|
||||
expect(dispatch.mock.calls[0][0].toString()).toBe(fetchMembreIfNeed(id).toString())
|
||||
})
|
||||
|
||||
it("renders the loading status if data invalid", () => {
|
||||
expect(renderHelper().firstChild).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it("renders the loading status if requesting data", () => {
|
||||
const reducer = { readyStatus: "request" }
|
||||
|
||||
expect(renderHelper(reducer).firstChild).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it("renders an error if loading failed", () => {
|
||||
const reducer = { readyStatus: "failure" }
|
||||
|
||||
expect(renderHelper(reducer).firstChild).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it("renders the <Info /> if loading was successful", () => {
|
||||
const reducer = { readyStatus: "success", entity: mockData }
|
||||
|
||||
expect(renderHelper(reducer).firstChild).toMatchSnapshot()
|
||||
})
|
||||
})
|
@@ -1,104 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`<MembrePage /> renders an error if loading failed 1`] = `
|
||||
<div
|
||||
class="membre"
|
||||
>
|
||||
<p>
|
||||
Oops! Failed to load data.
|
||||
</p>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<MembrePage /> renders the <Info /> if loading was successful 1`] = `
|
||||
<div
|
||||
class="membre"
|
||||
>
|
||||
<div>
|
||||
<div
|
||||
class="MembreCard"
|
||||
>
|
||||
<h4>
|
||||
Membre Info
|
||||
</h4>
|
||||
<ul>
|
||||
<li>
|
||||
Prénom:
|
||||
Amélie
|
||||
</li>
|
||||
<li>
|
||||
Nom:
|
||||
Aupeix
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<section
|
||||
class="MembreList"
|
||||
>
|
||||
<h2>
|
||||
Modifier un membre
|
||||
</h2>
|
||||
<form>
|
||||
<label
|
||||
for="postPrenom"
|
||||
>
|
||||
Prenom:
|
||||
<input
|
||||
id="postPrenom"
|
||||
name="postPrenom"
|
||||
type="text"
|
||||
value="Amélie"
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postNom"
|
||||
>
|
||||
Nom:
|
||||
<input
|
||||
id="postNom"
|
||||
name="postNom"
|
||||
type="text"
|
||||
value="Aupeix"
|
||||
/>
|
||||
</label>
|
||||
<label
|
||||
for="postMajeur"
|
||||
>
|
||||
Majeur:
|
||||
<input
|
||||
id="postMajeur"
|
||||
name="postMajeur"
|
||||
type="text"
|
||||
value="1"
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
>
|
||||
Save changes
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<MembrePage /> renders the loading status if data invalid 1`] = `
|
||||
<div
|
||||
class="membre"
|
||||
>
|
||||
<p>
|
||||
Oops! Failed to load data.
|
||||
</p>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<MembrePage /> renders the loading status if requesting data 1`] = `
|
||||
<div
|
||||
class="membre"
|
||||
>
|
||||
<p>
|
||||
Loading...
|
||||
</p>
|
||||
</div>
|
||||
`;
|
@@ -1,18 +1,22 @@
|
||||
import { RouteComponentProps } from "react-router-dom"
|
||||
import React, { memo } from "react"
|
||||
import { useDispatch } from "react-redux"
|
||||
import { FC, memo } from "react"
|
||||
import { Helmet } from "react-helmet"
|
||||
import styles from "./styles.module.scss"
|
||||
import RegisterForm from "../../components/RegisterForm/RegisterForm"
|
||||
|
||||
export type Props = RouteComponentProps
|
||||
|
||||
const RegisterPage: React.FC<Props> = (): JSX.Element => (
|
||||
<div className={styles.registerPage}>
|
||||
<div className={styles.registerContent}>
|
||||
<Helmet title="RegisterPage" />
|
||||
<RegisterForm />
|
||||
const RegisterPage: FC<Props> = (): JSX.Element => {
|
||||
const dispatch = useDispatch()
|
||||
return (
|
||||
<div className={styles.registerPage}>
|
||||
<div className={styles.registerContent}>
|
||||
<Helmet title="RegisterPage" />
|
||||
<RegisterForm dispatch={dispatch} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
export default memo(RegisterPage)
|
||||
|
Reference in New Issue
Block a user