Skip to content

Commit

Permalink
Adding a circular progress bar to the edit offer form and making a te…
Browse files Browse the repository at this point in the history
…st to verify if it is being shown.
  • Loading branch information
FranciscoCardoso913 committed Sep 16, 2023
1 parent a5f7e3a commit 3d0e58a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/components/Offers/Edit/EditOfferForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useOfferForm from "../../../hooks/useOfferForm";
import { INITIAL_JOB_DURATION } from "../../../reducers/searchOffersReducer";
import useSession from "../../../hooks/useSession";
import EditOfferSchema from "./EditOfferSchema";
import { CardContent, CircularProgress, Grid } from "@material-ui/core";

export const EditOfferControllerContext = React.createContext();

Expand Down Expand Up @@ -155,7 +156,20 @@ const EditOfferForm = () => {
canEdit,
} = useContext(EditOfferControllerContext);

if (canEdit === undefined) return null;
if (canEdit === undefined)
return (
<Grid
container
direction="column"
alignItems="center"
>
<Grid item xs={3}>
<CardContent>
<CircularProgress />
</CardContent>
</Grid>
</Grid>
);

if (errorOffer || canEdit === false) {
return <Redirect {...redirectProps} />;
Expand Down
17 changes: 17 additions & 0 deletions src/components/Offers/Edit/EditOfferForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,23 @@ describe("Edit Offer Form", () => {

expect(screen.findByText("Test Redirect"));
});
it("should show circular progress bar while data is being fetch", () => {
useSession.mockImplementation(() => ({ isValidating: true, isLoggedIn: true, data: { company: { _id: "company_id" } } }));
useOffer.mockImplementation(() => ({ offer, loading: false, error: null, mutate: () => {} }));

renderWithStoreAndTheme(
<BrowserRouter>
<MuiPickersUtilsProvider utils={DateFnsUtils}>
<EditOfferWrapper>
<EditOfferPage />
</EditOfferWrapper>
</MuiPickersUtilsProvider>
</BrowserRouter>,
{ initialState, theme }
);
expect(screen.queryByRole("progressbar")).toBeInTheDocument();

});

it("should render enabled form", () => {
useSession.mockImplementation(() => ({ isLoggedIn: true, data: { company: { _id: "company_id" } } }));
Expand Down

0 comments on commit 3d0e58a

Please sign in to comment.