Cover general and device reducers
This commit is contained in:
parent
8e3ba08ad3
commit
31206b397b
5 changed files with 254 additions and 3 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
170
test/general.test.js
Normal file
170
test/general.test.js
Normal file
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
78
test/reducers/device.test.js
Normal file
78
test/reducers/device.test.js
Normal file
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -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, {
|
||||
|
|
|
|||
Loading…
Reference in a new issue