| /******************************************************************************** |
| * 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 {fetchStatementDetailsAction, setStatementDetails} from "../actions"; |
| import {statementEntitiesReducer} from "./statement-entities.reducer"; |
| |
| describe("statementEntitiesReducer", () => { |
| |
| it("should not affect state on fetch action", () => { |
| const initialState = {}; |
| const action = fetchStatementDetailsAction({statementId: 19}); |
| const state = statementEntitiesReducer(initialState, action); |
| expect(state).toBe(initialState); |
| }); |
| |
| it("should create new entity of statement on set action", () => { |
| const initialState = {}; |
| const entity = {info: {} as any}; |
| const action = setStatementDetails({statementId: 19, details: entity}); |
| const state = statementEntitiesReducer(initialState, action); |
| expect(state).toEqual({ |
| 19: { |
| info: {} as any |
| } |
| }); |
| }); |
| |
| it("should update entity of statement on set action", () => { |
| const initialState = {18: {} as any, 19: {workflow: {} as any}}; |
| const entity = {info: {}} as any; |
| const action = setStatementDetails({statementId: 19, details: entity}); |
| const state = statementEntitiesReducer(initialState, action); |
| expect(state).toEqual({ |
| 18: {}, |
| 19: { |
| info: {} as any, |
| workflow: {} as any |
| } |
| }); |
| }); |
| |
| it("should not change state without any id", () => { |
| const initialState = {18: {} as any, 19: {workflow: {} as any}}; |
| const action = setStatementDetails({statementId: undefined, details: {}}); |
| let state = statementEntitiesReducer(initialState, action); |
| expect(state).toEqual(initialState); |
| state = statementEntitiesReducer(initialState, {type: "SpecAction"}); |
| expect(state).toEqual(initialState); |
| }); |
| |
| }); |