diff --git a/src/reducers/device.js b/src/reducers/device.js index 26762ae9f..be14f701a 100644 --- a/src/reducers/device.js +++ b/src/reducers/device.js @@ -3,8 +3,9 @@ import {handle, initialState} from './helpers.js'; import {DeviceTypes as types} from 'constants'; +export const initState = initialState(); -export default function device(state = initialState(), action) { +export default function device(state = initState, action) { return handle( types.DEVICE_REQUEST, types.DEVICE_SUCCESS, diff --git a/src/reducers/general.js b/src/reducers/general.js index 751f9c115..e4e1ca6af 100644 --- a/src/reducers/general.js +++ b/src/reducers/general.js @@ -5,7 +5,9 @@ import {combineReducers} from 'redux'; import {initialState, handle} from './helpers.js'; import {GeneralTypes as types} from 'constants'; -export function clientConfig(state = initialState(), action) { +export const initState = initialState(); + +export function clientConfig(state = initState, action) { return handle( types.CLIENT_CONFIG_REQUEST, types.CLIENT_CONFIG_SUCCESS, diff --git a/test/general.test.js b/test/general.test.js new file mode 100644 index 000000000..737de5cec --- /dev/null +++ b/test/general.test.js @@ -0,0 +1,170 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import assert from 'assert'; +import reduceGeneral, {initState} from 'reducers/general'; +import {GeneralTypes as types} from 'constants'; + +const combinedState = { + clientConfig: {...initState}, + ping: {...initState} +}; + +describe('general reducer', () => { + describe('PING', () => { + describe('Init', () => { + let store; + let expectedStore; + before(() => { + store = reduceGeneral(store, {type: ''}); + expectedStore = {...combinedState}; + }); + it('should be initial state', () => { + assert.equal(typeof store, 'object'); + }); + it('have a specifc initial state', () => { + assert.deepEqual(store, expectedStore); + }); + }); + describe(`when ${types.PING_REQUEST}`, () => { + let store; + let expectedStore; + before(() => { + store = reduceGeneral(store, { + type: types.PING_REQUEST + }); + expectedStore = { + ...combinedState, + ping: { + ...combinedState.ping, + loading: true + } + }; + }); + it('should set status to fetching', () => { + assert.deepEqual(store, expectedStore); + }); + }); + describe(`when ${types.PING_SUCCESS}`, () => { + let store; + let expectedStore; + const data = {some: 'data'}; + before(() => { + store = reduceGeneral(store, { + type: types.PING_SUCCESS, + data + }); + expectedStore = { + ...combinedState, + ping: { + ...combinedState.ping, + data + } + }; + }); + it('should set status to fetched and data', () => { + assert.deepEqual(store, expectedStore); + }); + }); + describe(`when ${types.PING_FAILURE}`, () => { + let store; + let error; + let expectedStore; + before(() => { + error = {id: 'the.error.id', message: 'Something went wrong'}; + store = reduceGeneral(store, { + type: types.PING_FAILURE, + error + }); + expectedStore = { + ...combinedState, + ping: { + ...combinedState.ping, + error + } + }; + }); + it('should set status to failed and error', () => { + assert.deepEqual(store, expectedStore); + }); + }); + }); + describe('CLIENT_CONFIG', () => { + describe('Init', () => { + let store; + let expectedStore; + before(() => { + store = reduceGeneral(store, {type: ''}); + expectedStore = {...combinedState}; + }); + it('should be initial state', () => { + assert.equal(typeof store, 'object'); + }); + it('have a specifc initial state', () => { + assert.deepEqual(store, expectedStore); + }); + }); + describe(`when ${types.CLIENT_CONFIG_REQUEST}`, () => { + let store; + let expectedStore; + before(() => { + store = reduceGeneral(store, { + type: types.CLIENT_CONFIG_REQUEST + }); + expectedStore = { + ...combinedState, + clientConfig: { + ...combinedState.clientConfig, + loading: true + } + }; + }); + it('should set status to fetching', () => { + assert.deepEqual(store, expectedStore); + }); + }); + describe(`when ${types.CLIENT_CONFIG_SUCCESS}`, () => { + let store; + let expectedStore; + const data = {some: 'data'}; + before(() => { + store = reduceGeneral(store, { + type: types.CLIENT_CONFIG_SUCCESS, + data + }); + expectedStore = { + ...combinedState, + clientConfig: { + ...combinedState.clientConfig, + data + } + }; + }); + it('should set status to fetched and data', () => { + assert.deepEqual(store, expectedStore); + }); + }); + describe(`when ${types.CLIENT_CONFIG_FAILURE}`, () => { + let store; + let error; + let expectedStore; + before(() => { + error = {id: 'the.error.id', message: 'Something went wrong'}; + store = reduceGeneral(store, { + type: types.CLIENT_CONFIG_FAILURE, + error + }); + expectedStore = { + ...combinedState, + clientConfig: { + ...combinedState.clientConfig, + error + } + }; + }); + it('should set status to failed and error', () => { + assert.deepEqual(store, expectedStore); + }); + }); + }); +}); diff --git a/test/reducers/device.test.js b/test/reducers/device.test.js new file mode 100644 index 000000000..1281891d4 --- /dev/null +++ b/test/reducers/device.test.js @@ -0,0 +1,78 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import assert from 'assert'; +import reduceDevice, {initState} from 'reducers/device'; +import {DeviceTypes as types} from 'constants'; + +describe('device reducer', () => { + describe('Init', () => { + let store; + let expectedStore; + before(() => { + store = reduceDevice(store, {type: ''}); + expectedStore = {...initState}; + }); + it('should be initial state', () => { + assert.equal(typeof store, 'object'); + }); + it('have a specifc initial state', () => { + assert.deepEqual(store, expectedStore); + }); + }); + describe(`when ${types.DEVICE_REQUEST}`, () => { + let store; + let expectedStore; + before(() => { + store = reduceDevice(store, { + type: types.DEVICE_REQUEST + }); + expectedStore = { + ...initState, + loading: true + }; + }); + it('should set status to fetching', () => { + assert.deepEqual(store, expectedStore); + }); + }); + describe(`when ${types.DEVICE_SUCCESS}`, () => { + let store; + let expectedStore; + const data = {some: 'data'}; + before(() => { + store = reduceDevice(store, { + type: types.DEVICE_SUCCESS, + data + }); + expectedStore = { + ...initState, + loading: false, + data + }; + }); + it('should set status to fetched and data', () => { + assert.deepEqual(store, expectedStore); + }); + }); + describe(`when ${types.DEVICE_FAILURE}`, () => { + let store; + let error; + let expectedStore; + before(() => { + error = {id: 'the.error.id', message: 'Something went wrong'}; + store = reduceDevice(store, { + type: types.DEVICE_FAILURE, + error + }); + expectedStore = { + ...initState, + loading: false, + error + }; + }); + it('should set status to failed and error', () => { + assert.deepEqual(store, expectedStore); + }); + }); +}); diff --git a/test/reducers/teams.test.js b/test/reducers/teams.test.js index 29dd00230..f6a93917a 100644 --- a/test/reducers/teams.test.js +++ b/test/reducers/teams.test.js @@ -55,7 +55,7 @@ describe('teams reducer', () => { }); describe(`when ${types.FETCH_TEAMS_SUCCESS}`, () => { let store; - let data = {some: 'thing'}; + const data = {some: 'thing'}; let expectedStore; before(() => { store = reduceTeams(store, {