mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
turned null actions in to classes
This commit is contained in:
@@ -7,19 +7,26 @@ import {
|
|||||||
HeaderToggleAction
|
HeaderToggleAction
|
||||||
} from "./header.actions";
|
} from "./header.actions";
|
||||||
|
|
||||||
describe("headerReducer", () => {
|
class NullAction extends HeaderCollapseAction {
|
||||||
let nullAction = new HeaderCollapseAction();
|
type = null;
|
||||||
nullAction.type = null;
|
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("headerReducer", () => {
|
||||||
it("should return the current state when no valid actions have been made", () => {
|
it("should return the current state when no valid actions have been made", () => {
|
||||||
const state = { navCollapsed: false };
|
const state = { navCollapsed: false };
|
||||||
const newState = headerReducer(state, nullAction);
|
const action = new NullAction();
|
||||||
|
const newState = headerReducer(state, action);
|
||||||
|
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should start with navCollapsed = true", () => {
|
it("should start with navCollapsed = true", () => {
|
||||||
const initialState = headerReducer(undefined, nullAction);
|
const action = new NullAction();
|
||||||
|
const initialState = headerReducer(undefined, action);
|
||||||
|
|
||||||
// The navigation starts collapsed
|
// The navigation starts collapsed
|
||||||
expect(initialState.navCollapsed).toEqual(true);
|
expect(initialState.navCollapsed).toEqual(true);
|
||||||
@@ -33,7 +40,7 @@ describe("headerReducer", () => {
|
|||||||
expect(newState.navCollapsed).toEqual(true);
|
expect(newState.navCollapsed).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should perform the COLLAPSE action without mutating the previous state", () => {
|
it("should perform the COLLAPSE action without affecting the previous state", () => {
|
||||||
const state = { navCollapsed: false };
|
const state = { navCollapsed: false };
|
||||||
deepFreeze(state);
|
deepFreeze(state);
|
||||||
|
|
||||||
@@ -52,7 +59,7 @@ describe("headerReducer", () => {
|
|||||||
expect(newState.navCollapsed).toEqual(false);
|
expect(newState.navCollapsed).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should perform the EXPAND action without mutating the previous state", () => {
|
it("should perform the EXPAND action without affecting the previous state", () => {
|
||||||
const state = { navCollapsed: true };
|
const state = { navCollapsed: true };
|
||||||
deepFreeze(state);
|
deepFreeze(state);
|
||||||
|
|
||||||
@@ -71,7 +78,7 @@ describe("headerReducer", () => {
|
|||||||
expect(state3.navCollapsed).toEqual(true);
|
expect(state3.navCollapsed).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should perform the TOGGLE action without mutating the previous state", () => {
|
it("should perform the TOGGLE action without affecting the previous state", () => {
|
||||||
const state = { navCollapsed: true };
|
const state = { navCollapsed: true };
|
||||||
deepFreeze(state);
|
deepFreeze(state);
|
||||||
|
|
||||||
|
@@ -2,19 +2,27 @@ import * as deepFreeze from "deep-freeze";
|
|||||||
import { hostWindowReducer } from "./host-window.reducer";
|
import { hostWindowReducer } from "./host-window.reducer";
|
||||||
import { HostWindowResizeAction } from "./host-window.actions";
|
import { HostWindowResizeAction } from "./host-window.actions";
|
||||||
|
|
||||||
|
class NullAction extends HostWindowResizeAction {
|
||||||
|
type = null;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super(0,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
describe('hostWindowReducer', () => {
|
describe('hostWindowReducer', () => {
|
||||||
let nullAction = new HostWindowResizeAction(0, 0);
|
|
||||||
nullAction.type = null;
|
|
||||||
|
|
||||||
it("should return the current state when no valid actions have been made", () => {
|
it("should return the current state when no valid actions have been made", () => {
|
||||||
const state = { width: 800, height: 600 };
|
const state = { width: 800, height: 600 };
|
||||||
const newState = hostWindowReducer(state, nullAction);
|
const action = new NullAction();
|
||||||
|
const newState = hostWindowReducer(state, action);
|
||||||
|
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should start with width = null and height = null", () => {
|
it("should start with width = null and height = null", () => {
|
||||||
const initialState = hostWindowReducer(undefined, nullAction);
|
const action = new NullAction();
|
||||||
|
const initialState = hostWindowReducer(undefined, action);
|
||||||
|
|
||||||
expect(initialState.width).toEqual(null);
|
expect(initialState.width).toEqual(null);
|
||||||
expect(initialState.height).toEqual(null);
|
expect(initialState.height).toEqual(null);
|
||||||
@@ -29,7 +37,7 @@ describe('hostWindowReducer', () => {
|
|||||||
expect(newState.height).toEqual(768);
|
expect(newState.height).toEqual(768);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should perform the RESIZE action without mutating the previous state", () => {
|
it("should perform the RESIZE action without affecting the previous state", () => {
|
||||||
const state = { width: 800, height: 600 };
|
const state = { width: 800, height: 600 };
|
||||||
deepFreeze(state);
|
deepFreeze(state);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user