mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-10 01:42:36 +02:00
Items/groups tests
This commit is contained in:
parent
c63b9ff439
commit
2a8a8340f6
|
@ -6,30 +6,34 @@ describe('groups reducer', () => {
|
||||||
expect(groups(defaultState, {})).to.equal(defaultState);
|
expect(groups(defaultState, {})).to.equal(defaultState);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ADD_GROUP', () => {
|
describe('when groups do not exist', () => {
|
||||||
const id = '1';
|
describe('ADD_GROUP', () => {
|
||||||
const value = 'Group one';
|
it('adds group', () => {
|
||||||
const active = true;
|
const id = '1';
|
||||||
const disabled = false;
|
const value = 'Group one';
|
||||||
|
const active = true;
|
||||||
|
const disabled = false;
|
||||||
|
|
||||||
const expectedResponse = [
|
const expectedResponse = [
|
||||||
{
|
{
|
||||||
id,
|
id,
|
||||||
value,
|
value,
|
||||||
active,
|
active,
|
||||||
disabled,
|
disabled,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const actualResponse = groups(undefined, {
|
const actualResponse = groups(undefined, {
|
||||||
type: 'ADD_GROUP',
|
type: 'ADD_GROUP',
|
||||||
id,
|
id,
|
||||||
value,
|
value,
|
||||||
active,
|
active,
|
||||||
disabled,
|
disabled,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(actualResponse).to.eql(expectedResponse);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(actualResponse).to.eql(expectedResponse);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when groups exist', () => {
|
describe('when groups exist', () => {
|
||||||
|
|
|
@ -6,4 +6,128 @@ describe('items reducer', () => {
|
||||||
it('should return same state when no action matches', () => {
|
it('should return same state when no action matches', () => {
|
||||||
expect(items(defaultState, {})).to.equal(defaultState);
|
expect(items(defaultState, {})).to.equal(defaultState);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when items do not exist', () => {
|
||||||
|
describe('ADD_ITEM', () => {
|
||||||
|
const value = 'Item one';
|
||||||
|
const label = 'Item one';
|
||||||
|
const id = 1234;
|
||||||
|
const choiceId = 5678;
|
||||||
|
const groupId = 1;
|
||||||
|
const customProperties = {
|
||||||
|
property: 'value',
|
||||||
|
};
|
||||||
|
const placeholder = 'This is a placeholder';
|
||||||
|
const keyCode = 10;
|
||||||
|
|
||||||
|
const expectedResponse = [
|
||||||
|
{
|
||||||
|
id,
|
||||||
|
choiceId,
|
||||||
|
groupId,
|
||||||
|
value,
|
||||||
|
label,
|
||||||
|
active: true,
|
||||||
|
highlighted: false,
|
||||||
|
customProperties,
|
||||||
|
placeholder,
|
||||||
|
keyCode: null,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const actualResponse = items(undefined, {
|
||||||
|
type: 'ADD_ITEM',
|
||||||
|
value,
|
||||||
|
label,
|
||||||
|
id,
|
||||||
|
choiceId,
|
||||||
|
groupId,
|
||||||
|
customProperties,
|
||||||
|
placeholder,
|
||||||
|
keyCode,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(actualResponse).to.eql(expectedResponse);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when items exist', () => {
|
||||||
|
let state;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
state = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
choiceId: 1,
|
||||||
|
groupId: -1,
|
||||||
|
value: 'Item one',
|
||||||
|
label: 'Item one',
|
||||||
|
active: false,
|
||||||
|
highlighted: false,
|
||||||
|
customProperties: null,
|
||||||
|
placeholder: false,
|
||||||
|
keyCode: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
choiceId: 2,
|
||||||
|
groupId: -1,
|
||||||
|
value: 'Item one',
|
||||||
|
label: 'Item one',
|
||||||
|
active: true,
|
||||||
|
highlighted: false,
|
||||||
|
customProperties: null,
|
||||||
|
placeholder: false,
|
||||||
|
keyCode: null,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('REMOVE_ITEM', () => {
|
||||||
|
it('sets an item to be inactive based on passed ID', () => {
|
||||||
|
const clonedState = state.slice(0);
|
||||||
|
const id = 2;
|
||||||
|
const expectedResponse = [
|
||||||
|
{
|
||||||
|
...state[0],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...state[1],
|
||||||
|
active: false,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const actualResponse = items(clonedState, {
|
||||||
|
type: 'REMOVE_ITEM',
|
||||||
|
id,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(actualResponse).to.eql(expectedResponse);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('HIGHLIGHT_ITEM', () => {
|
||||||
|
it('sets an item to be inactive based on passed ID', () => {
|
||||||
|
const clonedState = state.slice(0);
|
||||||
|
const id = 2;
|
||||||
|
const expectedResponse = [
|
||||||
|
{
|
||||||
|
...state[0],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...state[1],
|
||||||
|
highlighted: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const actualResponse = items(clonedState, {
|
||||||
|
type: 'HIGHLIGHT_ITEM',
|
||||||
|
id,
|
||||||
|
highlighted: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(actualResponse).to.eql(expectedResponse);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue