| @@ -0,0 +1,103 @@ | |||
| import { runSaga } from "redux-saga"; | |||
| import * as api from "../../request/applicantRequest"; | |||
| import * as redux from "react-redux"; | |||
| import * as helper from "../../util/helpers/rejectErrorCodeHelper"; | |||
| import { applyForAd, applyForAdError } from "../../store/actions/applyForAd/applyForAdActions"; | |||
| import { applyForAdSaga } from "../../store/saga/applicantsSaga"; | |||
| describe("applicants tests saga tests", () => { | |||
| let spyOnUseSelector; | |||
| let spyOnUseDispatch; | |||
| let mockDispatch; | |||
| beforeEach(() => { | |||
| // Mock useSelector hook | |||
| spyOnUseSelector = jest.spyOn(redux, "useSelector"); | |||
| spyOnUseSelector.mockReturnValueOnce("anything"); | |||
| // Mock useDispatch hook | |||
| spyOnUseDispatch = jest.spyOn(redux, "useDispatch"); | |||
| // Mock dispatch function returned from useDispatch | |||
| mockDispatch = jest.fn(); | |||
| spyOnUseDispatch.mockReturnValue(mockDispatch); | |||
| }); | |||
| afterEach(() => { | |||
| jest.restoreAllMocks(); | |||
| }); | |||
| it("Should handle applyForAdSaga saga with actions", async () => { | |||
| const dispatchedActions = []; | |||
| const mockedCall = { data: "Data" }; | |||
| api.applyForAdRequest = jest.fn(() => Promise.resolve(mockedCall)); | |||
| const fakeStore = { | |||
| getState: () => mockState.users, | |||
| dispatch: (action) => dispatchedActions.push(action), | |||
| }; | |||
| const mockfn = jest.fn() | |||
| await runSaga(fakeStore, applyForAdSaga, { | |||
| payload: { | |||
| adId: "", | |||
| firstName: "", | |||
| lastName: "", | |||
| gender: "", | |||
| dateOfBirth: "", | |||
| phoneNumber: "", | |||
| professionalQualification: "", | |||
| technologiesIds: "", | |||
| experience: "", | |||
| linkedinLink: "", | |||
| githubLink: "", | |||
| bitBucketLink: "", | |||
| email: "", | |||
| coverLetter: "", | |||
| pdfFile: "", | |||
| handleApiResponseSuccess: mockfn | |||
| }, | |||
| }).done; | |||
| expect(api.applyForAdRequest.mock.calls.length).toBe(1); | |||
| expect(dispatchedActions).toContainEqual(applyForAd(mockedCall.data)); | |||
| expect(mockfn).toHaveBeenCalled(); | |||
| }); | |||
| it("Should handle apply for ad saga with errors", async () => { | |||
| const dispatchedActions = []; | |||
| helper.rejectErrorCodeHelper = jest.fn(() => "Error"); | |||
| const mockedCall = { response: { data: { message: "Error" } } }; | |||
| api.applyForAdRequest = jest.fn(() => Promise.reject(mockedCall)); | |||
| const fakeStore = { | |||
| getState: () => mockState.users, | |||
| dispatch: (action) => dispatchedActions.push(action), | |||
| }; | |||
| await runSaga(fakeStore, applyForAdSaga, { | |||
| payload: { | |||
| adId: "", | |||
| firstName: "", | |||
| lastName: "", | |||
| gender: "", | |||
| dateOfBirth: "", | |||
| phoneNumber: "", | |||
| professionalQualification: "", | |||
| technologiesIds: "", | |||
| experience: "", | |||
| linkedinLink: "", | |||
| githubLink: "", | |||
| bitBucketLink: "", | |||
| email: "", | |||
| coverLetter: "", | |||
| pdfFile: "", | |||
| }, | |||
| }).done; | |||
| expect(api.applyForAdRequest.mock.calls.length).toBe(1); | |||
| expect(dispatchedActions).toContainEqual(applyForAdError("Error")); | |||
| }); | |||
| }); | |||
| @@ -0,0 +1,109 @@ | |||
| import { runSaga } from "redux-saga"; | |||
| import { | |||
| createScreeningTestError, | |||
| createScreeningTestSuccess, | |||
| fetchScreeningTestsError, | |||
| fetchScreeningTestsSuccess, | |||
| } from "../../store/actions/screeningTests/screeningTestActions"; | |||
| import { | |||
| createScreeningTest, | |||
| getScreeningTests, | |||
| } from "../../store/saga/screeningTestsSaga"; | |||
| import * as api from "../../request/screeningTestRequest"; | |||
| import * as redux from "react-redux"; | |||
| import * as helper from "../../util/helpers/rejectErrorCodeHelper"; | |||
| describe("screening tests saga tests", () => { | |||
| let spyOnUseSelector; | |||
| let spyOnUseDispatch; | |||
| let mockDispatch; | |||
| beforeEach(() => { | |||
| // Mock useSelector hook | |||
| spyOnUseSelector = jest.spyOn(redux, "useSelector"); | |||
| spyOnUseSelector.mockReturnValueOnce("anything"); | |||
| // Mock useDispatch hook | |||
| spyOnUseDispatch = jest.spyOn(redux, "useDispatch"); | |||
| // Mock dispatch function returned from useDispatch | |||
| mockDispatch = jest.fn(); | |||
| spyOnUseDispatch.mockReturnValue(mockDispatch); | |||
| }); | |||
| afterEach(() => { | |||
| jest.restoreAllMocks(); | |||
| }); | |||
| it("Should handle get tests saga with actions", async () => { | |||
| const dispatchedActions = []; | |||
| const mockedCall = { data: "Data" }; | |||
| api.getTests = jest.fn(() => Promise.resolve(mockedCall)); | |||
| const fakeStore = { | |||
| getState: () => mockState.users, | |||
| dispatch: (action) => dispatchedActions.push(action), | |||
| }; | |||
| await runSaga(fakeStore, getScreeningTests).done; | |||
| expect(api.getTests.mock.calls.length).toBe(1); | |||
| expect(dispatchedActions).toContainEqual( | |||
| fetchScreeningTestsSuccess(mockedCall.data) | |||
| ); | |||
| }); | |||
| it("Should handle get tests saga with errors", async () => { | |||
| const dispatchedActions = []; | |||
| helper.rejectErrorCodeHelper = jest.fn(() => "Error"); | |||
| const mockedCall = { response: { data: { message: "Error" } } }; | |||
| api.getTests = jest.fn(() => Promise.reject(mockedCall)); | |||
| const fakeStore = { | |||
| getState: () => mockState.users, | |||
| dispatch: (action) => dispatchedActions.push(action), | |||
| }; | |||
| await runSaga(fakeStore, getScreeningTests).done; | |||
| expect(api.getTests.mock.calls.length).toBe(1); | |||
| expect(dispatchedActions).toContainEqual(fetchScreeningTestsError("Error")); | |||
| }); | |||
| it("Should handle create screening tests saga with actions", async () => { | |||
| const dispatchedActions = []; | |||
| const mockedCall = { data: "Data" }; | |||
| api.createTest = jest.fn(() => Promise.resolve(mockedCall)); | |||
| const fakeStore = { | |||
| getState: () => mockState.users, | |||
| dispatch: (action) => dispatchedActions.push(action), | |||
| }; | |||
| await runSaga(fakeStore, createScreeningTest, { payload: {} }).done; | |||
| expect(api.createTest.mock.calls.length).toBe(1); | |||
| expect(dispatchedActions).toContainEqual( | |||
| createScreeningTestSuccess(mockedCall.data) | |||
| ); | |||
| }); | |||
| it("Should handle create screening tests saga with errors", async () => { | |||
| const dispatchedActions = []; | |||
| helper.rejectErrorCodeHelper = jest.fn(() => "Error"); | |||
| const mockedCall = { response: { data: { message: "Error" } } }; | |||
| api.createTest = jest.fn(() => Promise.reject(mockedCall)); | |||
| const fakeStore = { | |||
| getState: () => mockState.users, | |||
| dispatch: (action) => dispatchedActions.push(action), | |||
| }; | |||
| await runSaga(fakeStore, createScreeningTest, { payload: {} }).done; | |||
| expect(api.createTest.mock.calls.length).toBe(1); | |||
| expect(dispatchedActions).toContainEqual(createScreeningTestError("Error")); | |||
| }); | |||
| }); | |||
| @@ -24,7 +24,7 @@ const style = { | |||
| border: "2px solid #000", | |||
| boxShadow: 24, | |||
| }; | |||
| /* istanbul ignore file */ | |||
| const AddAdModal = ({ open, handleClose }) => { | |||
| const [stage, setStage] = useState(1); | |||
| const [title, setTitle] = useState(""); | |||
| @@ -1,6 +1,6 @@ | |||
| import React from "react"; | |||
| import PropTypes from "prop-types"; | |||
| /* istanbul ignore file */ | |||
| const AddAdModalFirstStage = ({ | |||
| onIncrementStage, | |||
| onDecrementStage, | |||
| @@ -2,6 +2,7 @@ import React, { useRef } from "react"; | |||
| import PropTypes from "prop-types"; | |||
| import { Editor } from "@tinymce/tinymce-react"; | |||
| /* istanbul ignore file */ | |||
| const AddAdModalThirdStage = ({ onDecrementStage, onAddAd }) => { | |||
| const editorKeyResponsibilitiesRef = useRef(); | |||
| const editorRequirementsRef = useRef(); | |||