mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-22 07:26:39 +02:00
Don't map over state for reducer tests
This commit is contained in:
parent
a9cdbc54c4
commit
b9750e3c83
|
@ -7,7 +7,7 @@
|
|||
"scripts": {
|
||||
"start": "node server.js",
|
||||
"lint": "eslint assets/**/*.js",
|
||||
"test": "nyc mocha --require ./config/test.js --compilers babel-core/register \"./src/**/**/**/**/*.test.js\"",
|
||||
"test": "nyc mocha --require ./config/test.js --compilers js:babel-core/register \"./src/**/**/**/**/*.test.js\"",
|
||||
"test:watch": "npm run test -- --watch",
|
||||
"css:watch": "nodemon -e scss -x \"npm run css:build\"",
|
||||
"css:build": "npm run css:sass -s && npm run css:prefix -s && npm run css:min -s",
|
||||
|
@ -31,10 +31,11 @@
|
|||
"homepage": "https://github.com/jshjohnson/Choices#readme",
|
||||
"devDependencies": {
|
||||
"autoprefixer": "^6.3.3",
|
||||
"babel-core": "^6.25.0",
|
||||
"babel-core": "^6.26.0",
|
||||
"babel-eslint": "^7.2.3",
|
||||
"babel-loader": "^6.2.4",
|
||||
"babel-preset-es2015": "^6.6.0",
|
||||
"babel-preset-stage-2": "^6.24.1",
|
||||
"chai": "^4.1.0",
|
||||
"concurrently": "^3.1.0",
|
||||
"core-js": "^2.4.1",
|
||||
|
@ -48,7 +49,7 @@
|
|||
"eslint-plugin-jsx-a11y": "^5.1.1",
|
||||
"eslint-plugin-react": "^7.2.1",
|
||||
"jasmine-core": "2.4.1",
|
||||
"jsdom": "^11.1.0",
|
||||
"jsdom": "^11.3.0",
|
||||
"mocha": "^3.4.2",
|
||||
"node-sass": "^3.4.2",
|
||||
"nodemon": "^1.9.1",
|
||||
|
|
0
src/scripts/src/components/container.test.js
Normal file
0
src/scripts/src/components/container.test.js
Normal file
0
src/scripts/src/components/dropdown.test.js
Normal file
0
src/scripts/src/components/dropdown.test.js
Normal file
0
src/scripts/src/components/input.test.js
Normal file
0
src/scripts/src/components/input.test.js
Normal file
0
src/scripts/src/components/list.test.js
Normal file
0
src/scripts/src/components/list.test.js
Normal file
|
@ -18,18 +18,6 @@ describe('choices reducer', () => {
|
|||
const customProperties = 'test';
|
||||
const placeholder = 'test';
|
||||
|
||||
const actualResponse = choices(undefined, {
|
||||
type: 'ADD_CHOICE',
|
||||
value,
|
||||
label,
|
||||
id,
|
||||
groupId,
|
||||
disabled,
|
||||
elementId,
|
||||
customProperties,
|
||||
placeholder,
|
||||
});
|
||||
|
||||
const expectedResponse = [
|
||||
{
|
||||
value,
|
||||
|
@ -47,6 +35,18 @@ describe('choices reducer', () => {
|
|||
},
|
||||
];
|
||||
|
||||
const actualResponse = choices(undefined, {
|
||||
type: 'ADD_CHOICE',
|
||||
value,
|
||||
label,
|
||||
id,
|
||||
groupId,
|
||||
disabled,
|
||||
elementId,
|
||||
customProperties,
|
||||
placeholder,
|
||||
});
|
||||
|
||||
expect(actualResponse).to.eql(expectedResponse);
|
||||
});
|
||||
});
|
||||
|
@ -92,7 +92,16 @@ describe('choices reducer', () => {
|
|||
it('sets active flag based on whether choice is in passed results', () => {
|
||||
const id = 1;
|
||||
const score = 10;
|
||||
const actualResponse = choices([...state], {
|
||||
const active = true;
|
||||
|
||||
const expectedResponse = {
|
||||
...state[0],
|
||||
active,
|
||||
score,
|
||||
};
|
||||
|
||||
|
||||
const actualResponse = choices(state, {
|
||||
type: 'FILTER_CHOICES',
|
||||
results: [{
|
||||
item: {
|
||||
|
@ -100,16 +109,7 @@ describe('choices reducer', () => {
|
|||
},
|
||||
score,
|
||||
}],
|
||||
});
|
||||
|
||||
const expectedResponse = state.map((choice) => {
|
||||
const clonedChoice = choice;
|
||||
if (clonedChoice.id === id) {
|
||||
clonedChoice.active = true;
|
||||
clonedChoice.score = 10;
|
||||
}
|
||||
return clonedChoice;
|
||||
});
|
||||
}).find(choice => choice.id === id);
|
||||
|
||||
expect(actualResponse).to.eql(expectedResponse);
|
||||
});
|
||||
|
@ -117,29 +117,36 @@ describe('choices reducer', () => {
|
|||
|
||||
describe('ACTIVATE_CHOICES', () => {
|
||||
it('sets active flag to passed value', () => {
|
||||
const actualResponse = choices([...state], {
|
||||
const clonedState = state.slice(0);
|
||||
|
||||
const expectedResponse = [
|
||||
{
|
||||
...state[0],
|
||||
active: true,
|
||||
},
|
||||
{
|
||||
...state[1],
|
||||
active: true,
|
||||
},
|
||||
];
|
||||
|
||||
const actualResponse = choices(clonedState, {
|
||||
type: 'ACTIVATE_CHOICES',
|
||||
active: true,
|
||||
});
|
||||
|
||||
const expectedResponse = state.map((choice) => {
|
||||
const clonedChoice = choice;
|
||||
clonedChoice.active = true;
|
||||
return clonedChoice;
|
||||
});
|
||||
|
||||
expect(actualResponse).to.eql(expectedResponse);
|
||||
});
|
||||
});
|
||||
|
||||
describe('CLEAR_CHOICES', () => {
|
||||
it('restores to defaultState', () => {
|
||||
const actualResponse = choices([...state], {
|
||||
const clonedState = state.slice(0);
|
||||
const expectedResponse = defaultState;
|
||||
const actualResponse = choices(clonedState, {
|
||||
type: 'CLEAR_CHOICES',
|
||||
});
|
||||
|
||||
const expectedResponse = defaultState;
|
||||
|
||||
expect(actualResponse).to.eql(expectedResponse);
|
||||
});
|
||||
});
|
||||
|
@ -147,24 +154,28 @@ describe('choices reducer', () => {
|
|||
describe('ADD_ITEM', () => {
|
||||
it('disables choice if action has choice id', () => {
|
||||
const id = 2;
|
||||
const actualResponse = choices(state, {
|
||||
const clonedState = state.slice(0);
|
||||
const expectedResponse = [
|
||||
{
|
||||
...state[0],
|
||||
},
|
||||
{
|
||||
...state[1],
|
||||
selected: true,
|
||||
},
|
||||
];
|
||||
|
||||
const actualResponse = choices(clonedState, {
|
||||
type: 'ADD_ITEM',
|
||||
choiceId: id,
|
||||
});
|
||||
|
||||
const expectedResponse = state.map((choice) => {
|
||||
const clonedChoice = choice;
|
||||
if (clonedChoice.id === id) {
|
||||
clonedChoice.selected = false;
|
||||
}
|
||||
return clonedChoice;
|
||||
});
|
||||
|
||||
expect(actualResponse).to.eql(expectedResponse);
|
||||
});
|
||||
|
||||
it('activates all choices if activateOptions flag passed', () => {
|
||||
const actualResponse = choices(state, {
|
||||
const clonedState = state.slice(0);
|
||||
const actualResponse = choices(clonedState, {
|
||||
type: 'ADD_ITEM',
|
||||
activateOptions: true,
|
||||
active: true,
|
||||
|
@ -178,19 +189,22 @@ describe('choices reducer', () => {
|
|||
describe('REMOVE_ITEM', () => {
|
||||
it('selects choice by passed id', () => {
|
||||
const id = 2;
|
||||
const actualResponse = choices([...state], {
|
||||
const clonedState = state.slice(0);
|
||||
const expectedResponse = [
|
||||
{
|
||||
...state[0],
|
||||
},
|
||||
{
|
||||
...state[1],
|
||||
selected: false,
|
||||
},
|
||||
];
|
||||
|
||||
const actualResponse = choices(clonedState, {
|
||||
type: 'REMOVE_ITEM',
|
||||
choiceId: id,
|
||||
});
|
||||
|
||||
const expectedResponse = state.map((choice) => {
|
||||
const clonedChoice = choice;
|
||||
if (clonedChoice.id === id) {
|
||||
clonedChoice.selected = false;
|
||||
}
|
||||
return clonedChoice;
|
||||
});
|
||||
|
||||
expect(actualResponse).to.eql(expectedResponse);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue