Initial reducer tests
This commit is contained in:
parent
99140c6ece
commit
8e3ba08ad3
8 changed files with 348 additions and 4 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import _ from 'lodash';
|
||||
import {ChannelsTypes as types} from 'constants';
|
||||
|
||||
const initState = {
|
||||
export const initState = {
|
||||
status: 'not fetched',
|
||||
error: null,
|
||||
data: {},
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import {LoginTypes as types} from 'constants';
|
||||
|
||||
const initState = {
|
||||
export const initState = {
|
||||
status: 'not fetched',
|
||||
error: null
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import {PostsTypes as types} from 'constants';
|
||||
|
||||
const initState = {
|
||||
export const initState = {
|
||||
status: 'not fetched',
|
||||
error: null,
|
||||
data: {}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import {TeamsTypes as types} from 'constants';
|
||||
|
||||
const initState = {
|
||||
export const initState = {
|
||||
status: 'not fetched',
|
||||
error: null,
|
||||
data: {},
|
||||
|
|
|
|||
94
test/reducers/channels.test.js
Normal file
94
test/reducers/channels.test.js
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import assert from 'assert';
|
||||
import reduceChannels, {initState} from 'reducers/channels';
|
||||
import {ChannelsTypes as types} from 'constants';
|
||||
|
||||
describe('channels reducer', () => {
|
||||
describe('Init', () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceChannels(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.SELECT_CHANNEL}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceChannels(store, {
|
||||
type: types.SELECT_CHANNEL,
|
||||
channelId: '1'
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
currentChannelId: '1'
|
||||
};
|
||||
});
|
||||
it('should set status to fetching', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${types.FETCH_CHANNELS_REQUEST}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceChannels(store, {
|
||||
type: types.FETCH_CHANNELS_REQUEST
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
status: 'fetching'
|
||||
};
|
||||
});
|
||||
it('should set status to fetching', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${types.FETCH_CHANNELS_SUCCESS}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceChannels(store, {
|
||||
type: types.FETCH_CHANNELS_SUCCESS,
|
||||
data: {channels: [{id: '1', attr: 'attr'}]}
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
status: 'fetched',
|
||||
data: {1: {id: '1', attr: 'attr'}}
|
||||
};
|
||||
});
|
||||
it('should set status to fetched and data', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${types.FETCH_CHANNELS_FAILURE}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
let error;
|
||||
before(() => {
|
||||
error = {id: 'the.error.id', message: 'Something went wrong'};
|
||||
store = reduceChannels(store, {
|
||||
type: types.FETCH_CHANNELS_FAILURE,
|
||||
error
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
status: 'failed',
|
||||
error
|
||||
};
|
||||
});
|
||||
it('should set status to failed and error', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
});
|
||||
75
test/reducers/login.test.js
Normal file
75
test/reducers/login.test.js
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import assert from 'assert';
|
||||
import reduceLogin, {initState} from 'reducers/login';
|
||||
import {LoginTypes as types} from 'constants';
|
||||
|
||||
describe('login reducer', () => {
|
||||
describe('Init', () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceLogin(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.LOGIN_REQUEST}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceLogin(store, {
|
||||
type: types.LOGIN_REQUEST
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
status: 'fetching'
|
||||
};
|
||||
});
|
||||
it('should set status to fetching', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${types.LOGIN_SUCCESS}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceLogin(store, {
|
||||
type: types.LOGIN_SUCCESS
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
status: 'fetched'
|
||||
};
|
||||
});
|
||||
it('should set status to fetched and data', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${types.LOGIN_FAILURE}`, () => {
|
||||
let store;
|
||||
let error;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
error = {id: 'the.error.id', message: 'Something went wrong'};
|
||||
store = reduceLogin(store, {
|
||||
type: types.LOGIN_FAILURE,
|
||||
error
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
status: 'failed',
|
||||
error
|
||||
};
|
||||
});
|
||||
it('should set status to failed and error', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
});
|
||||
80
test/reducers/posts.test.js
Normal file
80
test/reducers/posts.test.js
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import assert from 'assert';
|
||||
import reducePosts, {initState} from 'reducers/posts';
|
||||
import {PostsTypes as types} from 'constants';
|
||||
|
||||
describe('posts reducer', () => {
|
||||
describe('Init', () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reducePosts(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.FETCH_POSTS_REQUEST}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reducePosts(store, {
|
||||
type: types.FETCH_POSTS_REQUEST
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
status: 'fetching'
|
||||
};
|
||||
});
|
||||
it('should set status to fetching', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${types.FETCH_POSTS_SUCCESS}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
const data = {id: '1', attrs: 'attrs'};
|
||||
before(() => {
|
||||
store = reducePosts(store, {
|
||||
type: types.FETCH_POSTS_SUCCESS,
|
||||
data: {
|
||||
posts: data
|
||||
}
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
status: 'fetched',
|
||||
data
|
||||
};
|
||||
});
|
||||
it('should set status to fetched and data', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${types.FETCH_POSTS_FAILURE}`, () => {
|
||||
let store;
|
||||
let error;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
error = {id: 'the.error.id', message: 'Something went wrong'};
|
||||
store = reducePosts(store, {
|
||||
type: types.FETCH_POSTS_FAILURE,
|
||||
error
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
status: 'failed',
|
||||
error
|
||||
};
|
||||
});
|
||||
it('should set status to failed and error', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
});
|
||||
95
test/reducers/teams.test.js
Normal file
95
test/reducers/teams.test.js
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import assert from 'assert';
|
||||
import reduceTeams, {initState} from 'reducers/teams';
|
||||
import {TeamsTypes as types} from 'constants';
|
||||
|
||||
describe('teams reducer', () => {
|
||||
describe('Init', () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceTeams(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.SELECT_TEAM}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceTeams(store, {
|
||||
type: types.SELECT_TEAM,
|
||||
teamId: '1'
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
currentTeamId: '1'
|
||||
};
|
||||
});
|
||||
it('should set status to fetching', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${types.FETCH_TEAMS_REQUEST}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceTeams(store, {
|
||||
type: types.FETCH_TEAMS_REQUEST
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
status: 'fetching'
|
||||
};
|
||||
});
|
||||
it('should set status to fetching', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${types.FETCH_TEAMS_SUCCESS}`, () => {
|
||||
let store;
|
||||
let data = {some: 'thing'};
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceTeams(store, {
|
||||
type: types.FETCH_TEAMS_SUCCESS,
|
||||
data
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
status: 'fetched',
|
||||
data
|
||||
};
|
||||
});
|
||||
it('should set status to fetched and data', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${types.FETCH_TEAMS_FAILURE}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
let error;
|
||||
before(() => {
|
||||
error = {id: 'the.error.id', message: 'Something went wrong'};
|
||||
store = reduceTeams(store, {
|
||||
type: types.FETCH_TEAMS_FAILURE,
|
||||
error
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
status: 'failed',
|
||||
error
|
||||
};
|
||||
});
|
||||
it('should set status to failed and error', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue