mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 22:45:45 +01:00
implemented simplest reducer
This commit is contained in:
@@ -12,6 +12,7 @@ import auth from "./modules/auth";
|
|||||||
import pending from "./modules/pending";
|
import pending from "./modules/pending";
|
||||||
import failure from "./modules/failure";
|
import failure from "./modules/failure";
|
||||||
import config from "./config/modules/config";
|
import config from "./config/modules/config";
|
||||||
|
import indexResources from "./modules/indexResource";
|
||||||
|
|
||||||
import type { BrowserHistory } from "history/createBrowserHistory";
|
import type { BrowserHistory } from "history/createBrowserHistory";
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ function createReduxStore(history: BrowserHistory) {
|
|||||||
router: routerReducer,
|
router: routerReducer,
|
||||||
pending,
|
pending,
|
||||||
failure,
|
failure,
|
||||||
|
indexResources,
|
||||||
users,
|
users,
|
||||||
repos,
|
repos,
|
||||||
repositoryTypes,
|
repositoryTypes,
|
||||||
|
|||||||
@@ -53,3 +53,23 @@ export function fetchIndexResourcesFailure(err: Error): Action {
|
|||||||
payload: err
|
payload: err
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reducer
|
||||||
|
export default function reducer(
|
||||||
|
state: Object = {},
|
||||||
|
action: Action = { type: "UNKNOWN" }
|
||||||
|
): Object {
|
||||||
|
if (!action.payload) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (action.type) {
|
||||||
|
case FETCH_INDEXRESOURCES_SUCCESS:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
indexResources: action.payload
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
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_INDEXRESOURCES_PENDING,
|
FETCH_INDEXRESOURCES_PENDING,
|
||||||
FETCH_INDEXRESOURCES_SUCCESS,
|
FETCH_INDEXRESOURCES_SUCCESS,
|
||||||
FETCH_INDEXRESOURCES_FAILURE,
|
FETCH_INDEXRESOURCES_FAILURE,
|
||||||
fetchIndexResources
|
fetchIndexResources,
|
||||||
|
fetchIndexResourcesSuccess
|
||||||
} from "./indexResource";
|
} from "./indexResource";
|
||||||
|
|
||||||
const indexResourcesUnauthenticated = {
|
const indexResourcesUnauthenticated = {
|
||||||
@@ -119,3 +120,27 @@ describe("fetch index resource", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("index resources reducer", () => {
|
||||||
|
it("should return empty object, if state and action is undefined", () => {
|
||||||
|
expect(reducer()).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return the same state, if the action is undefined", () => {
|
||||||
|
const state = { x: true };
|
||||||
|
expect(reducer(state)).toBe(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return the same state, if the action is unknown to the reducer", () => {
|
||||||
|
const state = { x: true };
|
||||||
|
expect(reducer(state, { type: "EL_SPECIALE" })).toBe(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should store the index resources on FETCH_INDEXRESOURCES_SUCCESS", () => {
|
||||||
|
const newState = reducer(
|
||||||
|
{},
|
||||||
|
fetchIndexResourcesSuccess(indexResourcesAuthenticated)
|
||||||
|
);
|
||||||
|
expect(newState.indexResources).toBe(indexResourcesAuthenticated);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user