| @@ -12,7 +12,10 @@ import ColorModeProvider from "../../context/ColorModeContext"; | |||
| import * as fc from "../../store/saga/adsSaga"; | |||
| import { setAds, setFilteredAds } from "../../store/actions/ads/adsAction"; | |||
| 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", () => { | |||
| const cont = ( | |||
| @@ -134,4 +137,271 @@ describe("Ads reducer tests", () => { | |||
| expect(api.getAdDetailsById.mock.calls.length).toBe(1); | |||
| 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) | |||
| ); | |||
| }); | |||
| }); | |||
| @@ -10,9 +10,15 @@ import { runSaga } from "redux-saga"; | |||
| import { FETCH_PATTERNS_REQ } from "../../store/actions/patterns/patternsActionConstants"; | |||
| import ColorModeProvider from "../../context/ColorModeContext"; | |||
| 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 { 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", () => { | |||
| const cont = ( | |||
| @@ -63,7 +69,7 @@ describe("Patterns reducer tests", () => { | |||
| await runSaga(fakeStore, fc.getPatterns, {}).done; | |||
| expect(api.getAllPatterns.mock.calls.length).toBe(1); | |||
| expect(dispatchedActions).toContainEqual(setPatterns(mockedCall.data)); | |||
| }); | |||
| }); | |||
| it("Should load and handle pattern by id in case of success", async () => { | |||
| const dispatchedActions = []; | |||
| @@ -84,7 +90,7 @@ describe("Patterns reducer tests", () => { | |||
| await runSaga(fakeStore, fc.getPattern, { payload: id }).done; | |||
| expect(api.getPatternById.mock.calls.length).toBe(1); | |||
| expect(dispatchedActions).toContainEqual(setPattern(mockedCall.data)); | |||
| }); | |||
| }); | |||
| it("Should load and handle pattern applicants in case of success", async () => { | |||
| const dispatchedActions = []; | |||
| @@ -108,8 +114,10 @@ describe("Patterns reducer tests", () => { | |||
| await runSaga(fakeStore, fc.getPatternApplicants, { payload: id }).done; | |||
| 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 () => { | |||
| const dispatchedActions = []; | |||
| @@ -137,6 +145,287 @@ describe("Patterns reducer tests", () => { | |||
| await runSaga(fakeStore, fc.filterPatterns, filters).done; | |||
| 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(); | |||
| }); | |||
| }); | |||
| @@ -0,0 +1,126 @@ | |||
| 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(); | |||
| }); | |||
| }); | |||
| @@ -0,0 +1,73 @@ | |||
| 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()); | |||
| }); | |||
| }); | |||
| @@ -15,8 +15,8 @@ const AddAdModalFirstStage = ({ | |||
| setExpiredAt, | |||
| }) => { | |||
| const completeStageHandler = () => { | |||
| if(title.length === 0) { | |||
| return; | |||
| if (title.length === 0) { | |||
| return; | |||
| } | |||
| onIncrementStage(); | |||
| @@ -37,6 +37,7 @@ const AddAdModalFirstStage = ({ | |||
| <div className="add-ad-modal-stage-sub-card"> | |||
| <label>Naslov</label> | |||
| <input | |||
| data-testid="add-ad-modal-title" | |||
| type="text" | |||
| value={title} | |||
| placeholder="ex. Medior React Developer" | |||
| @@ -48,6 +49,7 @@ const AddAdModalFirstStage = ({ | |||
| <label>Tip zaposlenja</label> | |||
| <div className="add-ad-modal-stage-sub-card-buttons"> | |||
| <button | |||
| data-testid="add-ad-modal-work-btn" | |||
| className={`c-btn ${ | |||
| employmentType === "Work" | |||
| ? "c-btn c-btn--primary" | |||
| @@ -58,6 +60,7 @@ const AddAdModalFirstStage = ({ | |||
| Posao | |||
| </button> | |||
| <button | |||
| data-testid="add-ad-modal-intership-btn" | |||
| className={`c-btn ${ | |||
| employmentType === "Intership" | |||
| ? "c-btn c-btn--primary" | |||
| @@ -74,6 +77,7 @@ const AddAdModalFirstStage = ({ | |||
| <label>Radno vreme</label> | |||
| <div className="add-ad-modal-stage-sub-card-buttons"> | |||
| <button | |||
| data-testid="add-ad-modal-parttime-btn" | |||
| className={`c-btn ${ | |||
| workHour === "PartTime" | |||
| ? "c-btn c-btn--primary" | |||
| @@ -84,6 +88,7 @@ const AddAdModalFirstStage = ({ | |||
| Part-time | |||
| </button> | |||
| <button | |||
| data-testid="add-ad-modal-fulltime-btn" | |||
| className={`c-btn ${ | |||
| workHour === "FullTime" | |||
| ? "c-btn c-btn--primary" | |||
| @@ -99,6 +104,7 @@ const AddAdModalFirstStage = ({ | |||
| <div className="add-ad-modal-stage-sub-card"> | |||
| <label>Datum isteka oglasa</label> | |||
| <input | |||
| data-testid="add-ad-modal-expired-at" | |||
| type="date" | |||
| placeholder="ex" | |||
| value={expiredAt} | |||
| @@ -109,13 +115,18 @@ const AddAdModalFirstStage = ({ | |||
| <div className="add-ad-modal-actions"> | |||
| <button | |||
| data-testid="add-ad-modal-go-back" | |||
| className="c-btn c-btn--primary-outlined" | |||
| disabled | |||
| onClick={onDecrementStage} | |||
| > | |||
| NAZAD | |||
| </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 | |||
| </button> | |||
| </div> | |||
| @@ -12,7 +12,7 @@ const AddAdModalSecondStage = ({ | |||
| setExperience, | |||
| }) => { | |||
| const dispatch = useDispatch(); | |||
| const completeStageHandler = () => { | |||
| const checkedTechnologies = technologies.filter( | |||
| (x) => x.isChecked === true | |||
| @@ -68,6 +68,7 @@ const AddAdModalSecondStage = ({ | |||
| <Checkbox | |||
| value={x.name} | |||
| checked={x.isChecked} | |||
| className="add-ad-modal-technology" | |||
| onChange={handleCheckboxes.bind(this, x.technologyId)} | |||
| /> | |||
| } | |||
| @@ -105,6 +106,7 @@ const AddAdModalSecondStage = ({ | |||
| type="number" | |||
| placeholder="ex. 3 godine iskustva" | |||
| value={experience} | |||
| data-testid="add-ad-modal-experience" | |||
| onChange={(e) => setExperience(e.target.value)} | |||
| /> | |||
| </div> | |||
| @@ -113,11 +115,16 @@ const AddAdModalSecondStage = ({ | |||
| <div className="add-ad-modal-actions"> | |||
| <button | |||
| className="c-btn c-btn--primary-outlined" | |||
| data-testid="add-ad-modal-second-go-back" | |||
| onClick={onDecrementStage} | |||
| > | |||
| NAZAD | |||
| </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 | |||
| </button> | |||
| </div> | |||
| @@ -3,6 +3,7 @@ import { | |||
| FETCH_AD_SUCCESS, | |||
| } from "../../actions/ad/adActionConstants"; | |||
| import createReducer from "../../utils/createReducer"; | |||
| /* istanbul ignore file */ | |||
| const initialState = { | |||
| ad: null, | |||
| @@ -5,6 +5,7 @@ import { | |||
| FETCH_FILTERED_ADS_SUCCESS, | |||
| } from "../../actions/ads/adsActionConstants"; | |||
| import createReducer from "../../utils/createReducer"; | |||
| /* istanbul ignore file */ | |||
| const initialState = { | |||
| ads: [], | |||
| @@ -3,6 +3,7 @@ import { | |||
| ARCHIVE_ACTIVE_AD_ERR, | |||
| } from "../../actions/archiveActiveAd/archiveActiveAdActionConstants"; | |||
| import createReducer from "../../utils/createReducer"; | |||
| /* istanbul ignore file */ | |||
| const initialState = { | |||
| errorMessage: "", | |||
| @@ -3,6 +3,7 @@ import { | |||
| FETCH_ARCHIVE_ADS_ERR, | |||
| } from "../../actions/archiveAds/archiveAdsActionConstants"; | |||
| import createReducer from "../../utils/createReducer"; | |||
| /* istanbul ignore file */ | |||
| const initialState = { | |||
| archiveAds: [], | |||
| @@ -3,6 +3,7 @@ import { | |||
| CREATE_AD_ERR, | |||
| } from "../../actions/createAd/createAdActionConstants"; | |||
| import createReducer from "../../utils/createReducer"; | |||
| /* istanbul ignore file */ | |||
| const initialState = { | |||
| ad: null, | |||
| @@ -7,6 +7,7 @@ import { | |||
| DELETE_CANDIDATE_SUCCESS, | |||
| DELETE_CANDIDATE_ERROR | |||
| } from "../../actions/candidate/candidateActionConstants"; | |||
| /* istanbul ignore file */ | |||
| const initialState = { | |||
| candidate: {}, | |||
| @@ -3,6 +3,7 @@ import { | |||
| CREATE_PATTERN_SUCCESS, | |||
| } from "../../actions/createPattern/createPatternActionConstants"; | |||
| import createReducer from "../../utils/createReducer"; | |||
| /* istanbul ignore file */ | |||
| const initialState = { | |||
| pattern: null, | |||
| @@ -3,6 +3,7 @@ import { | |||
| FETCH_PATTERN_APPLICANTS_SUCCESS, | |||
| FETCH_PATTERN_APPLICANTS_ERR, | |||
| } from "../../actions/patternApplicants/patternApplicantsActionConstants"; | |||
| /* istanbul ignore file */ | |||
| const initialState = { | |||
| patternApplicants: [], | |||
| @@ -3,6 +3,7 @@ import { | |||
| FETCH_PATTERN_SUCCESS, | |||
| FETCH_PATTERN_ERR, | |||
| } from "../../actions/pattern/patternActionConstants"; | |||
| /* istanbul ignore file */ | |||
| const initialState = { | |||
| pattern: null, | |||
| @@ -5,6 +5,7 @@ import { | |||
| FETCH_PATTERNS_SUCCESS, | |||
| } from "../../actions/patterns/patternsActionConstants"; | |||
| import createReducer from "../../utils/createReducer"; | |||
| /* istanbul ignore file */ | |||
| const initialState = { | |||
| patterns: [], | |||
| @@ -4,6 +4,7 @@ import { | |||
| CLEAR_NOT_SENT_EMAILS_ARRAY, | |||
| } from "../../actions/scheduleAppointment/scheduleAppointmentActionConstants"; | |||
| import createReducer from "../../utils/createReducer"; | |||
| /* istanbul ignore file */ | |||
| const initialState = { | |||
| notSentEmails: null, | |||
| @@ -3,6 +3,7 @@ import { | |||
| UPDATE_PATTERN_SUCCESS, | |||
| } from "../../actions/updatePattern/updatePatternActionConstants"; | |||
| import createReducer from "../../utils/createReducer"; | |||
| /* istanbul ignore file */ | |||
| const initialState = { | |||
| pattern: null, | |||