Skip to content

Commit

Permalink
chore(frontend):add tests and refacto components
Browse files Browse the repository at this point in the history
  • Loading branch information
Thibaut-Mouton committed Jul 3, 2024
1 parent 0d0bafc commit 024cdce
Show file tree
Hide file tree
Showing 18 changed files with 280 additions and 211 deletions.
1 change: 1 addition & 0 deletions frontend-web/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
"env": {
"node": true,
"browser": true,
"es2021": true
},
Expand Down
3 changes: 2 additions & 1 deletion frontend-web/.npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
8.19.2
engine-strict=true
registry=https://registry.npmjs.org/
21 changes: 16 additions & 5 deletions frontend-web/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
/** @type {import('jest').Config} */
const config = {
testEnvironment: "jsdom",
coveragePathIgnorePatterns: [
"/node_modules/",
"/coverage",
"package.json",
"package-lock.json",
"reportWebVitals.ts",
"setupTests.ts",
"index.tsx"
],
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
}

module.exports = config
1 change: 1 addition & 0 deletions frontend-web/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "@testing-library/jest-dom"
20 changes: 14 additions & 6 deletions frontend-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
"name": "Thibaut MOUTON",
"email": "[email protected]"
},
"engines": {
"node": ">= 20",
"npm": ">= 8.0.0"
},
"scripts": {
"start": "react-scripts start",
"start:test": "tsc && set PORT=8080 && react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test": "react-scripts test --watchAll=false",
"lint": "eslint -c .eslintrc.json --ext .ts,.tsx .",
"lint:fix": "npm run lint -- --fix",
"eject": "react-scripts eject"
Expand All @@ -19,8 +23,8 @@
"@emotion/react": "11.11.4",
"@emotion/styled": "11.11.5",
"@mui/icons-material": "5.15.20",
"@mui/lab": "^5.0.0-alpha.170",
"@mui/material": "5.15.20",
"@mui/lab": "5.0.0-alpha.170",
"@mui/material": "5.15.21",
"@stomp/stompjs": "7.0.0",
"axios": "1.6.8",
"history": "5.3.0",
Expand All @@ -32,15 +36,19 @@
"react-scripts": "5.0.1",
"react-toastify": "10.0.5",
"sockjs-client": "1.6.1",
"ts-jest": "29.1.5",
"typescript": "4.7.4"
},
"eslintConfig": {
"extends": "react-app"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/react": "18.2.74",
"@types/react-dom": "18.2.24",
"@testing-library/dom": "10.3.0",
"@testing-library/jest-dom": "6.4.6",
"@testing-library/react": "16.0.0",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"@types/jest": "29.5.12",
"@typescript-eslint/eslint-plugin": "7.5.0",
"@typescript-eslint/parser": "7.5.0",
"eslint-plugin-react": "7.34.1"
Expand Down
46 changes: 0 additions & 46 deletions frontend-web/src/components/home.tsx

This file was deleted.

8 changes: 2 additions & 6 deletions frontend-web/src/components/login/LoginComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Button, Grid, TextField, Typography} from "@mui/material"
import React, {useContext, useEffect, useState} from "react"
import React, {useContext, useState} from "react"
import {Link, useNavigate} from "react-router-dom"
import {useThemeContext} from "../../context/theme-context"
import {generateLinkColorMode} from "../utils/enable-dark-mode"
Expand All @@ -21,10 +21,6 @@ export function LoginComponent(): React.JSX.Element {
const {theme} = useThemeContext()
const httpService = new HttpGroupService()

useEffect(() => {
document.title = "Login | FLM"
}, [])

function handleChange(e: any) {
e.preventDefault()
switch (e.target.name) {
Expand Down Expand Up @@ -135,7 +131,7 @@ export function LoginComponent(): React.JSX.Element {
<Grid container justifyContent={"space-between"}>
<Link className={"lnk"}
style={{color: generateLinkColorMode(theme)}}
to={"/forgetpassword"}>
to={"/reset/password"}>
Forgot your password ?
</Link>
<Link className={"lnk"}
Expand Down
16 changes: 16 additions & 0 deletions frontend-web/src/components/login/LoginWrapperComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, {useEffect} from "react"
import {WelcomeComponent} from "../welcome/WelcomeComponent"
import {LoginComponent} from "./LoginComponent"

export function LoginWrapperComponent(): React.JSX.Element {

useEffect(() => {
document.title = "Login | FLM"
}, [])

return <>
<WelcomeComponent>
<LoginComponent/>
</WelcomeComponent>
</>
}
10 changes: 10 additions & 0 deletions frontend-web/src/components/partials/FooterComponent.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react"
import {render, screen} from "@testing-library/react"
import {FooterComponent} from "./FooterComponent"

describe(FooterComponent.name, () => {
test("should render footer component", () => {
render(<FooterComponent/>)
expect(screen.getByTestId("footer-title").textContent).toEqual("FastLiteMessage - Open source software")
})
})
27 changes: 27 additions & 0 deletions frontend-web/src/components/partials/FooterComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {Box, Typography} from "@mui/material"
import React from "react"
import {useThemeContext} from "../../context/theme-context"
import {generateColorMode} from "../utils/enable-dark-mode"

export function FooterComponent(): React.JSX.Element {
const {theme} = useThemeContext()

return (
<Box mt={5} display="flex" flexDirection={"column"}>
<Typography variant="body2" color="inherit" align="center">
<a className={"clrcstm lnk" + generateColorMode(theme)} target={"_blank"} data-testid="footer-title"
href={"https://github.com/Thibaut-Mouton/react-spring-messenger-project"} rel="noreferrer">
FastLiteMessage - Open source software
</a>
{" | "}
{new Date().getFullYear()}
</Typography>
<Typography variant="caption" color="inherit" align="center">
<a role={"gcu"} className={"clrcstm lnk" + generateColorMode(theme)} target={"_blank"}
href={"#"} rel="noreferrer">
GCU
</a>
</Typography>
</Box>
)
}
21 changes: 0 additions & 21 deletions frontend-web/src/components/partials/footer-component.tsx

This file was deleted.

Loading

0 comments on commit 024cdce

Please sign in to comment.