Choices/src/scripts/actions/choices.test.ts

93 lines
2.3 KiB
TypeScript
Raw Normal View History

2017-10-10 16:26:38 +02:00
import { expect } from 'chai';
import * as actions from './choices';
2017-10-29 19:56:24 +01:00
describe('actions/choices', () => {
2017-10-10 16:26:38 +02:00
describe('addChoice action', () => {
it('returns ADD_CHOICE action', () => {
const value = 'test';
const label = 'test';
const id = 1;
const groupId = 1;
2017-10-10 16:26:38 +02:00
const disabled = false;
const elementId = 1;
const customProperties = { test: true };
const placeholder = true;
2017-10-10 16:26:38 +02:00
const keyCode = 10;
const expectedAction: actions.AddChoiceAction = {
2017-10-10 16:26:38 +02:00
type: 'ADD_CHOICE',
value,
label,
id,
groupId,
disabled,
elementId,
customProperties,
placeholder,
keyCode,
};
expect(
2018-05-29 20:55:33 +02:00
actions.addChoice({
value,
label,
id,
groupId,
disabled,
elementId,
customProperties,
placeholder,
keyCode,
2018-05-29 20:55:33 +02:00
}),
).to.eql(expectedAction);
2017-10-10 16:26:38 +02:00
});
});
describe('filterChoices action', () => {
it('returns FILTER_CHOICES action', () => {
const results = Array(10);
const expectedAction: actions.FilterChoicesAction = {
2017-10-10 16:26:38 +02:00
type: 'FILTER_CHOICES',
results,
};
expect(actions.filterChoices(results)).to.eql(expectedAction);
});
});
describe('activateChoices action', () => {
2017-11-11 14:40:18 +01:00
describe('not passing active parameter', () => {
it('returns ACTIVATE_CHOICES action', () => {
const expectedAction: actions.ActivateChoicesAction = {
2017-11-11 14:40:18 +01:00
type: 'ACTIVATE_CHOICES',
active: true,
};
expect(actions.activateChoices()).to.eql(expectedAction);
});
});
describe('passing active parameter', () => {
it('returns ACTIVATE_CHOICES action', () => {
const active = true;
const expectedAction: actions.ActivateChoicesAction = {
2017-11-11 14:40:18 +01:00
type: 'ACTIVATE_CHOICES',
active,
};
2017-10-10 16:26:38 +02:00
2017-11-11 14:40:18 +01:00
expect(actions.activateChoices(active)).to.eql(expectedAction);
});
2017-10-10 16:26:38 +02:00
});
});
describe('clearChoices action', () => {
it('returns CLEAR_CHOICES action', () => {
const expectedAction: actions.ClearChoicesAction = {
2017-10-10 16:26:38 +02:00
type: 'CLEAR_CHOICES',
};
expect(actions.clearChoices()).to.eql(expectedAction);
});
});
});