mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 15:03:07 +00:00
added tests for headerReducer and HeaderActions
This commit is contained in:
@@ -103,6 +103,7 @@
|
||||
"@types/body-parser": "0.0.33",
|
||||
"@types/compression": "0.0.33",
|
||||
"@types/cookie-parser": "1.3.30",
|
||||
"@types/deep-freeze": "0.0.29",
|
||||
"@types/express": "4.0.34",
|
||||
"@types/express-serve-static-core": "4.0.39",
|
||||
"@types/hammerjs": "2.0.33",
|
||||
@@ -123,6 +124,7 @@
|
||||
"cookie-parser": "1.4.3",
|
||||
"copy-webpack-plugin": "4.0.1",
|
||||
"css-loader": "^0.26.0",
|
||||
"deep-freeze": "0.0.1",
|
||||
"html-webpack-plugin": "^2.21.0",
|
||||
"imports-loader": "0.7.0",
|
||||
"istanbul-instrumenter-loader": "^0.2.0",
|
||||
|
22
src/app/header/header.actions.spec.ts
Normal file
22
src/app/header/header.actions.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { HeaderActions } from "./header.actions";
|
||||
describe("HeaderActions", () => {
|
||||
|
||||
describe("collapse", () => {
|
||||
it("should return a COLLAPSE action", () => {
|
||||
expect(HeaderActions.collapse().type).toEqual(HeaderActions.COLLAPSE);
|
||||
});
|
||||
});
|
||||
|
||||
describe("expand", () => {
|
||||
it("should return an EXPAND action", () => {
|
||||
expect(HeaderActions.expand().type).toEqual(HeaderActions.EXPAND);
|
||||
});
|
||||
});
|
||||
|
||||
describe("toggle", () => {
|
||||
it("should return a TOGGLE action", () => {
|
||||
expect(HeaderActions.toggle().type).toEqual(HeaderActions.TOGGLE);
|
||||
});
|
||||
})
|
||||
|
||||
});
|
76
src/app/header/header.reducer.spec.ts
Normal file
76
src/app/header/header.reducer.spec.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import * as deepFreeze from "deep-freeze";
|
||||
|
||||
import { headerReducer } from "./header.reducer";
|
||||
import { HeaderActions } from "./header.actions";
|
||||
|
||||
describe("headerReducer", () => {
|
||||
|
||||
it("should return the current state when no valid actions have been made", () => {
|
||||
const state = { navCollapsed: false };
|
||||
const newState = headerReducer(state, {type: 'undefined-action'});
|
||||
|
||||
expect(newState).toEqual(state);
|
||||
});
|
||||
|
||||
it("should start with navCollapsed = true", () => {
|
||||
const initialState = headerReducer(undefined, {type: 'undefined-action'});
|
||||
|
||||
// The navigation starts collapsed
|
||||
expect(initialState.navCollapsed).toEqual(true);
|
||||
});
|
||||
|
||||
it("should set navCollapsed to true in response to the COLLAPSE action", () => {
|
||||
const state = { navCollapsed: false };
|
||||
const action = HeaderActions.collapse();
|
||||
const newState = headerReducer(state, action);
|
||||
|
||||
expect(newState.navCollapsed).toEqual(true);
|
||||
});
|
||||
|
||||
it("should perform the COLLAPSE action without mutating the previous state", () => {
|
||||
const state = { navCollapsed: false };
|
||||
deepFreeze(state);
|
||||
|
||||
const action = HeaderActions.collapse();
|
||||
headerReducer(state, action);
|
||||
|
||||
//no expect required, deepFreeze will ensure an exception is thrown if the state
|
||||
//is mutated, and any uncaught exception will cause the test to fail
|
||||
});
|
||||
|
||||
it("should set navCollapsed to false in response to the EXPAND action", () => {
|
||||
const state = { navCollapsed: true };
|
||||
const action = HeaderActions.expand();
|
||||
const newState = headerReducer(state, action);
|
||||
|
||||
expect(newState.navCollapsed).toEqual(false);
|
||||
});
|
||||
|
||||
it("should perform the EXPAND action without mutating the previous state", () => {
|
||||
const state = { navCollapsed: true };
|
||||
deepFreeze(state);
|
||||
|
||||
const action = HeaderActions.expand();
|
||||
headerReducer(state, action);
|
||||
});
|
||||
|
||||
it("should flip the value of navCollapsed in response to the TOGGLE action", () => {
|
||||
const state1 = { navCollapsed: true };
|
||||
const action = HeaderActions.toggle();
|
||||
|
||||
const state2 = headerReducer(state1, action);
|
||||
const state3 = headerReducer(state2, action);
|
||||
|
||||
expect(state2.navCollapsed).toEqual(false);
|
||||
expect(state3.navCollapsed).toEqual(true);
|
||||
});
|
||||
|
||||
it("should perform the TOGGLE action without mutating the previous state", () => {
|
||||
const state = { navCollapsed: true };
|
||||
deepFreeze(state);
|
||||
|
||||
const action = HeaderActions.toggle();
|
||||
headerReducer(state, action);
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user