mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-19 22:16:33 +02:00
Group reducer tests
This commit is contained in:
parent
b9750e3c83
commit
c63b9ff439
|
@ -1,9 +1,67 @@
|
|||
import { expect } from 'chai';
|
||||
// import * as actions from '../actions/actions';
|
||||
import groups, { defaultState } from './groups';
|
||||
|
||||
describe('groups reducer', () => {
|
||||
it('should return same state when no action matches', () => {
|
||||
expect(groups(defaultState, {})).to.equal(defaultState);
|
||||
});
|
||||
|
||||
describe('ADD_GROUP', () => {
|
||||
const id = '1';
|
||||
const value = 'Group one';
|
||||
const active = true;
|
||||
const disabled = false;
|
||||
|
||||
const expectedResponse = [
|
||||
{
|
||||
id,
|
||||
value,
|
||||
active,
|
||||
disabled,
|
||||
},
|
||||
];
|
||||
|
||||
const actualResponse = groups(undefined, {
|
||||
type: 'ADD_GROUP',
|
||||
id,
|
||||
value,
|
||||
active,
|
||||
disabled,
|
||||
});
|
||||
|
||||
expect(actualResponse).to.eql(expectedResponse);
|
||||
});
|
||||
|
||||
describe('when groups exist', () => {
|
||||
let state;
|
||||
|
||||
beforeEach(() => {
|
||||
state = [
|
||||
{
|
||||
id: 1,
|
||||
value: 'Group one',
|
||||
active: true,
|
||||
disabled: false,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
value: 'Group two',
|
||||
active: true,
|
||||
disabled: false,
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
describe('CLEAR_CHOICES', () => {
|
||||
it('restores to defaultState', () => {
|
||||
const clonedState = state.slice(0);
|
||||
const expectedResponse = defaultState;
|
||||
const actualResponse = groups(clonedState, {
|
||||
type: 'CLEAR_CHOICES',
|
||||
});
|
||||
|
||||
expect(actualResponse).to.eql(expectedResponse);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue