Fixed unit test

This commit is contained in:
Philipp Czora
2018-10-04 19:03:03 +02:00
parent 11d1575265
commit 1f0fea37a9
2 changed files with 7 additions and 32 deletions

View File

@@ -1,9 +1,5 @@
// @flow // @flow
import { import {FAILURE_SUFFIX, PENDING_SUFFIX, SUCCESS_SUFFIX} from "../../modules/types";
FAILURE_SUFFIX,
PENDING_SUFFIX,
SUCCESS_SUFFIX
} from "../../modules/types";
import {apiClient} from "@scm-manager/ui-components"; import {apiClient} from "@scm-manager/ui-components";
import type {Repository} from "@scm-manager/ui-types"; import type {Repository} from "@scm-manager/ui-types";
@@ -82,7 +78,8 @@ export default function reducer(
): Object { ): Object {
switch (action.type) { switch (action.type) {
case FETCH_BRANCHES_SUCCESS: case FETCH_BRANCHES_SUCCESS:
const key = action.itemId; const { namespace, name } = action.payload.repository;
const key = `${namespace}/${name}`;
let oldBranchesByNames = { [key]: {} }; let oldBranchesByNames = { [key]: {} };
if (state[key] !== undefined) { if (state[key] !== undefined) {
oldBranchesByNames[key] = state[key]; oldBranchesByNames[key] = state[key];

View File

@@ -1,14 +1,13 @@
import configureMockStore from "redux-mock-store"; import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk"; import thunk from "redux-thunk";
import fetchMock from "fetch-mock"; import fetchMock from "fetch-mock";
import { import reducer, {
FETCH_BRANCHES_FAILURE, FETCH_BRANCHES_FAILURE,
FETCH_BRANCHES_PENDING, FETCH_BRANCHES_PENDING,
FETCH_BRANCHES_SUCCESS, FETCH_BRANCHES_SUCCESS,
fetchBranches, fetchBranches,
getBranchNames getBranchNames
} from "./branches"; } from "./branches";
import reducer from "./branches";
const namespace = "foo"; const namespace = "foo";
const name = "bar"; const name = "bar";
@@ -96,8 +95,7 @@ describe("branches", () => {
const action = { const action = {
type: FETCH_BRANCHES_SUCCESS, type: FETCH_BRANCHES_SUCCESS,
payload: { payload: {
namespace, repository,
name,
data: branches data: branches
} }
}; };
@@ -120,7 +118,6 @@ describe("branches", () => {
}; };
const newState = reducer(oldState, action); const newState = reducer(oldState, action);
console.log(newState);
expect(newState[key].byNames["branch1"]).toEqual(branch1); expect(newState[key].byNames["branch1"]).toEqual(branch1);
expect(newState[key].byNames["branch2"]).toEqual(branch2); expect(newState[key].byNames["branch2"]).toEqual(branch2);
expect(newState[key].byNames["branch3"]).toEqual(branch3); expect(newState[key].byNames["branch3"]).toEqual(branch3);
@@ -128,25 +125,6 @@ describe("branches", () => {
}); });
describe("branch selectors", () => { describe("branch selectors", () => {
it("should get branches for namespace and name", () => {
const state = {
branches: {
[key]: {
byNames: {
branch1: branch1
}
}
}
};
const branches = getBranchesForNamespaceAndNameFromState(
namespace,
name,
state
);
expect(branches.length).toEqual(1);
expect(branches[0]).toEqual(branch1);
});
it("should return branches names", () => { it("should return branches names", () => {
const state = { const state = {
branches: { branches: {