added branch reducer tests

This commit is contained in:
Florian Scholdei
2019-04-02 10:27:00 +02:00
parent db0a835bca
commit e736add3fd
2 changed files with 36 additions and 2 deletions

View File

@@ -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,

View File

@@ -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", () => {