| import * as fc from "../../store/saga/adsSaga"; | import * as fc from "../../store/saga/adsSaga"; | ||||
| import { setAds, setFilteredAds } from "../../store/actions/ads/adsAction"; | import { setAds, setFilteredAds } from "../../store/actions/ads/adsAction"; | ||||
| import { setArchiveAds } from "../../store/actions/archiveAds/archiveAdsActions"; | import { setArchiveAds } from "../../store/actions/archiveAds/archiveAdsActions"; | ||||
| import { setAd } from "../../store/actions/ad/adActions"; | |||||
| import { setCreateAd } from "../../store/actions/createAd/createAdActions"; | |||||
| import { setAd, setAdError } from "../../store/actions/ad/adActions"; | |||||
| import { archiveActiveAd } from "../../store/actions/archiveActiveAd/archiveActiveAdActions"; | |||||
| import * as helper from "../../util/helpers/rejectErrorCodeHelper"; | |||||
| describe("Ads reducer tests", () => { | describe("Ads reducer tests", () => { | ||||
| const cont = ( | const cont = ( | ||||
| expect(api.getAdDetailsById.mock.calls.length).toBe(1); | expect(api.getAdDetailsById.mock.calls.length).toBe(1); | ||||
| expect(dispatchedActions).toContainEqual(setAd(mockedCall.data)); | expect(dispatchedActions).toContainEqual(setAd(mockedCall.data)); | ||||
| }); | }); | ||||
| it("Should create ad", async () => { | |||||
| const dispatchedActions = []; | |||||
| const mockedCall = { | |||||
| data: { | |||||
| title: "React Developer", | |||||
| minimumExperience: 1, | |||||
| createdAt: new Date(), | |||||
| expiredAt: new Date("2023-5-5"), | |||||
| keyResponsibilities: "key responsibilities", | |||||
| requirements: "requirements", | |||||
| offer: "offer", | |||||
| workHour: "PartTime", | |||||
| employmentType: "Intership", | |||||
| technologiesIds: [1, 2], | |||||
| onSuccessAddAd: jest.fn, | |||||
| }, | |||||
| }; | |||||
| api.createNewAd = jest.fn(() => Promise.resolve(mockedCall)); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.ads.ads, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| await runSaga(fakeStore, fc.createAd, { | |||||
| payload: { | |||||
| title: "React Developer", | |||||
| minimumExperience: 1, | |||||
| createdAt: new Date(), | |||||
| expiredAt: new Date("2023-5-5"), | |||||
| keyResponsibilities: "key responsibilities", | |||||
| requirements: "requirements", | |||||
| offer: "offer", | |||||
| workHour: "PartTime", | |||||
| employmentType: "Intership", | |||||
| technologiesIds: [1, 2], | |||||
| onSuccessAddAd: jest.fn, | |||||
| }, | |||||
| }).done; | |||||
| expect(api.createNewAd.mock.calls.length).toBe(1); | |||||
| expect(dispatchedActions).toContainEqual(setCreateAd(mockedCall.data)); | |||||
| }); | |||||
| it("Archive ad", async () => { | |||||
| const dispatchedActions = []; | |||||
| const mockedCall = { | |||||
| data: { | |||||
| id: 1, | |||||
| navigateToAds: jest.fn, | |||||
| }, | |||||
| }; | |||||
| api.archiveActiveAdRequest = jest.fn(() => Promise.resolve(mockedCall)); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.ads.ads, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| await runSaga(fakeStore, fc.archiveActiveAdSaga, { | |||||
| payload: { | |||||
| id: 1, | |||||
| navigateToAds: jest.fn, | |||||
| }, | |||||
| }).done; | |||||
| expect(api.archiveActiveAdRequest.mock.calls.length).toBe(1); | |||||
| expect(dispatchedActions).toContainEqual(archiveActiveAd(mockedCall.data)); | |||||
| }); | |||||
| it("Should not return ads when exception was thrown", async () => { | |||||
| const dispatchedActions = []; | |||||
| const error = { | |||||
| response: { | |||||
| data: { message: "Error" }, | |||||
| }, | |||||
| }; | |||||
| api.getAllAds = jest.fn(() => Promise.reject(error)); | |||||
| const mockfn = jest.fn(); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.ads.ads, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| // wait for saga to complete | |||||
| await runSaga(fakeStore, fc.getAds, {}).done; | |||||
| expect(mockfn).not.toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should not return filtered ads when exception was thrown", async () => { | |||||
| const dispatchedActions = []; | |||||
| const error = { | |||||
| response: { | |||||
| data: { message: "Error" }, | |||||
| }, | |||||
| }; | |||||
| const filter = { | |||||
| minimumExperience: 0, | |||||
| maximumExperience: 0, | |||||
| technologies: [1], | |||||
| workHour: "FullTime", | |||||
| employmentType: "Work", | |||||
| }; | |||||
| api.getFilteredAds = jest.fn(() => Promise.reject(error)); | |||||
| const mockfn = jest.fn(); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.ads.ads, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| // wait for saga to complete | |||||
| await runSaga(fakeStore, fc.getFilteredAds, filter).done; | |||||
| expect(mockfn).not.toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should not return ad when exception was thrown", async () => { | |||||
| const dispatchedActions = []; | |||||
| const error = { | |||||
| response: { | |||||
| data: { message: "Error" }, | |||||
| }, | |||||
| }; | |||||
| api.getAd = jest.fn(() => Promise.reject(error)); | |||||
| const mockfn = jest.fn(); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.ads.ads, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| // wait for saga to complete | |||||
| await runSaga(fakeStore, fc.getAd, { | |||||
| payload: { | |||||
| id: 1, | |||||
| }, | |||||
| }).done; | |||||
| expect(mockfn).not.toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should not return archived ad when exception was thrown", async () => { | |||||
| const dispatchedActions = []; | |||||
| const error = { | |||||
| response: { | |||||
| data: { message: "Error" }, | |||||
| }, | |||||
| }; | |||||
| api.getAd = jest.fn(() => Promise.reject(error)); | |||||
| const mockfn = jest.fn(); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.ads.ads, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| // wait for saga to complete | |||||
| await runSaga(fakeStore, fc.getArchiveAds, {}).done; | |||||
| expect(mockfn).not.toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should not create ad when exception was thrown", async () => { | |||||
| const dispatchedActions = []; | |||||
| const error = { | |||||
| response: { | |||||
| data: { message: "Error" }, | |||||
| }, | |||||
| }; | |||||
| api.createNewAd = jest.fn(() => Promise.reject(error)); | |||||
| const mockfn = jest.fn(); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.ads.ads, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| // wait for saga to complete | |||||
| await runSaga(fakeStore, fc.createAd, { | |||||
| payload: { | |||||
| title: "React Developer", | |||||
| minimumExperience: 1, | |||||
| createdAt: new Date(), | |||||
| expiredAt: new Date("2023-5-5"), | |||||
| keyResponsibilities: "key responsibilities", | |||||
| requirements: "requirements", | |||||
| offer: "offer", | |||||
| workHour: "PartTime", | |||||
| employmentType: "Intership", | |||||
| technologiesIds: [1, 2], | |||||
| onSuccessAddAd: jest.fn, | |||||
| }, | |||||
| }).done; | |||||
| expect(mockfn).not.toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should archive active ad when exception was thrown", async () => { | |||||
| const dispatchedActions = []; | |||||
| const error = { | |||||
| response: { | |||||
| data: { message: "Error" }, | |||||
| }, | |||||
| }; | |||||
| api.createNewAd = jest.fn(() => Promise.reject(error)); | |||||
| const mockfn = jest.fn(); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.ads.ads, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| // wait for saga to complete | |||||
| await runSaga(fakeStore, fc.archiveActiveAdSaga, { | |||||
| payload: { | |||||
| id: 1, | |||||
| navigateToAds: jest.fn, | |||||
| }, | |||||
| }).done; | |||||
| expect(mockfn).not.toHaveBeenCalled(); | |||||
| }); | |||||
| it("should handle ad load errors in case of failure", async () => { | |||||
| const dispatchedActions = []; | |||||
| helper.rejectErrorCodeHelper = jest.fn(() => "Error"); | |||||
| const error = { | |||||
| response: { | |||||
| data: { message: "Error" }, | |||||
| }, | |||||
| }; | |||||
| api.getAd = jest.fn(() => Promise.reject(error)); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.ads.ads, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| await runSaga(fakeStore, fc.getAd, { | |||||
| payload: { | |||||
| id: 1, | |||||
| }, | |||||
| }).done; | |||||
| expect(api.getAdDetailsById.mock.calls.length).toBe(1); | |||||
| expect(dispatchedActions).toContainEqual( | |||||
| setAdError(error.response.data.message) | |||||
| ); | |||||
| }); | |||||
| }); | }); |
| import { FETCH_PATTERNS_REQ } from "../../store/actions/patterns/patternsActionConstants"; | import { FETCH_PATTERNS_REQ } from "../../store/actions/patterns/patternsActionConstants"; | ||||
| import ColorModeProvider from "../../context/ColorModeContext"; | import ColorModeProvider from "../../context/ColorModeContext"; | ||||
| import * as fc from "../../store/saga/patternsSaga"; | import * as fc from "../../store/saga/patternsSaga"; | ||||
| import { setFilteredPatterns, setPatterns } from "../../store/actions/patterns/patternsActions"; | |||||
| import { | |||||
| setFilteredPatterns, | |||||
| setPatterns, | |||||
| } from "../../store/actions/patterns/patternsActions"; | |||||
| import { setPattern } from "../../store/actions/pattern/patternActions"; | import { setPattern } from "../../store/actions/pattern/patternActions"; | ||||
| import { setPatternApplicants } from "../../store/actions/patternApplicants/patternApplicantsActions"; | import { setPatternApplicants } from "../../store/actions/patternApplicants/patternApplicantsActions"; | ||||
| import { createPattern } from "../../store/actions/createPattern/createPatternActions"; | |||||
| import { updatePattern } from "../../store/actions/updatePattern/updatePatternActions"; | |||||
| import { scheduleAppointment } from "../../store/actions/scheduleAppointment/scheduleAppointmentActions"; | |||||
| describe("Patterns reducer tests", () => { | describe("Patterns reducer tests", () => { | ||||
| const cont = ( | const cont = ( | ||||
| await runSaga(fakeStore, fc.getPatterns, {}).done; | await runSaga(fakeStore, fc.getPatterns, {}).done; | ||||
| expect(api.getAllPatterns.mock.calls.length).toBe(1); | expect(api.getAllPatterns.mock.calls.length).toBe(1); | ||||
| expect(dispatchedActions).toContainEqual(setPatterns(mockedCall.data)); | expect(dispatchedActions).toContainEqual(setPatterns(mockedCall.data)); | ||||
| }); | |||||
| }); | |||||
| it("Should load and handle pattern by id in case of success", async () => { | it("Should load and handle pattern by id in case of success", async () => { | ||||
| const dispatchedActions = []; | const dispatchedActions = []; | ||||
| await runSaga(fakeStore, fc.getPattern, { payload: id }).done; | await runSaga(fakeStore, fc.getPattern, { payload: id }).done; | ||||
| expect(api.getPatternById.mock.calls.length).toBe(1); | expect(api.getPatternById.mock.calls.length).toBe(1); | ||||
| expect(dispatchedActions).toContainEqual(setPattern(mockedCall.data)); | expect(dispatchedActions).toContainEqual(setPattern(mockedCall.data)); | ||||
| }); | |||||
| }); | |||||
| it("Should load and handle pattern applicants in case of success", async () => { | it("Should load and handle pattern applicants in case of success", async () => { | ||||
| const dispatchedActions = []; | const dispatchedActions = []; | ||||
| await runSaga(fakeStore, fc.getPatternApplicants, { payload: id }).done; | await runSaga(fakeStore, fc.getPatternApplicants, { payload: id }).done; | ||||
| expect(api.getPatternApplicantsById.mock.calls.length).toBe(1); | expect(api.getPatternApplicantsById.mock.calls.length).toBe(1); | ||||
| expect(dispatchedActions).toContainEqual(setPatternApplicants(mockedCall.data)); | |||||
| }); | |||||
| expect(dispatchedActions).toContainEqual( | |||||
| setPatternApplicants(mockedCall.data) | |||||
| ); | |||||
| }); | |||||
| it("Should load and handle filtered patterns in case of success", async () => { | it("Should load and handle filtered patterns in case of success", async () => { | ||||
| const dispatchedActions = []; | const dispatchedActions = []; | ||||
| await runSaga(fakeStore, fc.filterPatterns, filters).done; | await runSaga(fakeStore, fc.filterPatterns, filters).done; | ||||
| expect(api.getFilteredPatterns.mock.calls.length).toBe(1); | expect(api.getFilteredPatterns.mock.calls.length).toBe(1); | ||||
| expect(dispatchedActions).toContainEqual(setFilteredPatterns(mockedCall.data)); | |||||
| }); | |||||
| expect(dispatchedActions).toContainEqual( | |||||
| setFilteredPatterns(mockedCall.data) | |||||
| ); | |||||
| }); | |||||
| it("Should create new pattern", async () => { | |||||
| const dispatchedActions = []; | |||||
| const mockedCall = { | |||||
| data: { | |||||
| title: "Neuspesan korak", | |||||
| selectionLevelId: 1, | |||||
| message: "Poruka", | |||||
| }, | |||||
| }; | |||||
| api.createPatternRequest = jest.fn(() => Promise.resolve(mockedCall)); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.patterns.patterns, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| await runSaga(fakeStore, fc.createPatternSaga, { | |||||
| payload: { | |||||
| title: "Neuspesan korak", | |||||
| selectionLevelId: 1, | |||||
| message: "Poruka", | |||||
| }, | |||||
| }).done; | |||||
| expect(api.createPatternRequest.mock.calls.length).toBe(1); | |||||
| expect(dispatchedActions).toContainEqual(createPattern(mockedCall.data)); | |||||
| }); | |||||
| it("Should update pattern", async () => { | |||||
| const dispatchedActions = []; | |||||
| const mockedCall = { | |||||
| data: { | |||||
| id: 1, | |||||
| title: "Zakazan intervju", | |||||
| createdAt: new Date(), | |||||
| selectionLevelId: 1, | |||||
| message: "Message", | |||||
| }, | |||||
| }; | |||||
| api.updatePatternRequest = jest.fn(() => Promise.resolve(mockedCall)); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.patterns.patterns, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| await runSaga(fakeStore, fc.updatePatternSaga, { | |||||
| payload: { | |||||
| id: 1, | |||||
| title: "Zakazan intervju", | |||||
| createdAt: new Date(), | |||||
| selectionLevelId: 1, | |||||
| message: "Message", | |||||
| }, | |||||
| }).done; | |||||
| expect(api.updatePatternRequest.mock.calls.length).toBe(1); | |||||
| expect(dispatchedActions).toContainEqual(updatePattern(mockedCall.data)); | |||||
| }); | |||||
| it("Should schedule appointment", async () => { | |||||
| const dispatchedActions = []; | |||||
| const mockedCall = { | |||||
| data: { | |||||
| emails: ["ermin.bronja@dilig.net"], | |||||
| patternId: 1, | |||||
| handleApiResponseSuccess: jest.fn, | |||||
| }, | |||||
| }; | |||||
| api.scheduleAppointmentRequest = jest.fn(() => Promise.resolve(mockedCall)); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.patterns.patterns, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| await runSaga(fakeStore, fc.scheduleAppointmentSaga, { | |||||
| payload: { | |||||
| emails: ["ermin.bronja@dilig.net"], | |||||
| patternId: 1, | |||||
| handleApiResponseSuccess: jest.fn, | |||||
| }, | |||||
| }).done; | |||||
| expect(api.scheduleAppointmentRequest.mock.calls.length).toBe(1); | |||||
| expect(dispatchedActions).toContainEqual( | |||||
| scheduleAppointment(mockedCall.data) | |||||
| ); | |||||
| }); | |||||
| it("Should not return patterns when exception was thrown", async () => { | |||||
| const dispatchedActions = []; | |||||
| const error = { | |||||
| response: { | |||||
| data: { message: "Error" }, | |||||
| }, | |||||
| }; | |||||
| api.getAllPatterns = jest.fn(() => Promise.reject(error)); | |||||
| const mockfn = jest.fn(); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.patterns.patterns, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| // wait for saga to complete | |||||
| await runSaga(fakeStore, fc.getPatterns, {}).done; | |||||
| expect(mockfn).not.toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should not return pattern when exception was thrown", async () => { | |||||
| const dispatchedActions = []; | |||||
| const error = { | |||||
| response: { | |||||
| data: { message: "Error" }, | |||||
| }, | |||||
| }; | |||||
| api.getPatternById = jest.fn(() => Promise.reject(error)); | |||||
| const mockfn = jest.fn(); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.patterns.patterns, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| // wait for saga to complete | |||||
| await runSaga(fakeStore, fc.getPattern, { | |||||
| payload: { | |||||
| id: 1, | |||||
| }, | |||||
| }).done; | |||||
| expect(mockfn).not.toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should not return pattern applicants when exception was thrown", async () => { | |||||
| const dispatchedActions = []; | |||||
| const error = { | |||||
| response: { | |||||
| data: { message: "Error" }, | |||||
| }, | |||||
| }; | |||||
| api.getPatternApplicants = jest.fn(() => Promise.reject(error)); | |||||
| const mockfn = jest.fn(); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.patterns.patterns, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| // wait for saga to complete | |||||
| await runSaga(fakeStore, fc.getPatternApplicants, { | |||||
| payload: { | |||||
| id: 1, | |||||
| }, | |||||
| }).done; | |||||
| expect(mockfn).not.toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should not return filtered patterns when exception was thrown", async () => { | |||||
| const dispatchedActions = []; | |||||
| const error = { | |||||
| response: { | |||||
| data: { message: "Error" }, | |||||
| }, | |||||
| }; | |||||
| api.getFilteredPatterns = jest.fn(() => Promise.reject(error)); | |||||
| const mockfn = jest.fn(); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.patterns.patterns, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| // wait for saga to complete | |||||
| await runSaga(fakeStore, fc.filterPatterns, { | |||||
| fromDate: new Date("2-2-2021"), | |||||
| toDate: new Date("3-3-2023"), | |||||
| selectionLevels: [1, 2], | |||||
| }).done; | |||||
| expect(mockfn).not.toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should not create pattern when exception was thrown", async () => { | |||||
| const dispatchedActions = []; | |||||
| const error = { | |||||
| response: { | |||||
| data: { message: "Error" }, | |||||
| }, | |||||
| }; | |||||
| api.createPatternRequest = jest.fn(() => Promise.reject(error)); | |||||
| const mockfn = jest.fn(); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.patterns.patterns, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| // wait for saga to complete | |||||
| await runSaga(fakeStore, fc.createPatternSaga, { | |||||
| payload: { | |||||
| title: "Neuspesan korak", | |||||
| selectionLevelId: 1, | |||||
| message: "Poruka", | |||||
| }, | |||||
| }).done; | |||||
| expect(mockfn).not.toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should not update pattern when exception was thrown", async () => { | |||||
| const dispatchedActions = []; | |||||
| const error = { | |||||
| response: { | |||||
| data: { message: "Error" }, | |||||
| }, | |||||
| }; | |||||
| api.updatePatternRequest = jest.fn(() => Promise.reject(error)); | |||||
| const mockfn = jest.fn(); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.patterns.patterns, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| // wait for saga to complete | |||||
| await runSaga(fakeStore, fc.updatePatternSaga, { | |||||
| payload: { | |||||
| id: 1, | |||||
| title: "Zakazan intervju", | |||||
| createdAt: new Date(), | |||||
| selectionLevelId: 1, | |||||
| message: "Message", | |||||
| }, | |||||
| }).done; | |||||
| expect(mockfn).not.toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should not chedule appointment when exception was thrown", async () => { | |||||
| const dispatchedActions = []; | |||||
| const error = { | |||||
| response: { | |||||
| data: { message: "Error" }, | |||||
| }, | |||||
| }; | |||||
| api.scheduleAppointmentRequest = jest.fn(() => Promise.reject(error)); | |||||
| const mockfn = jest.fn(); | |||||
| const fakeStore = { | |||||
| getState: () => mockState.patterns.patterns, | |||||
| dispatch: (action) => dispatchedActions.push(action), | |||||
| }; | |||||
| // wait for saga to complete | |||||
| await runSaga(fakeStore, fc.scheduleAppointmentSaga, { | |||||
| payload: { | |||||
| emails: ["ermin.bronja@dilig.net"], | |||||
| patternId: 1, | |||||
| handleApiResponseSuccess: jest.fn, | |||||
| }, | |||||
| }).done; | |||||
| expect(mockfn).not.toHaveBeenCalled(); | |||||
| }); | |||||
| }); | }); |
| import { fireEvent, render, screen, waitFor } from "@testing-library/react"; | |||||
| import * as redux from "react-redux"; | |||||
| import store from "../../store"; | |||||
| import { Router } from "react-router-dom"; | |||||
| import history from "../../store/utils/history"; | |||||
| import { mockState } from "../../mockState"; | |||||
| import ColorModeProvider from "../../context/ColorModeContext"; | |||||
| import AddAdModalFirstStage from "../../components/Ads/AddAdModalFirstStage"; | |||||
| describe("Add ad modals ui tests", () => { | |||||
| const props = { | |||||
| onIncrementStage: jest.fn(), | |||||
| onDecrementStage: jest.fn(), | |||||
| onCompleteFirstStage: jest.fn(), | |||||
| title: "Title", | |||||
| employmentType: "Work", | |||||
| workHour: "FullTime", | |||||
| setTitle: jest.fn(), | |||||
| setEmploymentType: jest.fn(), | |||||
| setWorkHour: jest.fn(), | |||||
| expiredAt: new Date(), | |||||
| setExpiredAt: jest.fn(), | |||||
| }; | |||||
| const cont = ( | |||||
| <redux.Provider store={store}> | |||||
| <Router history={history}> | |||||
| <ColorModeProvider> | |||||
| <AddAdModalFirstStage {...props} /> | |||||
| </ColorModeProvider> | |||||
| </Router> | |||||
| </redux.Provider> | |||||
| ); | |||||
| let spyOnUseSelector; | |||||
| beforeEach(() => { | |||||
| spyOnUseSelector = jest.spyOn(redux, "useSelector"); | |||||
| spyOnUseSelector.mockReturnValue(mockState.ads.ads); | |||||
| }); | |||||
| afterEach(() => { | |||||
| jest.restoreAllMocks(); | |||||
| }); | |||||
| it("Should render add ad modal stage", () => { | |||||
| const { container } = render(cont); | |||||
| const modal = container.getElementsByClassName("add-ad-modal-stage"); | |||||
| expect(modal).toBeDefined(); | |||||
| }); | |||||
| it("Should render work button", () => { | |||||
| render(cont); | |||||
| expect(screen.getByTestId("add-ad-modal-work-btn")).toBeDefined(); | |||||
| }); | |||||
| it("Should render intership button", () => { | |||||
| render(cont); | |||||
| expect(screen.getByTestId("add-ad-modal-intership-btn")).toBeDefined(); | |||||
| }); | |||||
| it("Should render parttime button", () => { | |||||
| render(cont); | |||||
| expect(screen.getByTestId("add-ad-modal-parttime-btn")).toBeDefined(); | |||||
| }); | |||||
| it("Should render fulltime button", () => { | |||||
| render(cont); | |||||
| expect(screen.getByTestId("add-ad-modal-fulltime-btn")).toBeDefined(); | |||||
| }); | |||||
| it("Should render add ad modal first stage actions", () => { | |||||
| const { container } = render(cont); | |||||
| expect( | |||||
| container.getElementsByClassName("add-ad-modal-action") | |||||
| ).toBeDefined(); | |||||
| }); | |||||
| it("Should change employment type to intership", () => { | |||||
| render(cont); | |||||
| fireEvent.click(screen.getByTestId("add-ad-modal-intership-btn")); | |||||
| expect(props.setEmploymentType).toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should change employment type to work", () => { | |||||
| render(cont); | |||||
| fireEvent.click(screen.getByTestId("add-ad-modal-work-btn")); | |||||
| expect(props.setEmploymentType).toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should change work hour to parttime", () => { | |||||
| render(cont); | |||||
| fireEvent.click(screen.getByTestId("add-ad-modal-parttime-btn")); | |||||
| expect(props.setWorkHour).toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should change work hour to fulltime", () => { | |||||
| render(cont); | |||||
| fireEvent.click(screen.getByTestId("add-ad-modal-fulltime-btn")); | |||||
| expect(props.setWorkHour).toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should call function on click go back button", async () => { | |||||
| render(cont); | |||||
| fireEvent.click(screen.getByTestId("add-ad-modal-go-back")); | |||||
| waitFor(() => expect(props.onDecrementStage).toHaveBeenCalled()); | |||||
| }); | |||||
| it("Should call function on click go forward button", () => { | |||||
| render(cont); | |||||
| fireEvent.click(screen.getByTestId("add-ad-modal-go-forward")); | |||||
| expect(props.onIncrementStage).toHaveBeenCalled(); | |||||
| }); | |||||
| it("Should change title text", () => { | |||||
| render(cont); | |||||
| fireEvent.change(screen.getByTestId("add-ad-modal-title"), { target: { value: ".NET DEVELOPER" } }) | |||||
| expect(props.setTitle).toBeCalled(); | |||||
| }); | |||||
| it("Should change expired at text", () => { | |||||
| render(cont); | |||||
| fireEvent.change(screen.getByTestId("add-ad-modal-expired-at"), { target: { value: "2020-05-24" } }) | |||||
| expect(props.setExpiredAt).toBeCalled(); | |||||
| }); | |||||
| }); |
| import { render, screen, waitFor, fireEvent } from "@testing-library/react"; | |||||
| import * as redux from "react-redux"; | |||||
| import store from "../../store"; | |||||
| import { Router } from "react-router-dom"; | |||||
| import history from "../../store/utils/history"; | |||||
| import { mockState } from "../../mockState"; | |||||
| import ColorModeProvider from "../../context/ColorModeContext"; | |||||
| import AddAdModalSecondStage from "../../components/Ads/AddAdModalSecondStage"; | |||||
| describe("Add ad modals ui tests", () => { | |||||
| const props = { | |||||
| onIncrementStage: jest.fn(), | |||||
| onDecrementStage: jest.fn(), | |||||
| technologies: [ | |||||
| { | |||||
| value: ".NET", | |||||
| isChecked: false, | |||||
| technologyId: 1, | |||||
| technologyType: "Backend", | |||||
| }, | |||||
| ], | |||||
| experience: 1, | |||||
| setExperience: jest.fn(), | |||||
| }; | |||||
| const cont = ( | |||||
| <redux.Provider store={store}> | |||||
| <Router history={history}> | |||||
| <ColorModeProvider> | |||||
| <AddAdModalSecondStage {...props} /> | |||||
| </ColorModeProvider> | |||||
| </Router> | |||||
| </redux.Provider> | |||||
| ); | |||||
| let spyOnUseSelector; | |||||
| beforeEach(() => { | |||||
| spyOnUseSelector = jest.spyOn(redux, "useSelector"); | |||||
| spyOnUseSelector.mockReturnValue(mockState.ads.ads); | |||||
| }); | |||||
| afterEach(() => { | |||||
| jest.restoreAllMocks(); | |||||
| }); | |||||
| it("Should render add ad modal second stage", () => { | |||||
| const { container } = render(cont); | |||||
| expect( | |||||
| container.getElementsByClassName("add-ad-modal-stages")[0] | |||||
| ).toBeDefined(); | |||||
| }); | |||||
| it("Should change experience input", async () => { | |||||
| render(cont); | |||||
| fireEvent.change(screen.getByTestId("add-ad-modal-experience"), { | |||||
| target: { value: 1 }, | |||||
| }); | |||||
| waitFor(() => expect(props.setExperience).toBeCalled()); | |||||
| }); | |||||
| it("Should call go back", async () => { | |||||
| render(cont); | |||||
| fireEvent.click(screen.getByTestId("add-ad-modal-second-go-back")); | |||||
| waitFor(() => expect(props.onDecrementStage).toBeCalled()); | |||||
| }); | |||||
| it("Should call go forward", async () => { | |||||
| render(cont); | |||||
| fireEvent.click(screen.getByTestId("add-ad-modal-second-go-forward")); | |||||
| waitFor(() => expect(props.onIncrementStage).toBeCalled()); | |||||
| }); | |||||
| }); |
| setExpiredAt, | setExpiredAt, | ||||
| }) => { | }) => { | ||||
| const completeStageHandler = () => { | const completeStageHandler = () => { | ||||
| if(title.length === 0) { | |||||
| return; | |||||
| if (title.length === 0) { | |||||
| return; | |||||
| } | } | ||||
| onIncrementStage(); | onIncrementStage(); | ||||
| <div className="add-ad-modal-stage-sub-card"> | <div className="add-ad-modal-stage-sub-card"> | ||||
| <label>Naslov</label> | <label>Naslov</label> | ||||
| <input | <input | ||||
| data-testid="add-ad-modal-title" | |||||
| type="text" | type="text" | ||||
| value={title} | value={title} | ||||
| placeholder="ex. Medior React Developer" | placeholder="ex. Medior React Developer" | ||||
| <label>Tip zaposlenja</label> | <label>Tip zaposlenja</label> | ||||
| <div className="add-ad-modal-stage-sub-card-buttons"> | <div className="add-ad-modal-stage-sub-card-buttons"> | ||||
| <button | <button | ||||
| data-testid="add-ad-modal-work-btn" | |||||
| className={`c-btn ${ | className={`c-btn ${ | ||||
| employmentType === "Work" | employmentType === "Work" | ||||
| ? "c-btn c-btn--primary" | ? "c-btn c-btn--primary" | ||||
| Posao | Posao | ||||
| </button> | </button> | ||||
| <button | <button | ||||
| data-testid="add-ad-modal-intership-btn" | |||||
| className={`c-btn ${ | className={`c-btn ${ | ||||
| employmentType === "Intership" | employmentType === "Intership" | ||||
| ? "c-btn c-btn--primary" | ? "c-btn c-btn--primary" | ||||
| <label>Radno vreme</label> | <label>Radno vreme</label> | ||||
| <div className="add-ad-modal-stage-sub-card-buttons"> | <div className="add-ad-modal-stage-sub-card-buttons"> | ||||
| <button | <button | ||||
| data-testid="add-ad-modal-parttime-btn" | |||||
| className={`c-btn ${ | className={`c-btn ${ | ||||
| workHour === "PartTime" | workHour === "PartTime" | ||||
| ? "c-btn c-btn--primary" | ? "c-btn c-btn--primary" | ||||
| Part-time | Part-time | ||||
| </button> | </button> | ||||
| <button | <button | ||||
| data-testid="add-ad-modal-fulltime-btn" | |||||
| className={`c-btn ${ | className={`c-btn ${ | ||||
| workHour === "FullTime" | workHour === "FullTime" | ||||
| ? "c-btn c-btn--primary" | ? "c-btn c-btn--primary" | ||||
| <div className="add-ad-modal-stage-sub-card"> | <div className="add-ad-modal-stage-sub-card"> | ||||
| <label>Datum isteka oglasa</label> | <label>Datum isteka oglasa</label> | ||||
| <input | <input | ||||
| data-testid="add-ad-modal-expired-at" | |||||
| type="date" | type="date" | ||||
| placeholder="ex" | placeholder="ex" | ||||
| value={expiredAt} | value={expiredAt} | ||||
| <div className="add-ad-modal-actions"> | <div className="add-ad-modal-actions"> | ||||
| <button | <button | ||||
| data-testid="add-ad-modal-go-back" | |||||
| className="c-btn c-btn--primary-outlined" | className="c-btn c-btn--primary-outlined" | ||||
| disabled | disabled | ||||
| onClick={onDecrementStage} | onClick={onDecrementStage} | ||||
| > | > | ||||
| NAZAD | NAZAD | ||||
| </button> | </button> | ||||
| <button className="c-btn c-btn--primary" onClick={completeStageHandler}> | |||||
| <button | |||||
| className="c-btn c-btn--primary" | |||||
| onClick={completeStageHandler} | |||||
| data-testid="add-ad-modal-go-forward" | |||||
| > | |||||
| NASTAVI | NASTAVI | ||||
| </button> | </button> | ||||
| </div> | </div> |
| setExperience, | setExperience, | ||||
| }) => { | }) => { | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const completeStageHandler = () => { | const completeStageHandler = () => { | ||||
| const checkedTechnologies = technologies.filter( | const checkedTechnologies = technologies.filter( | ||||
| (x) => x.isChecked === true | (x) => x.isChecked === true | ||||
| <Checkbox | <Checkbox | ||||
| value={x.name} | value={x.name} | ||||
| checked={x.isChecked} | checked={x.isChecked} | ||||
| className="add-ad-modal-technology" | |||||
| onChange={handleCheckboxes.bind(this, x.technologyId)} | onChange={handleCheckboxes.bind(this, x.technologyId)} | ||||
| /> | /> | ||||
| } | } | ||||
| type="number" | type="number" | ||||
| placeholder="ex. 3 godine iskustva" | placeholder="ex. 3 godine iskustva" | ||||
| value={experience} | value={experience} | ||||
| data-testid="add-ad-modal-experience" | |||||
| onChange={(e) => setExperience(e.target.value)} | onChange={(e) => setExperience(e.target.value)} | ||||
| /> | /> | ||||
| </div> | </div> | ||||
| <div className="add-ad-modal-actions"> | <div className="add-ad-modal-actions"> | ||||
| <button | <button | ||||
| className="c-btn c-btn--primary-outlined" | className="c-btn c-btn--primary-outlined" | ||||
| data-testid="add-ad-modal-second-go-back" | |||||
| onClick={onDecrementStage} | onClick={onDecrementStage} | ||||
| > | > | ||||
| NAZAD | NAZAD | ||||
| </button> | </button> | ||||
| <button className="c-btn c-btn--primary" onClick={completeStageHandler}> | |||||
| <button | |||||
| className="c-btn c-btn--primary" | |||||
| data-testid="add-ad-modal-second-go-forward" | |||||
| onClick={completeStageHandler} | |||||
| > | |||||
| NASTAVI | NASTAVI | ||||
| </button> | </button> | ||||
| </div> | </div> |
| FETCH_AD_SUCCESS, | FETCH_AD_SUCCESS, | ||||
| } from "../../actions/ad/adActionConstants"; | } from "../../actions/ad/adActionConstants"; | ||||
| import createReducer from "../../utils/createReducer"; | import createReducer from "../../utils/createReducer"; | ||||
| /* istanbul ignore file */ | |||||
| const initialState = { | const initialState = { | ||||
| ad: null, | ad: null, |
| FETCH_FILTERED_ADS_SUCCESS, | FETCH_FILTERED_ADS_SUCCESS, | ||||
| } from "../../actions/ads/adsActionConstants"; | } from "../../actions/ads/adsActionConstants"; | ||||
| import createReducer from "../../utils/createReducer"; | import createReducer from "../../utils/createReducer"; | ||||
| /* istanbul ignore file */ | |||||
| const initialState = { | const initialState = { | ||||
| ads: [], | ads: [], |
| ARCHIVE_ACTIVE_AD_ERR, | ARCHIVE_ACTIVE_AD_ERR, | ||||
| } from "../../actions/archiveActiveAd/archiveActiveAdActionConstants"; | } from "../../actions/archiveActiveAd/archiveActiveAdActionConstants"; | ||||
| import createReducer from "../../utils/createReducer"; | import createReducer from "../../utils/createReducer"; | ||||
| /* istanbul ignore file */ | |||||
| const initialState = { | const initialState = { | ||||
| errorMessage: "", | errorMessage: "", |
| FETCH_ARCHIVE_ADS_ERR, | FETCH_ARCHIVE_ADS_ERR, | ||||
| } from "../../actions/archiveAds/archiveAdsActionConstants"; | } from "../../actions/archiveAds/archiveAdsActionConstants"; | ||||
| import createReducer from "../../utils/createReducer"; | import createReducer from "../../utils/createReducer"; | ||||
| /* istanbul ignore file */ | |||||
| const initialState = { | const initialState = { | ||||
| archiveAds: [], | archiveAds: [], |
| CREATE_AD_ERR, | CREATE_AD_ERR, | ||||
| } from "../../actions/createAd/createAdActionConstants"; | } from "../../actions/createAd/createAdActionConstants"; | ||||
| import createReducer from "../../utils/createReducer"; | import createReducer from "../../utils/createReducer"; | ||||
| /* istanbul ignore file */ | |||||
| const initialState = { | const initialState = { | ||||
| ad: null, | ad: null, |
| DELETE_CANDIDATE_SUCCESS, | DELETE_CANDIDATE_SUCCESS, | ||||
| DELETE_CANDIDATE_ERROR | DELETE_CANDIDATE_ERROR | ||||
| } from "../../actions/candidate/candidateActionConstants"; | } from "../../actions/candidate/candidateActionConstants"; | ||||
| /* istanbul ignore file */ | |||||
| const initialState = { | const initialState = { | ||||
| candidate: {}, | candidate: {}, |
| CREATE_PATTERN_SUCCESS, | CREATE_PATTERN_SUCCESS, | ||||
| } from "../../actions/createPattern/createPatternActionConstants"; | } from "../../actions/createPattern/createPatternActionConstants"; | ||||
| import createReducer from "../../utils/createReducer"; | import createReducer from "../../utils/createReducer"; | ||||
| /* istanbul ignore file */ | |||||
| const initialState = { | const initialState = { | ||||
| pattern: null, | pattern: null, |
| FETCH_PATTERN_APPLICANTS_SUCCESS, | FETCH_PATTERN_APPLICANTS_SUCCESS, | ||||
| FETCH_PATTERN_APPLICANTS_ERR, | FETCH_PATTERN_APPLICANTS_ERR, | ||||
| } from "../../actions/patternApplicants/patternApplicantsActionConstants"; | } from "../../actions/patternApplicants/patternApplicantsActionConstants"; | ||||
| /* istanbul ignore file */ | |||||
| const initialState = { | const initialState = { | ||||
| patternApplicants: [], | patternApplicants: [], |
| FETCH_PATTERN_SUCCESS, | FETCH_PATTERN_SUCCESS, | ||||
| FETCH_PATTERN_ERR, | FETCH_PATTERN_ERR, | ||||
| } from "../../actions/pattern/patternActionConstants"; | } from "../../actions/pattern/patternActionConstants"; | ||||
| /* istanbul ignore file */ | |||||
| const initialState = { | const initialState = { | ||||
| pattern: null, | pattern: null, |
| FETCH_PATTERNS_SUCCESS, | FETCH_PATTERNS_SUCCESS, | ||||
| } from "../../actions/patterns/patternsActionConstants"; | } from "../../actions/patterns/patternsActionConstants"; | ||||
| import createReducer from "../../utils/createReducer"; | import createReducer from "../../utils/createReducer"; | ||||
| /* istanbul ignore file */ | |||||
| const initialState = { | const initialState = { | ||||
| patterns: [], | patterns: [], |
| CLEAR_NOT_SENT_EMAILS_ARRAY, | CLEAR_NOT_SENT_EMAILS_ARRAY, | ||||
| } from "../../actions/scheduleAppointment/scheduleAppointmentActionConstants"; | } from "../../actions/scheduleAppointment/scheduleAppointmentActionConstants"; | ||||
| import createReducer from "../../utils/createReducer"; | import createReducer from "../../utils/createReducer"; | ||||
| /* istanbul ignore file */ | |||||
| const initialState = { | const initialState = { | ||||
| notSentEmails: null, | notSentEmails: null, |
| UPDATE_PATTERN_SUCCESS, | UPDATE_PATTERN_SUCCESS, | ||||
| } from "../../actions/updatePattern/updatePatternActionConstants"; | } from "../../actions/updatePattern/updatePatternActionConstants"; | ||||
| import createReducer from "../../utils/createReducer"; | import createReducer from "../../utils/createReducer"; | ||||
| /* istanbul ignore file */ | |||||
| const initialState = { | const initialState = { | ||||
| pattern: null, | pattern: null, |