Skip to content

Commit

Permalink
Making tests for the validate application and the fetch company appli…
Browse files Browse the repository at this point in the history
…cation services
  • Loading branch information
FranciscoCardoso913 committed Aug 29, 2023
1 parent 598c567 commit 16e11d1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ describe("Application Review Widget", () => {
</SnackbarProvider>
</MuiPickersUtilsProvider>, { 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");
Expand Down
36 changes: 20 additions & 16 deletions src/components/utils/Alert.js
Original file line number Diff line number Diff line change
@@ -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 (
<MUI_Alert severity={type} className={classes.content} icon={<WarningIcon />} data-testid="Alert">
{title ? <AlertTitle>{title}</AlertTitle> : null}
<MUIAlert severity={type} className={classes.content} icon={<WarningIcon />} data-testid="Alert">
{title ?
<AlertTitle>
{title}
</AlertTitle> : null}
{children}
</MUI_Alert>
)
}
</MUIAlert>
);
};

Alert.propTypes = {
type: PropTypes.oneOf(["error", "warning", "info", "success"]),
title: PropTypes.string,
children: PropTypes.string,
fontSize: PropTypes.number,
}
};
27 changes: 12 additions & 15 deletions src/pages/ValidationPage.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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,
Expand All @@ -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,
}
},
},


Expand All @@ -48,7 +45,7 @@ const ValidationPage = () => {
const [error, setError] = useState("");


useEffect( () => {
useEffect(() => {
async function validate() {
try {
setLoading(false);
Expand All @@ -71,10 +68,10 @@ const ValidationPage = () => {
const { title, text } = success ? successMessage : getValidationMessage(error);
return (
<CardContent className={classes.content}>
<Typography variant="h5" className={classes.title} gutterBottom>
<Typography variant="h5" className={classes.title} gutterBottom>
{title}
</Typography>
<Typography variant="body1" gutterBottom align='center' >
</Typography>
<Typography variant="body1" gutterBottom align="center">
{text}
{!success ? "For more information contact us at " : ""}
<Link href={"mailto:[email protected]"}> [email protected]</Link>
Expand All @@ -97,7 +94,7 @@ const ValidationPage = () => {
</CardContent>
);
} else {
return getMessageCard(error);
return getMessageCard(error);
}

};
Expand Down
29 changes: 17 additions & 12 deletions src/pages/ValidationPage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,53 +25,58 @@ describe("Validation Page", () => {
const page = await render(
<BrowserRouter>
<ThemeProvider theme={AppTheme}>
<ValidationPage></ValidationPage>
<ValidationPage />
</ThemeProvider>
</BrowserRouter>,
);

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(
<BrowserRouter>
<ThemeProvider theme={AppTheme}>
<ValidationPage></ValidationPage>
<ValidationPage />
</ThemeProvider>
</BrowserRouter>,
);
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(
<BrowserRouter>
<ThemeProvider theme={AppTheme}>
<ValidationPage></ValidationPage>
<ValidationPage />
</ThemeProvider>
</BrowserRouter>,
);
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(
<BrowserRouter>
<ThemeProvider theme={AppTheme}>
<ValidationPage></ValidationPage>
<ValidationPage />
</ThemeProvider>
</BrowserRouter>,
);
const {title, text} = getValidationMessage("application-already-validated");
const { title } = getValidationMessage("application-already-validated");
expect(page.queryByText(title)).toBeInTheDocument();
});
});

0 comments on commit 16e11d1

Please sign in to comment.