From 16e11d103b14b9256aafab9d2ccc30e38b38cc6c Mon Sep 17 00:00:00 2001 From: FranciscoCardoso913 Date: Tue, 29 Aug 2023 12:42:45 +0100 Subject: [PATCH] Making tests for the validate application and the fetch company application services --- .../ApplicationsReviewWidget.spec.js | 4 +-- src/components/utils/Alert.js | 36 ++++++++++--------- src/pages/ValidationPage.js | 27 +++++++------- src/pages/ValidationPage.spec.js | 29 ++++++++------- 4 files changed, 51 insertions(+), 45 deletions(-) diff --git a/src/components/Review/Applications/ApplicationsReviewWidget.spec.js b/src/components/Review/Applications/ApplicationsReviewWidget.spec.js index d42b5a07..67d50630 100644 --- a/src/components/Review/Applications/ApplicationsReviewWidget.spec.js +++ b/src/components/Review/Applications/ApplicationsReviewWidget.spec.js @@ -286,10 +286,10 @@ describe("Application Review Widget", () => { , { initialState: {}, theme }) ); - + expect(screen.queryByLabelText("Approve Application")).not.toBeInTheDocument(); expect(screen.queryByLabelText("Reject Application")).not.toBeInTheDocument(); - }) + }); it("Should maintain state filter after rejecting an application", async () => { const applications = generateApplications(1, "PENDING"); diff --git a/src/components/utils/Alert.js b/src/components/utils/Alert.js index 76bbcbbe..5f4adf34 100644 --- a/src/components/utils/Alert.js +++ b/src/components/utils/Alert.js @@ -1,33 +1,37 @@ -import {Alert as MUI_Alert, AlertTitle} from "@material-ui/lab"; -import {makeStyles} from "@material-ui/core"; + +import { Alert as MUIAlert, AlertTitle } from "@material-ui/lab"; +import { makeStyles } from "@material-ui/core"; import PropTypes from "prop-types"; import { Warning as WarningIcon } from "@material-ui/icons"; -import React from 'react'; +import React from "react"; -const useStyles = (props) => makeStyles((theme) => ({ +const useStyles = (props) => makeStyles(() => ({ - content:{ - fontSize: props.fontSize+"em", + content: { + fontSize: `${props.fontSize}em`, "& .MuiAlert-icon": { - fontSize: (props.fontSize+0.3)+"em" + fontSize: `${props.fontSize + 0.3}em`, }, - margin:"0.5em 0em" + margin: "0.5em 0em", }, })); -export const Alert = ({type, title, fontSize = 1, children}) => { - const classes = useStyles({fontSize: fontSize})(); +export const Alert = ({ type, title, fontSize = 1, children }) => { + const classes = useStyles({ fontSize: fontSize })(); return ( - } data-testid="Alert"> - {title ? {title} : null} + } data-testid="Alert"> + {title ? + + {title} + : null} {children} - - ) -} + + ); +}; Alert.propTypes = { type: PropTypes.oneOf(["error", "warning", "info", "success"]), title: PropTypes.string, children: PropTypes.string, fontSize: PropTypes.number, -} +}; diff --git a/src/pages/ValidationPage.js b/src/pages/ValidationPage.js index bc70cfce..4c606a73 100644 --- a/src/pages/ValidationPage.js +++ b/src/pages/ValidationPage.js @@ -1,13 +1,10 @@ -/* eslint-disable react/jsx-indent */ -/* eslint-disable react/jsx-closing-tag-location */ -/* eslint-disable indent */ import React, { useEffect, useState } from "react"; -import {CardContent, CircularProgress, makeStyles, Button, Link, Typography} from "@material-ui/core"; +import { CardContent, CircularProgress, makeStyles, Button, Link, Typography } from "@material-ui/core"; import { useMobile } from "../utils/media-queries"; import { useParams } from "react-router-dom"; import { validateApplication } from "../services/companyApplicationService"; import { getValidationMessage } from "../components/Apply/Company/CompanyApplicationUtils.js"; -import {RouterLink} from "../utils"; +import { RouterLink } from "../utils"; const useStyles = (isMobile) => makeStyles((theme) => ({ content: { @@ -16,10 +13,10 @@ const useStyles = (isMobile) => makeStyles((theme) => ({ flexDirection: "column", alignItems: "center", justifyContent: "center", - gap:"1em", + gap: "1em", }, title: { - fontWeight:500, + fontWeight: 500, }, text: { fontSize: theme.typography.body1, @@ -29,10 +26,10 @@ const useStyles = (isMobile) => makeStyles((theme) => ({ }, button: { background: theme.palette.primary.main, - color:theme.palette.dark.contrastText, - '&:hover':{ + color: theme.palette.dark.contrastText, + "&:hover": { background: theme.palette.secondary.main, - } + }, }, @@ -48,7 +45,7 @@ const ValidationPage = () => { const [error, setError] = useState(""); - useEffect( () => { + useEffect(() => { async function validate() { try { setLoading(false); @@ -71,10 +68,10 @@ const ValidationPage = () => { const { title, text } = success ? successMessage : getValidationMessage(error); return ( - + {title} - - + + {text} {!success ? "For more information contact us at " : ""} nijobs@aefeup.pt @@ -97,7 +94,7 @@ const ValidationPage = () => { ); } else { - return getMessageCard(error); + return getMessageCard(error); } }; diff --git a/src/pages/ValidationPage.spec.js b/src/pages/ValidationPage.spec.js index 9681fb45..57e4f6cd 100644 --- a/src/pages/ValidationPage.spec.js +++ b/src/pages/ValidationPage.spec.js @@ -25,53 +25,58 @@ describe("Validation Page", () => { const page = await render( - + , ); - const {title, text} = getValidationMessage("success"); + const { title } = getValidationMessage("success"); expect(page.queryByText(title)).toBeInTheDocument(); }); it("Should show error message if token does not exist", async () => { - validateApplication.mockImplementation(() =>{ throw [{ msg: "invalid-token" }]}); + validateApplication.mockImplementation(() => { + throw [{ msg: "invalid-token" }]; + }); const page = await render( - + , ); - const {title, text} = getValidationMessage("invalid-token"); + const { title } = getValidationMessage("invalid-token"); expect(page.queryByText(title)).toBeInTheDocument(); }); it("Should show error message if token has expired", async () => { - validateApplication.mockImplementation(() =>{ throw [{ msg: "expired-token" }]}); + validateApplication.mockImplementation(() => { + throw [{ msg: "expired-token" }]; + }); const page = await render( - + , ); - const {title, text} = getValidationMessage("expired-token"); + const { title } = getValidationMessage("expired-token"); expect(page.queryByText(title)).toBeInTheDocument(); }); it("Should show error message if application is already validated", async () => { - validateApplication.mockImplementation(() =>{ throw [{ msg: "application-already-validated" }]}); + validateApplication.mockImplementation(() => { + throw [{ msg: "application-already-validated" }]; + }); const page = await render( - + , ); - const {title, text} = getValidationMessage("application-already-validated"); + const { title } = getValidationMessage("application-already-validated"); expect(page.queryByText(title)).toBeInTheDocument(); }); }); -