Преглед на файлове

added tests

pull/167/head
meris.ahmatovic преди 3 години
родител
ревизия
be94fda037
променени са 2 файла, в които са добавени 299 реда и са изтрити 1 реда
  1. 299
    0
      src/__tests__/ReduxTests/processesReducer.test.js
  2. 0
    1
      src/components/MUI/StatusDialog.js

+ 299
- 0
src/__tests__/ReduxTests/processesReducer.test.js Целия файл

@@ -13,12 +13,23 @@ import history from "../../store/utils/history";
import {
getProcesses,
getFilteredProcesses,
finishProcess,
changeStatus,
changeInterviewer,
} from "../../store/saga/processSaga";
import {
setProcesses,
setProcessesError,
} from "../../store/actions/processes/processesAction";
import { SelectionProvider } from "../../context/SelectionContext";
import {
setDoneProcess,
setDoneProcessError,
setUpdateInterviewerErr,
setUpdateInterviewerSucc,
setUpdateStatusErr,
setUpdateStatusSucc,
} from "../../store/actions/processes/processAction";

describe("SelectionProcessPage render tests", () => {
const cont = (
@@ -184,4 +195,292 @@ describe("SelectionProcessPage render tests", () => {
expect(api.getAllFilteredProcessesReq.mock.calls.length).toBe(1);
expect(dispatchedActions).toContainEqual(setProcesses(filteredData));
});

it("should handle process to set it done in case of finish success", async () => {
const dispatchedActions = [];
const mockedCall = { data: { isSuccess: true } };
api.doneProcess = jest.fn(() => Promise.resolve(mockedCall));

const fakeStore = {
getState: () => mockState.selections.processes,
dispatch: (action) => dispatchedActions.push(action),
};

// wait for saga to complete
await runSaga(fakeStore, finishProcess, {
payload: {
id: 1,
name: "Some random name",
applicantId: 5,
schedulerId: 10,
},
}).done;

expect(api.doneProcess.mock.calls.length).toBe(1);
expect(dispatchedActions).toContainEqual(setDoneProcess(mockedCall.data));
});

it("should handle error in case of finish process exception", async () => {
const dispatchedActions = [];

const error = {
response: {
data: { message: mockState.selections.fetchSelectionsErrorMessage },
},
};
api.doneProcess = jest.fn(() => Promise.reject(error));

const fakeStore = {
getState: () => mockState.selections.processes,
dispatch: (action) => dispatchedActions.push(action),
};

// wait for saga to complete
await runSaga(fakeStore, finishProcess, {
payload: {
id: 1,
name: "Some random name",
applicantId: 5,
schedulerId: 10,
},
}).done;

expect(api.doneProcess.mock.calls.length).toBe(1);
expect(dispatchedActions).toContainEqual(
setDoneProcessError(error.response.data.message)
);
});

it("should handle process status update", async () => {
const dispatchedActions = [];
const mockedCall = { data: { isSuccess: true } };
api.updateStatus = jest.fn(() => Promise.resolve(mockedCall));

const fakeStore = {
getState: () => mockState.selections.processes,
dispatch: (action) => dispatchedActions.push(action),
};

// wait for saga to complete
await runSaga(fakeStore, changeStatus, {
payload: {
data: {
schedulerId: 3,
appointment: "22-10-2023",
newStatus: "Odrađen",
processId: 1,
},
},
}).done;

expect(api.updateStatus.mock.calls.length).toBe(1);
expect(dispatchedActions).toContainEqual(setUpdateStatusSucc());
});

it("should call responsehandler while handling process status update", async () => {
const dispatchedActions = [];
const mockedCall = { data: { isSuccess: true } };
api.updateStatus = jest.fn(() => Promise.resolve(mockedCall));

const mockfn = jest.fn();

const fakeStore = {
getState: () => mockState.selections.processes,
dispatch: (action) => dispatchedActions.push(action),
};

// wait for saga to complete
await runSaga(fakeStore, changeStatus, {
payload: {
data: {
schedulerId: 3,
appointment: "22-10-2023",
newStatus: "Odrađen",
processId: 1,
},
responseHandler: mockfn,
},
}).done;

expect(mockfn).toHaveBeenCalled();
});

it("should handle process status update error if exception is thrown", async () => {
const dispatchedActions = [];
const error = {
response: {
data: { message: mockState.selections.fetchSelectionsErrorMessage },
},
};
api.updateStatus = jest.fn(() => Promise.reject(error));

const fakeStore = {
getState: () => mockState.selections.processes,
dispatch: (action) => dispatchedActions.push(action),
};

// wait for saga to complete
await runSaga(fakeStore, changeStatus, {
payload: {
data: {
schedulerId: 3,
appointment: "22-10-2023",
newStatus: "Odrađen",
processId: 1,
},
},
}).done;

expect(api.updateStatus.mock.calls.length).toBe(1);
expect(dispatchedActions).toContainEqual(
setUpdateStatusErr(error.response.data.message)
);
});

it("should not call responseHandler if exception is thrown", async () => {
const dispatchedActions = [];
const error = {
response: {
data: { message: mockState.selections.fetchSelectionsErrorMessage },
},
};
api.updateStatus = jest.fn(() => Promise.reject(error));

const mockfn = jest.fn();

const fakeStore = {
getState: () => mockState.selections.processes,
dispatch: (action) => dispatchedActions.push(action),
};

// wait for saga to complete
await runSaga(fakeStore, changeStatus, {
payload: {
data: {
schedulerId: 3,
appointment: "22-10-2023",
newStatus: "Odrađen",
processId: 1,
},
responseHandler: mockfn,
},
}).done;

expect(mockfn).not.toHaveBeenCalled();
});

it("should handle interviewer update", async () => {
const dispatchedActions = [];
const mockedCall = { data: { isSuccess: true } };
api.updateInterviewer = jest.fn(() => Promise.resolve(mockedCall));

const fakeStore = {
getState: () => mockState.selections.processes,
dispatch: (action) => dispatchedActions.push(action),
};

// wait for saga to complete
await runSaga(fakeStore, changeInterviewer, {
payload: {
data: {
schedulerId: 1,
processId: 2,
},
// responseHandler: apiSuccess,
}
}).done;

expect(api.updateInterviewer.mock.calls.length).toBe(1);
expect(dispatchedActions).toContainEqual(setUpdateInterviewerSucc());
});

it("should call response handler on change success", async () => {
const dispatchedActions = [];
const mockedCall = { data: { isSuccess: true } };
api.updateInterviewer = jest.fn(() => Promise.resolve(mockedCall));

const fakeStore = {
getState: () => mockState.selections.processes,
dispatch: (action) => dispatchedActions.push(action),
};

const mockfn = jest.fn()

// wait for saga to complete
await runSaga(fakeStore, changeInterviewer, {
payload: {
data: {
schedulerId: 1,
processId: 2,
},
responseHandler: mockfn,
}
}).done;

expect(mockfn).toHaveBeenCalled();
});

it("should handle interviewer update error if exception is thrown", async () => {
const dispatchedActions = [];
const error = {
response: {
data: { message: mockState.selections.fetchSelectionsErrorMessage },
},
};
api.updateInterviewer = jest.fn(() => Promise.reject(error));

const fakeStore = {
getState: () => mockState.selections.processes,
dispatch: (action) => dispatchedActions.push(action),
};

// wait for saga to complete
await runSaga(fakeStore, changeInterviewer, {
payload: {
data: {
schedulerId: 1,
processId: 2,
},
// responseHandler: mockfn,
}
}).done;

expect(api.updateInterviewer.mock.calls.length).toBe(1);
expect(dispatchedActions).toContainEqual(
setUpdateInterviewerErr(error.response.data.message)
);
});

it("should not call response handler if exception is thrown", async () => {
const dispatchedActions = [];
const error = {
response: {
data: { message: mockState.selections.fetchSelectionsErrorMessage },
},
};
api.updateInterviewer = jest.fn(() => Promise.reject(error));

const mockfn = jest.fn()

const fakeStore = {
getState: () => mockState.selections.processes,
dispatch: (action) => dispatchedActions.push(action),
};

// wait for saga to complete
await runSaga(fakeStore, changeInterviewer, {
payload: {
data: {
schedulerId: 1,
processId: 2,
},
responseHandler: mockfn,
}
}).done;

expect(mockfn).not.toHaveBeenCalled();
});
});

+ 0
- 1
src/components/MUI/StatusDialog.js Целия файл

@@ -83,7 +83,6 @@ const StatusDialog = ({
};

const submitHandler = () => {
console.log(selected);
if (activeProcess.process.selectionLevelId !== 2) {
dispatch(
setUpdateStatusReq({

Loading…
Отказ
Запис