diff --git a/src/components/Offers/Form/form-components/OfferForm.js b/src/components/Offers/Form/form-components/OfferForm.js
index 86d8a415..fa31f2b7 100644
--- a/src/components/Offers/Form/form-components/OfferForm.js
+++ b/src/components/Offers/Form/form-components/OfferForm.js
@@ -112,9 +112,6 @@ const OfferForm = ({ context, title }) => {
key: `${Date.now()}-fetchCompanyApplicationsError`,
});
});
- return () => {
- request.cancel();
- };
}
}, [addSnackbar, session.isValidating, session.isLoggedIn]);
diff --git a/src/components/Offers/New/CreateOfferForm.spec.js b/src/components/Offers/New/CreateOfferForm.spec.js
index 95588488..5aefdd77 100644
--- a/src/components/Offers/New/CreateOfferForm.spec.js
+++ b/src/components/Offers/New/CreateOfferForm.spec.js
@@ -3,7 +3,7 @@ import { createTheme } from "@material-ui/core/styles";
import useComponentController from "../../../hooks/useComponentController";
import { CreateOfferController, CreateOfferControllerContext } from "./CreateOfferForm";
import { BrowserRouter } from "react-router-dom";
-import { screen, fireEvent, renderWithStoreAndTheme } from "../../../test-utils";
+import { screen, fireEvent, renderWithStoreAndTheme, render } from "../../../test-utils";
import useSession from "../../../hooks/useSession";
import CreateOfferPage from "../../../pages/CreateOfferPage";
import { MuiPickersUtilsProvider } from "@material-ui/pickers";
@@ -14,9 +14,17 @@ import { act } from "@testing-library/react";
import { DAY_IN_MS } from "../../../utils/TimeUtils";
import { PAID_OPTIONS } from "../Form/form-components/OfferForm";
import { HumanValidationReasons } from "../../../utils";
+import { validateApplication } from "../../../services/companyApplicationService";
+import { ThemeProvider } from "@material-ui/core";
+import AppTheme from "../../../AppTheme";
+import ValidationPage from "../../../pages/ValidationPage";
+import { getValidationMessage } from "../../Apply/Company/CompanyApplicationUtils";
+import { fetchCompanyApplicationState } from "../../../services/companyService";
+import { Alert } from "../../utils/Alert";
jest.mock("../../../hooks/useSession");
jest.mock("../../../services/locationSearchService");
+jest.mock("../../../services/companyService");
// eslint-disable-next-line react/prop-types
const CreateOfferWrapper = ({ children }) => {
@@ -40,6 +48,7 @@ describe("Create Offer Form", () => {
const initialState = {};
const theme = createTheme({});
+ fetchCompanyApplicationState.mockImplementation(async () =>"APPROVED");
// it("Should edit description", () => {
// As of today, it is not possible to test contenteditable elements (such as the awesome description editor)
@@ -217,6 +226,41 @@ describe("Create Offer Form", () => {
expect(element).toBeVisible();
});
});
+
+ it("Should render alert if company is not approved", async () => {
+ useSession.mockImplementation(() => ({ isLoggedIn: true, data: { company: { name: "Company Name" } } }));
+ fetchCompanyApplicationState.mockImplementation(async () =>"UNVERIFIED");
+
+ await renderWithStoreAndTheme(
+
+
+
+
+
+
+ ,
+ { initialState, theme }
+ );
+ expect( screen.queryByTestId( 'Alert')).toBeInTheDocument();
+
+ });
+
+ it("Should not render alert if company is approved", async () => {
+ useSession.mockImplementation(() => ({ isLoggedIn: true, data: { company: { name: "Company Name" } } }));
+ fetchCompanyApplicationState.mockImplementation(async () =>"APPROVED");
+
+ await renderWithStoreAndTheme(
+
+
+
+
+
+
+ ,
+ { initialState, theme }
+ );
+ expect(await screen.queryByTestId("Alert")).not.toBeInTheDocument();
+ });
});
describe("Should validate Form", () => {
diff --git a/src/components/utils/Alert.js b/src/components/utils/Alert.js
index 49236787..76bbcbbe 100644
--- a/src/components/utils/Alert.js
+++ b/src/components/utils/Alert.js
@@ -18,7 +18,7 @@ const useStyles = (props) => makeStyles((theme) => ({
export const Alert = ({type, title, fontSize = 1, children}) => {
const classes = useStyles({fontSize: fontSize})();
return (
- }>
+ } data-testid="Alert">
{title ? {title} : null}
{children}
@@ -30,4 +30,4 @@ Alert.propTypes = {
title: PropTypes.string,
children: PropTypes.string,
fontSize: PropTypes.number,
-}
\ No newline at end of file
+}
diff --git a/src/pages/CompanyOffersManagementPage.js b/src/pages/CompanyOffersManagementPage.js
index 79248cc5..09793a97 100644
--- a/src/pages/CompanyOffersManagementPage.js
+++ b/src/pages/CompanyOffersManagementPage.js
@@ -37,9 +37,6 @@ const CompanyOffersManagementPage = () => {
key: `${Date.now()}-fetchCompanyApplicationsError`,
});
});
- return () => {
- request.cancel();
- };
}
}, [addSnackbar, session.isLoggedIn, session.isValidating]);
diff --git a/src/pages/CompanyOffersManagementPage.spec.js b/src/pages/CompanyOffersManagementPage.spec.js
new file mode 100644
index 00000000..6286e084
--- /dev/null
+++ b/src/pages/CompanyOffersManagementPage.spec.js
@@ -0,0 +1,50 @@
+import React from "react";
+import { createTheme } from "@material-ui/core/styles";
+import { BrowserRouter } from "react-router-dom";
+import { renderWithStoreAndTheme, screen } from "../test-utils";
+import useSession from "../hooks/useSession";
+import { fetchCompanyApplicationState } from "../services/companyService";
+import { MuiPickersUtilsProvider } from "@material-ui/pickers";
+import DateFnsUtils from "@date-io/date-fns";
+import CompanyOffersManagementPage from "./CompanyOffersManagementPage";
+
+jest.mock("../hooks/useSession");
+jest.mock("../services/offerService");
+jest.mock("../services/companyService");
+const theme = createTheme({});
+
+// eslint-disable-next-line react/prop-types
+
+describe("Company Offers Management Page", () => {
+
+ it("Should render alert if company is not approved", async () => {
+ useSession.mockImplementation(() => ({ isLoggedIn: true, data: { company: { name: "Company Name" } } }));
+ fetchCompanyApplicationState.mockImplementation(async () =>"UNVERIFIED");
+
+ await renderWithStoreAndTheme(
+
+
+
+
+ ,
+ { initialState: {}, theme }
+ );
+ expect( screen.queryByTestId( 'Alert')).toBeInTheDocument();
+
+ });
+
+ it("Should not render alert if company is approved", async () => {
+ useSession.mockImplementation(() => ({ isLoggedIn: true, data: { company: { name: "Company Name" } } }));
+ fetchCompanyApplicationState.mockImplementation(async () =>"APPROVED");
+
+ await renderWithStoreAndTheme(
+
+
+
+
+ ,
+ { initialState: {}, theme }
+ );
+ expect(await screen.queryByTestId("Alert")).not.toBeInTheDocument();
+ });
+});