| 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")); | |||||
| }); | |||||
| }); |
| 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")); | |||||
| }); | |||||
| }); |
| border: "2px solid #000", | border: "2px solid #000", | ||||
| boxShadow: 24, | boxShadow: 24, | ||||
| }; | }; | ||||
| /* istanbul ignore file */ | |||||
| const AddAdModal = ({ open, handleClose }) => { | const AddAdModal = ({ open, handleClose }) => { | ||||
| const [stage, setStage] = useState(1); | const [stage, setStage] = useState(1); | ||||
| const [title, setTitle] = useState(""); | const [title, setTitle] = useState(""); |
| import React from "react"; | import React from "react"; | ||||
| import PropTypes from "prop-types"; | import PropTypes from "prop-types"; | ||||
| /* istanbul ignore file */ | |||||
| const AddAdModalFirstStage = ({ | const AddAdModalFirstStage = ({ | ||||
| onIncrementStage, | onIncrementStage, | ||||
| onDecrementStage, | onDecrementStage, |
| import PropTypes from "prop-types"; | import PropTypes from "prop-types"; | ||||
| import { Editor } from "@tinymce/tinymce-react"; | import { Editor } from "@tinymce/tinymce-react"; | ||||
| /* istanbul ignore file */ | |||||
| const AddAdModalThirdStage = ({ onDecrementStage, onAddAd }) => { | const AddAdModalThirdStage = ({ onDecrementStage, onAddAd }) => { | ||||
| const editorKeyResponsibilitiesRef = useRef(); | const editorKeyResponsibilitiesRef = useRef(); | ||||
| const editorRequirementsRef = useRef(); | const editorRequirementsRef = useRef(); |