From 5a15396ce4755748d4dca998c48e95a84d200c7b Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Wed, 29 Nov 2017 10:01:12 +0100 Subject: [PATCH] Add reducer test --- frontend/src/__mocks__/react-mdl.js | 40 +++++++++---------- frontend/src/store/api/__tests__/.eslintrc | 5 +++ .../store/api/__tests__/api-store-tests.js | 18 +++++++++ 3 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 frontend/src/store/api/__tests__/.eslintrc create mode 100644 frontend/src/store/api/__tests__/api-store-tests.js diff --git a/frontend/src/__mocks__/react-mdl.js b/frontend/src/__mocks__/react-mdl.js index 9563ea7159..04e07f153d 100644 --- a/frontend/src/__mocks__/react-mdl.js +++ b/frontend/src/__mocks__/react-mdl.js @@ -1,22 +1,22 @@ module.exports = { - Card: "react-mdl-Card", - CardTitle: "react-mdl-CardTitle", - CardText: "react-mdl-CardText", - CardMenu: "react-mdl-CardMenu", - DataTable: "react-mdl-DataTable", - Cell: "react-mdl-Cell", - Grid: "react-mdl-Grid", - Icon: "react-mdl-Icon", - IconButton: "react-mdl-IconButton", - List: "react-mdl-List", - ListItem: "react-mdl-ListItem", - ListItemContent: "react-mdl-ListItemContent", - ProgressBar: "react-mdl-ProgressBar", - Switch: "react-mdl-Switch", - Tab: "react-mdl-Tab", - Tabs: "react-mdl-Tabs", - TableHeader: "react-mdl-TableHeader", - Textfield: "react-mdl-Textfield", - FooterSection: "react-mdl-FooterSection", - FooterLinkList: "react-mdl-FooterLinkList" + Card: 'react-mdl-Card', + CardTitle: 'react-mdl-CardTitle', + CardText: 'react-mdl-CardText', + CardMenu: 'react-mdl-CardMenu', + DataTable: 'react-mdl-DataTable', + Cell: 'react-mdl-Cell', + Grid: 'react-mdl-Grid', + Icon: 'react-mdl-Icon', + IconButton: 'react-mdl-IconButton', + List: 'react-mdl-List', + ListItem: 'react-mdl-ListItem', + ListItemContent: 'react-mdl-ListItemContent', + ProgressBar: 'react-mdl-ProgressBar', + Switch: 'react-mdl-Switch', + Tab: 'react-mdl-Tab', + Tabs: 'react-mdl-Tabs', + TableHeader: 'react-mdl-TableHeader', + Textfield: 'react-mdl-Textfield', + FooterSection: 'react-mdl-FooterSection', + FooterLinkList: 'react-mdl-FooterLinkList', }; diff --git a/frontend/src/store/api/__tests__/.eslintrc b/frontend/src/store/api/__tests__/.eslintrc new file mode 100644 index 0000000000..eba2077219 --- /dev/null +++ b/frontend/src/store/api/__tests__/.eslintrc @@ -0,0 +1,5 @@ +{ + "env": { + "jest": true + } +} diff --git a/frontend/src/store/api/__tests__/api-store-tests.js b/frontend/src/store/api/__tests__/api-store-tests.js new file mode 100644 index 0000000000..93140f8d2d --- /dev/null +++ b/frontend/src/store/api/__tests__/api-store-tests.js @@ -0,0 +1,18 @@ +import apiReducer from '../index'; +import { RECIEVE_API_DETAILS } from '../actions'; + +test('should have inital state', () => { + const store = apiReducer(undefined, {}); + expect(store.toJS()).toEqual({}); +}); + +test('should have new state', () => { + const store = apiReducer(undefined, { type: RECIEVE_API_DETAILS, value: { version: '1.1.1' } }); + expect(store.toJS()).toEqual({ version: '1.1.1' }); +}); + +test('should have updated state', () => { + const inital = apiReducer(undefined, { type: RECIEVE_API_DETAILS, value: { version: '1.1.1' } }); + const store = apiReducer(inital, { type: RECIEVE_API_DETAILS, value: { version: '1.2.1' } }); + expect(store.toJS()).toEqual({ version: '1.2.1' }); +});