| /******************************************************************************** |
| * Copyright (c) 2020 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0 |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| ********************************************************************************/ |
| |
| import {IAPIProcessTask} from "../../../core/api/process"; |
| import {TStoreEntities} from "../../../util/store"; |
| import {deleteTaskAction, setTasksAction} from "../actions"; |
| import {statementTaskReducer} from "./statement-tasks.reducer"; |
| |
| describe("statementTaskReducer", () => { |
| |
| it("should set the taskids to the given statementid to the state", () => { |
| |
| const actionPayload = {statementId: "1"} as unknown as { statementId: number, tasks: IAPIProcessTask[] }; |
| let initialState: TStoreEntities<string[]> = {}; |
| let action = setTasksAction(actionPayload); |
| let state = statementTaskReducer(initialState, action); |
| expect(state).toEqual(initialState); |
| |
| action = setTasksAction(undefined); |
| state = statementTaskReducer(initialState, action); |
| expect(state).toEqual(initialState); |
| |
| actionPayload.statementId = 1; |
| actionPayload.tasks = [ |
| { |
| statementId: 1, |
| taskId: "taskId" |
| }, |
| { |
| statementId: 2, |
| taskId: "taskId2" |
| } |
| ] as IAPIProcessTask[]; |
| action = setTasksAction(actionPayload); |
| state = statementTaskReducer(initialState, action); |
| expect(state).toEqual({1: ["taskId"]}); |
| |
| initialState = state; |
| actionPayload.statementId = 2; |
| action = setTasksAction(actionPayload); |
| state = statementTaskReducer(initialState, action); |
| expect(state).toEqual({1: ["taskId"], 2: ["taskId2"]}); |
| |
| initialState = {}; |
| actionPayload.statementId = 1; |
| actionPayload.tasks = {} as IAPIProcessTask[]; |
| action = setTasksAction(actionPayload); |
| state = statementTaskReducer(initialState, action); |
| expect(state).toEqual({1: undefined}); |
| }); |
| |
| it("should delete the taskid for the given statementid from the state", () => { |
| |
| const actionPayload = {statementId: "1", taskId: "taskId"} as unknown as { statementId: number, taskId: string }; |
| let initialState: TStoreEntities<string[]> = {}; |
| let action = deleteTaskAction(actionPayload); |
| let state = statementTaskReducer(initialState, action); |
| expect(state).toEqual(initialState); |
| |
| actionPayload.statementId = 1; |
| actionPayload.taskId = {} as string; |
| action = deleteTaskAction(actionPayload); |
| state = statementTaskReducer(initialState, action); |
| expect(state).toEqual(initialState); |
| |
| initialState = {1: ["taskId"], 2: ["taskId2"]}; |
| actionPayload.statementId = 1; |
| actionPayload.taskId = "taskId"; |
| action = deleteTaskAction(actionPayload); |
| state = statementTaskReducer(initialState, action); |
| expect(state).toEqual({1: undefined, 2: ["taskId2"]}); |
| |
| initialState = state; |
| actionPayload.statementId = 2; |
| actionPayload.taskId = "taskId2"; |
| action = deleteTaskAction(actionPayload); |
| state = statementTaskReducer(initialState, action); |
| expect(state).toEqual({1: undefined, 2: undefined}); |
| |
| initialState = {1: ["taskId"], 2: ["taskId2"]}; |
| actionPayload.statementId = 1; |
| actionPayload.taskId = "wrongTaskId"; |
| action = deleteTaskAction(actionPayload); |
| state = statementTaskReducer(initialState, action); |
| expect(state).toEqual(initialState); |
| |
| initialState = {1: ["taskId"], 2: ["taskId2"]}; |
| actionPayload.statementId = 3; |
| actionPayload.taskId = "taskId"; |
| action = deleteTaskAction(actionPayload); |
| state = statementTaskReducer(initialState, action); |
| expect(state).toEqual({...initialState, 3: undefined}); |
| }); |
| |
| }); |