mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-18 21:46:33 +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);
|
||||
});
|
||||
|
||||
describe('ADD_GROUP', () => {
|
||||
const id = '1';
|
||||
const value = 'Group one';
|
||||
const active = true;
|
||||
const disabled = false;
|
||||
describe('when groups do not exist', () => {
|
||||
describe('ADD_GROUP', () => {
|
||||
it('adds group', () => {
|
||||
const id = '1';
|
||||
const value = 'Group one';
|
||||
const active = true;
|
||||
const disabled = false;
|
||||
|
||||
const expectedResponse = [
|
||||
{
|
||||
id,
|
||||
value,
|
||||
active,
|
||||
disabled,
|
||||
},
|
||||
];
|
||||
const expectedResponse = [
|
||||
{
|
||||
id,
|
||||
value,
|
||||
active,
|
||||
disabled,
|
||||
},
|
||||
];
|
||||
|
||||
const actualResponse = groups(undefined, {
|
||||
type: 'ADD_GROUP',
|
||||
id,
|
||||
value,
|
||||
active,
|
||||
disabled,
|
||||
const actualResponse = groups(undefined, {
|
||||
type: 'ADD_GROUP',
|
||||
id,
|
||||
value,
|
||||
active,
|
||||
disabled,
|
||||
});
|
||||
|
||||
expect(actualResponse).to.eql(expectedResponse);
|
||||
});
|
||||
});
|
||||
|
||||
expect(actualResponse).to.eql(expectedResponse);
|
||||
});
|
||||
|
||||
describe('when groups exist', () => {
|
||||
|
|
|
@ -6,4 +6,128 @@ describe('items reducer', () => {
|
|||
it('should return same state when no action matches', () => {
|
||||
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