diff --git a/scm-ui/src/repos/branches/modules/branches.js b/scm-ui/src/repos/branches/modules/branches.js index 03c0c1a9eb..a080a3877f 100644 --- a/scm-ui/src/repos/branches/modules/branches.js +++ b/scm-ui/src/repos/branches/modules/branches.js @@ -41,7 +41,7 @@ export function fetchBranchPending(name: string): Action { }; } -export function fetchBranchSuccess(branch: Branch): Action { +export function fetchBranchSuccess(repo: Repository, branch: Branch): Action { return { type: FETCH_BRANCH_SUCCESS, payload: branch, diff --git a/scm-ui/src/repos/branches/modules/branches.test.js b/scm-ui/src/repos/branches/modules/branches.test.js index 754a3803e9..cc67aaf33a 100644 --- a/scm-ui/src/repos/branches/modules/branches.test.js +++ b/scm-ui/src/repos/branches/modules/branches.test.js @@ -1,5 +1,5 @@ import configureMockStore from "redux-mock-store"; -import thunk from "redux-thunk/index"; +import thunk from "redux-thunk"; import fetchMock from "fetch-mock"; import reducer, { FETCH_BRANCHES, @@ -161,6 +161,40 @@ describe("branches", () => { const newState = reducer({}, fetchBranchSuccess(branch3)); expect(newState["branch3"]).toBe(branch3); }); + + it("should not delete existing branch from state", () => { + const oldState = { + branch1 + }; + + const newState = reducer(oldState, fetchBranchSuccess(branch2)); + expect(newState["branch1"]).toBe(branch1); + expect(newState["branch2"]).toBe(branch2); + }); + + it("should update required branch from state", () => { + const oldState = { + branch1 + }; + + const newBranch1 = { name: "branch1", revision: "revision2" }; + + const newState = reducer(oldState, fetchBranchSuccess(newBranch1)); + expect(newState["branch1"]).not.toBe(branch1); + expect(newState["branch1"]).toBe(newBranch1); + }); + + it("should update required branch from state and keeps old repo", () => { + const oldState = { + repo1: { + branch1 + } + }; + const repo2 = { repo2: { branch3 } }; + const newState = reducer(oldState, fetchBranchSuccess(repo2, branch2)); + expect(newState["repo1"]).toBe({ branch1 }); + expect(newState["repo2"]).toBe({ branch2, branch3 }); + }); }); describe("branch selectors", () => {