mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-03 06:22:25 +02:00
Eslint spec files
This commit is contained in:
parent
67fe5d7dda
commit
9eebfc7ad1
|
@ -5,7 +5,9 @@
|
||||||
},
|
},
|
||||||
"env": {
|
"env": {
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"node": true
|
"node": true,
|
||||||
|
"mocha": true,
|
||||||
|
"jasmine": true
|
||||||
},
|
},
|
||||||
"parser": "babel-eslint",
|
"parser": "babel-eslint",
|
||||||
"rules": {
|
"rules": {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import 'whatwg-fetch';
|
import 'whatwg-fetch';
|
||||||
import 'es6-promise';
|
import 'es6-promise';
|
||||||
import 'core-js/fn/object/assign';
|
import 'core-js/fn/object/assign';
|
||||||
import Choices from '../../assets/scripts/src/choices.js';
|
import Choices from '../../assets/scripts/src/choices';
|
||||||
import itemReducer from '../../assets/scripts/src/reducers/items.js';
|
import itemReducer from '../../assets/scripts/src/reducers/items';
|
||||||
import choiceReducer from '../../assets/scripts/src/reducers/choices.js';
|
import choiceReducer from '../../assets/scripts/src/reducers/choices';
|
||||||
import {
|
import {
|
||||||
addItem as addItemAction,
|
addItem as addItemAction,
|
||||||
addChoice as addChoiceAction
|
addChoice as addChoiceAction,
|
||||||
} from '../../assets/scripts/src/actions/index.js';
|
} from '../../assets/scripts/src/actions/index';
|
||||||
|
|
||||||
describe('Choices', () => {
|
describe('Choices', () => {
|
||||||
describe('should initialize Choices', () => {
|
describe('should initialize Choices', () => {
|
||||||
|
@ -157,7 +157,7 @@ describe('Choices', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should accept text inputs', function() {
|
describe('should accept text inputs', () => {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.input = document.createElement('input');
|
this.input = document.createElement('input');
|
||||||
this.input.type = 'text';
|
this.input.type = 'text';
|
||||||
|
@ -190,7 +190,7 @@ describe('Choices', () => {
|
||||||
this.choices._onKeyDown({
|
this.choices._onKeyDown({
|
||||||
target: this.choices.input,
|
target: this.choices.input,
|
||||||
keyCode: 13,
|
keyCode: 13,
|
||||||
ctrlKey: false
|
ctrlKey: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(this.choices.currentState.items[0].value).toContain(this.choices.input.value);
|
expect(this.choices.currentState.items[0].value).toContain(this.choices.input.value);
|
||||||
|
@ -214,7 +214,7 @@ describe('Choices', () => {
|
||||||
this.choices._onKeyDown({
|
this.choices._onKeyDown({
|
||||||
target: this.choices.input,
|
target: this.choices.input,
|
||||||
keyCode: 13,
|
keyCode: 13,
|
||||||
ctrlKey: false
|
ctrlKey: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(this.choices.currentState.items[this.choices.currentState.items.length - 1]).not.toContain(this.choices.input.value);
|
expect(this.choices.currentState.items[this.choices.currentState.items.length - 1]).not.toContain(this.choices.input.value);
|
||||||
|
@ -231,7 +231,7 @@ describe('Choices', () => {
|
||||||
this.choices._onKeyDown({
|
this.choices._onKeyDown({
|
||||||
target: this.choices.input,
|
target: this.choices.input,
|
||||||
keyCode: 13,
|
keyCode: 13,
|
||||||
ctrlKey: false
|
ctrlKey: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.choices.input.focus();
|
this.choices.input.focus();
|
||||||
|
@ -240,7 +240,7 @@ describe('Choices', () => {
|
||||||
this.choices._onKeyDown({
|
this.choices._onKeyDown({
|
||||||
target: this.choices.input,
|
target: this.choices.input,
|
||||||
keyCode: 13,
|
keyCode: 13,
|
||||||
ctrlKey: false
|
ctrlKey: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const lastItem = this.choices.currentState.items[this.choices.currentState.items.length - 1];
|
const lastItem = this.choices.currentState.items[this.choices.currentState.items.length - 1];
|
||||||
|
@ -261,7 +261,7 @@ describe('Choices', () => {
|
||||||
this.choices._onKeyDown({
|
this.choices._onKeyDown({
|
||||||
target: this.choices.input,
|
target: this.choices.input,
|
||||||
keyCode: 13,
|
keyCode: 13,
|
||||||
ctrlKey: false
|
ctrlKey: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const lastItem = this.choices.currentState.items[this.choices.currentState.items.length - 1];
|
const lastItem = this.choices.currentState.items[this.choices.currentState.items.length - 1];
|
||||||
|
@ -271,7 +271,7 @@ describe('Choices', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should accept single select inputs', function() {
|
describe('should accept single select inputs', () => {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.input = document.createElement('select');
|
this.input = document.createElement('select');
|
||||||
this.input.className = 'js-choices';
|
this.input.className = 'js-choices';
|
||||||
|
@ -295,7 +295,7 @@ describe('Choices', () => {
|
||||||
|
|
||||||
it('should not apply placeholderValue to input', function() {
|
it('should not apply placeholderValue to input', function() {
|
||||||
this.choices = new Choices(this.input, {
|
this.choices = new Choices(this.input, {
|
||||||
placeholderValue: 'Placeholder'
|
placeholderValue: 'Placeholder',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(this.choices.input.placeholder).not.toEqual('Placeholder');
|
expect(this.choices.input.placeholder).not.toEqual('Placeholder');
|
||||||
|
@ -303,7 +303,7 @@ describe('Choices', () => {
|
||||||
|
|
||||||
it('should apply searchPlaceholderValue to input', function() {
|
it('should apply searchPlaceholderValue to input', function() {
|
||||||
this.choices = new Choices(this.input, {
|
this.choices = new Choices(this.input, {
|
||||||
searchPlaceholderValue: 'Placeholder'
|
searchPlaceholderValue: 'Placeholder',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(this.choices.input.placeholder).toEqual('Placeholder');
|
expect(this.choices.input.placeholder).toEqual('Placeholder');
|
||||||
|
@ -322,7 +322,7 @@ describe('Choices', () => {
|
||||||
|
|
||||||
it('should highlight the choices on keydown', function() {
|
it('should highlight the choices on keydown', function() {
|
||||||
this.choices = new Choices(this.input, {
|
this.choices = new Choices(this.input, {
|
||||||
renderChoiceLimit: -1
|
renderChoiceLimit: -1,
|
||||||
});
|
});
|
||||||
this.choices.input.focus();
|
this.choices.input.focus();
|
||||||
|
|
||||||
|
@ -332,7 +332,7 @@ describe('Choices', () => {
|
||||||
target: this.choices.input,
|
target: this.choices.input,
|
||||||
keyCode: 40,
|
keyCode: 40,
|
||||||
ctrlKey: false,
|
ctrlKey: false,
|
||||||
preventDefault: () => {}
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,7 +348,7 @@ describe('Choices', () => {
|
||||||
target: this.choices.input,
|
target: this.choices.input,
|
||||||
keyCode: 40,
|
keyCode: 40,
|
||||||
ctrlKey: false,
|
ctrlKey: false,
|
||||||
preventDefault: () => {}
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Key down to select choice
|
// Key down to select choice
|
||||||
|
@ -356,7 +356,7 @@ describe('Choices', () => {
|
||||||
target: this.choices.input,
|
target: this.choices.input,
|
||||||
keyCode: 13,
|
keyCode: 13,
|
||||||
ctrlKey: false,
|
ctrlKey: false,
|
||||||
preventDefault: () => {}
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(this.choices.currentState.items.length).toBe(2);
|
expect(this.choices.currentState.items.length).toBe(2);
|
||||||
|
@ -379,7 +379,7 @@ describe('Choices', () => {
|
||||||
target: this.choices.input,
|
target: this.choices.input,
|
||||||
keyCode: 40,
|
keyCode: 40,
|
||||||
ctrlKey: false,
|
ctrlKey: false,
|
||||||
preventDefault: () => {}
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Key down to select choice
|
// Key down to select choice
|
||||||
|
@ -387,7 +387,7 @@ describe('Choices', () => {
|
||||||
target: this.choices.input,
|
target: this.choices.input,
|
||||||
keyCode: 13,
|
keyCode: 13,
|
||||||
ctrlKey: false,
|
ctrlKey: false,
|
||||||
preventDefault: () => {}
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
const returnValue = changeSpy.calls.mostRecent().args[0].detail.value;
|
const returnValue = changeSpy.calls.mostRecent().args[0].detail.value;
|
||||||
|
@ -402,7 +402,7 @@ describe('Choices', () => {
|
||||||
this.choices._onClick({
|
this.choices._onClick({
|
||||||
target: container,
|
target: container,
|
||||||
ctrlKey: false,
|
ctrlKey: false,
|
||||||
preventDefault: () => {}
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(document.activeElement === this.choices.input && container.classList.contains('is-open')).toBe(true);
|
expect(document.activeElement === this.choices.input && container.classList.contains('is-open')).toBe(true);
|
||||||
|
@ -416,13 +416,13 @@ describe('Choices', () => {
|
||||||
this.choices._onClick({
|
this.choices._onClick({
|
||||||
target: container,
|
target: container,
|
||||||
ctrlKey: false,
|
ctrlKey: false,
|
||||||
preventDefault: () => {}
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
this.choices._onClick({
|
this.choices._onClick({
|
||||||
target: container,
|
target: container,
|
||||||
ctrlKey: false,
|
ctrlKey: false,
|
||||||
preventDefault: () => {}
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(document.activeElement === this.choices.input && container.classList.contains(openState)).toBe(false);
|
expect(document.activeElement === this.choices.input && container.classList.contains(openState)).toBe(false);
|
||||||
|
@ -441,14 +441,14 @@ describe('Choices', () => {
|
||||||
this.choices._onClick({
|
this.choices._onClick({
|
||||||
target: container,
|
target: container,
|
||||||
ctrlKey: false,
|
ctrlKey: false,
|
||||||
preventDefault: () => {}
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Hold mouse on scrollbar
|
// Hold mouse on scrollbar
|
||||||
this.choices._onMouseDown({
|
this.choices._onMouseDown({
|
||||||
target: choiceList,
|
target: choiceList,
|
||||||
ctrlKey: false,
|
ctrlKey: false,
|
||||||
preventDefault: () => {}
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(this.choices.isScrollingOnIe).toBe(true);
|
expect(this.choices.isScrollingOnIe).toBe(true);
|
||||||
|
@ -469,7 +469,7 @@ describe('Choices', () => {
|
||||||
this.choices._onClick({
|
this.choices._onClick({
|
||||||
target: container,
|
target: container,
|
||||||
ctrlKey: false,
|
ctrlKey: false,
|
||||||
preventDefault: () => {}
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(showDropdownSpy).toHaveBeenCalled();
|
expect(showDropdownSpy).toHaveBeenCalled();
|
||||||
|
@ -489,13 +489,13 @@ describe('Choices', () => {
|
||||||
this.choices._onClick({
|
this.choices._onClick({
|
||||||
target: container,
|
target: container,
|
||||||
ctrlKey: false,
|
ctrlKey: false,
|
||||||
preventDefault: () => {}
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
this.choices._onClick({
|
this.choices._onClick({
|
||||||
target: container,
|
target: container,
|
||||||
ctrlKey: false,
|
ctrlKey: false,
|
||||||
preventDefault: () => {}
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(hideDropdownSpy).toHaveBeenCalled();
|
expect(hideDropdownSpy).toHaveBeenCalled();
|
||||||
|
@ -516,12 +516,10 @@ describe('Choices', () => {
|
||||||
this.choices._onKeyUp({
|
this.choices._onKeyUp({
|
||||||
target: this.choices.input,
|
target: this.choices.input,
|
||||||
keyCode: 13,
|
keyCode: 13,
|
||||||
ctrlKey: false
|
ctrlKey: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const mostAccurateResult = this.choices.currentState.choices.filter(function (choice) {
|
const mostAccurateResult = this.choices.currentState.choices.filter((choice) => choice.active);
|
||||||
return choice.active;
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(this.choices.isSearching && mostAccurateResult[0].value === 'Value 3').toBe(true);
|
expect(this.choices.isSearching && mostAccurateResult[0].value === 'Value 3').toBe(true);
|
||||||
expect(searchSpy).toHaveBeenCalled();
|
expect(searchSpy).toHaveBeenCalled();
|
||||||
|
@ -529,7 +527,7 @@ describe('Choices', () => {
|
||||||
|
|
||||||
it('shouldn\'t filter choices when searching', function() {
|
it('shouldn\'t filter choices when searching', function() {
|
||||||
this.choices = new Choices(this.input, {
|
this.choices = new Choices(this.input, {
|
||||||
searchChoices: false
|
searchChoices: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.choices.setValue(['Javascript', 'HTML', 'Jasmine']);
|
this.choices.setValue(['Javascript', 'HTML', 'Jasmine']);
|
||||||
|
@ -546,12 +544,10 @@ describe('Choices', () => {
|
||||||
this.choices._onKeyUp({
|
this.choices._onKeyUp({
|
||||||
target: this.choices.input,
|
target: this.choices.input,
|
||||||
keyCode: 13,
|
keyCode: 13,
|
||||||
ctrlKey: false
|
ctrlKey: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const activeOptions = this.choices.currentState.choices.filter(function(choice) {
|
const activeOptions = this.choices.currentState.choices.filter((choice) => choice.active);
|
||||||
return choice.active;
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(activeOptions.length).toEqual(this.choices.currentState.choices.length);
|
expect(activeOptions.length).toEqual(this.choices.currentState.choices.length);
|
||||||
expect(searchSpy).toHaveBeenCalled();
|
expect(searchSpy).toHaveBeenCalled();
|
||||||
|
@ -562,14 +558,14 @@ describe('Choices', () => {
|
||||||
shouldSort: false,
|
shouldSort: false,
|
||||||
choices: [{
|
choices: [{
|
||||||
value: 'Value 5',
|
value: 'Value 5',
|
||||||
label: 'Label Five'
|
label: 'Label Five',
|
||||||
}, {
|
}, {
|
||||||
value: 'Value 6',
|
value: 'Value 6',
|
||||||
label: 'Label Six'
|
label: 'Label Six',
|
||||||
}, {
|
}, {
|
||||||
value: 'Value 7',
|
value: 'Value 7',
|
||||||
label: 'Label Seven'
|
label: 'Label Seven',
|
||||||
}, ],
|
}],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(this.choices.currentState.choices[0].value).toEqual('Value 5');
|
expect(this.choices.currentState.choices[0].value).toEqual('Value 5');
|
||||||
|
@ -580,14 +576,14 @@ describe('Choices', () => {
|
||||||
shouldSort: true,
|
shouldSort: true,
|
||||||
choices: [{
|
choices: [{
|
||||||
value: 'Value 5',
|
value: 'Value 5',
|
||||||
label: 'Label Five'
|
label: 'Label Five',
|
||||||
}, {
|
}, {
|
||||||
value: 'Value 6',
|
value: 'Value 6',
|
||||||
label: 'Label Six'
|
label: 'Label Six',
|
||||||
}, {
|
}, {
|
||||||
value: 'Value 7',
|
value: 'Value 7',
|
||||||
label: 'Label Seven'
|
label: 'Label Seven',
|
||||||
}, ],
|
}],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(this.choices.currentState.choices[0].value).toEqual('Value 1');
|
expect(this.choices.currentState.choices[0].value).toEqual('Value 1');
|
||||||
|
@ -596,14 +592,14 @@ describe('Choices', () => {
|
||||||
it('should set searchPlaceholderValue if set', function() {
|
it('should set searchPlaceholderValue if set', function() {
|
||||||
const dummyPlaceholder = 'Test placeholder';
|
const dummyPlaceholder = 'Test placeholder';
|
||||||
this.choices = new Choices(this.input, {
|
this.choices = new Choices(this.input, {
|
||||||
searchPlaceholderValue: dummyPlaceholder
|
searchPlaceholderValue: dummyPlaceholder,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(this.choices.input.placeholder).toEqual(dummyPlaceholder);
|
expect(this.choices.input.placeholder).toEqual(dummyPlaceholder);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should accept multiple select inputs', function() {
|
describe('should accept multiple select inputs', () => {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.input = document.createElement('select');
|
this.input = document.createElement('select');
|
||||||
this.input.className = 'js-choices';
|
this.input.className = 'js-choices';
|
||||||
|
@ -631,15 +627,15 @@ describe('Choices', () => {
|
||||||
value: 'One',
|
value: 'One',
|
||||||
label: 'Label One',
|
label: 'Label One',
|
||||||
selected: true,
|
selected: true,
|
||||||
disabled: false
|
disabled: false,
|
||||||
}, {
|
}, {
|
||||||
value: 'Two',
|
value: 'Two',
|
||||||
label: 'Label Two',
|
label: 'Label Two',
|
||||||
disabled: true
|
disabled: true,
|
||||||
}, {
|
}, {
|
||||||
value: 'Three',
|
value: 'Three',
|
||||||
label: 'Label Three'
|
label: 'Label Three',
|
||||||
}, ],
|
}],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -668,7 +664,7 @@ describe('Choices', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should handle public methods on select input types', function() {
|
describe('should handle public methods on select input types', () => {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.input = document.createElement('select');
|
this.input = document.createElement('select');
|
||||||
this.input.className = 'js-choices';
|
this.input.className = 'js-choices';
|
||||||
|
@ -719,7 +715,7 @@ describe('Choices', () => {
|
||||||
|
|
||||||
this.choices.highlightAll();
|
this.choices.highlightAll();
|
||||||
|
|
||||||
const unhighlightedItems = items.some((item) => item.highlighted === false);
|
const unhighlightedItems = items.some(item => item.highlighted === false);
|
||||||
|
|
||||||
expect(unhighlightedItems).toBe(false);
|
expect(unhighlightedItems).toBe(false);
|
||||||
});
|
});
|
||||||
|
@ -729,7 +725,7 @@ describe('Choices', () => {
|
||||||
|
|
||||||
this.choices.unhighlightAll();
|
this.choices.unhighlightAll();
|
||||||
|
|
||||||
const highlightedItems = items.some((item) => item.highlighted === true);
|
const highlightedItems = items.some(item => item.highlighted === true);
|
||||||
|
|
||||||
expect(highlightedItems).toBe(false);
|
expect(highlightedItems).toBe(false);
|
||||||
});
|
});
|
||||||
|
@ -739,7 +735,7 @@ describe('Choices', () => {
|
||||||
this.choices.highlightAll();
|
this.choices.highlightAll();
|
||||||
this.choices.removeHighlightedItems();
|
this.choices.removeHighlightedItems();
|
||||||
|
|
||||||
const activeItems = items.some((item) => item.active === true);
|
const activeItems = items.some(item => item.active === true);
|
||||||
|
|
||||||
expect(activeItems).toBe(false);
|
expect(activeItems).toBe(false);
|
||||||
});
|
});
|
||||||
|
@ -814,15 +810,15 @@ describe('Choices', () => {
|
||||||
choices: [{
|
choices: [{
|
||||||
value: 'Child One',
|
value: 'Child One',
|
||||||
label: 'Child One',
|
label: 'Child One',
|
||||||
selected: true
|
selected: true,
|
||||||
}, {
|
}, {
|
||||||
value: 'Child Two',
|
value: 'Child Two',
|
||||||
label: 'Child Two',
|
label: 'Child Two',
|
||||||
disabled: true
|
disabled: true,
|
||||||
}, {
|
}, {
|
||||||
value: 'Child Three',
|
value: 'Child Three',
|
||||||
label: 'Child Three'
|
label: 'Child Three',
|
||||||
}, ]
|
}],
|
||||||
}, {
|
}, {
|
||||||
label: 'Group two',
|
label: 'Group two',
|
||||||
id: 2,
|
id: 2,
|
||||||
|
@ -830,14 +826,14 @@ describe('Choices', () => {
|
||||||
choices: [{
|
choices: [{
|
||||||
value: 'Child Four',
|
value: 'Child Four',
|
||||||
label: 'Child Four',
|
label: 'Child Four',
|
||||||
disabled: true
|
disabled: true,
|
||||||
}, {
|
}, {
|
||||||
value: 'Child Five',
|
value: 'Child Five',
|
||||||
label: 'Child Five'
|
label: 'Child Five',
|
||||||
}, {
|
}, {
|
||||||
value: 'Child Six',
|
value: 'Child Six',
|
||||||
label: 'Child Six'
|
label: 'Child Six',
|
||||||
}, ]
|
}],
|
||||||
}], 'value', 'label');
|
}], 'value', 'label');
|
||||||
|
|
||||||
|
|
||||||
|
@ -853,10 +849,10 @@ describe('Choices', () => {
|
||||||
it('should handle setChoices() with blank values', function() {
|
it('should handle setChoices() with blank values', function() {
|
||||||
this.choices.setChoices([{
|
this.choices.setChoices([{
|
||||||
label: 'Choice one',
|
label: 'Choice one',
|
||||||
value: 'one'
|
value: 'one',
|
||||||
}, {
|
}, {
|
||||||
label: 'Choice two',
|
label: 'Choice two',
|
||||||
value: ''
|
value: '',
|
||||||
}], 'value', 'label', true);
|
}], 'value', 'label', true);
|
||||||
|
|
||||||
|
|
||||||
|
@ -908,7 +904,7 @@ describe('Choices', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should handle public methods on select-one input types', function() {
|
describe('should handle public methods on select-one input types', () => {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.input = document.createElement('select');
|
this.input = document.createElement('select');
|
||||||
this.input.className = 'js-choices';
|
this.input.className = 'js-choices';
|
||||||
|
@ -948,7 +944,7 @@ describe('Choices', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should handle public methods on text input types', function() {
|
describe('should handle public methods on text input types', () => {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.input = document.createElement('input');
|
this.input = document.createElement('input');
|
||||||
this.input.type = 'text';
|
this.input.type = 'text';
|
||||||
|
@ -977,7 +973,7 @@ describe('Choices', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should react to config options', function() {
|
describe('should react to config options', () => {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.input = document.createElement('select');
|
this.input = document.createElement('select');
|
||||||
this.input.className = 'js-choices';
|
this.input.className = 'js-choices';
|
||||||
|
@ -1015,7 +1011,7 @@ describe('Choices', () => {
|
||||||
|
|
||||||
it('shouldn\'t flip the dropdown', function() {
|
it('shouldn\'t flip the dropdown', function() {
|
||||||
this.choices = new Choices(this.input, {
|
this.choices = new Choices(this.input, {
|
||||||
position: 'bottom'
|
position: 'bottom',
|
||||||
});
|
});
|
||||||
|
|
||||||
const container = this.choices.containerOuter;
|
const container = this.choices.containerOuter;
|
||||||
|
@ -1026,7 +1022,7 @@ describe('Choices', () => {
|
||||||
it('should render selected choices', function() {
|
it('should render selected choices', function() {
|
||||||
this.choices = new Choices(this.input, {
|
this.choices = new Choices(this.input, {
|
||||||
renderSelectedChoices: 'always',
|
renderSelectedChoices: 'always',
|
||||||
renderChoiceLimit: -1
|
renderChoiceLimit: -1,
|
||||||
});
|
});
|
||||||
const renderedChoices = this.choices.choiceList.querySelectorAll('.choices__item');
|
const renderedChoices = this.choices.choiceList.querySelectorAll('.choices__item');
|
||||||
expect(renderedChoices.length).toEqual(3);
|
expect(renderedChoices.length).toEqual(3);
|
||||||
|
@ -1035,7 +1031,7 @@ describe('Choices', () => {
|
||||||
it('shouldn\'t render selected choices', function() {
|
it('shouldn\'t render selected choices', function() {
|
||||||
this.choices = new Choices(this.input, {
|
this.choices = new Choices(this.input, {
|
||||||
renderSelectedChoices: 'auto',
|
renderSelectedChoices: 'auto',
|
||||||
renderChoiceLimit: -1
|
renderChoiceLimit: -1,
|
||||||
});
|
});
|
||||||
const renderedChoices = this.choices.choiceList.querySelectorAll('.choices__item');
|
const renderedChoices = this.choices.choiceList.querySelectorAll('.choices__item');
|
||||||
expect(renderedChoices.length).toEqual(1);
|
expect(renderedChoices.length).toEqual(1);
|
||||||
|
@ -1071,7 +1067,7 @@ describe('Choices', () => {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
renderSelectedChoices: 'auto',
|
renderSelectedChoices: 'auto',
|
||||||
renderChoiceLimit: 4
|
renderChoiceLimit: 4,
|
||||||
});
|
});
|
||||||
|
|
||||||
const renderedChoices = this.choices.choiceList.querySelectorAll('.choices__item');
|
const renderedChoices = this.choices.choiceList.querySelectorAll('.choices__item');
|
||||||
|
@ -1079,8 +1075,8 @@ describe('Choices', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should allow custom properties provided by the user on items or choices', function() {
|
describe('should allow custom properties provided by the user on items or choices', () => {
|
||||||
it('should allow the user to supply custom properties for an item', function() {
|
it('should allow the user to supply custom properties for an item', () => {
|
||||||
const randomItem = {
|
const randomItem = {
|
||||||
id: 8999,
|
id: 8999,
|
||||||
choiceId: 9000,
|
choiceId: 9000,
|
||||||
|
@ -1088,10 +1084,10 @@ describe('Choices', () => {
|
||||||
value: 'value',
|
value: 'value',
|
||||||
label: 'label',
|
label: 'label',
|
||||||
customProperties: {
|
customProperties: {
|
||||||
foo: 'bar'
|
foo: 'bar',
|
||||||
},
|
},
|
||||||
placeholder: false,
|
placeholder: false,
|
||||||
keyCode: null
|
keyCode: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const expectedState = [{
|
const expectedState = [{
|
||||||
|
@ -1104,7 +1100,7 @@ describe('Choices', () => {
|
||||||
highlighted: false,
|
highlighted: false,
|
||||||
customProperties: randomItem.customProperties,
|
customProperties: randomItem.customProperties,
|
||||||
placeholder: false,
|
placeholder: false,
|
||||||
keyCode: randomItem.keyCode
|
keyCode: randomItem.keyCode,
|
||||||
}];
|
}];
|
||||||
|
|
||||||
const action = addItemAction(
|
const action = addItemAction(
|
||||||
|
@ -1114,13 +1110,13 @@ describe('Choices', () => {
|
||||||
randomItem.choiceId,
|
randomItem.choiceId,
|
||||||
randomItem.groupId,
|
randomItem.groupId,
|
||||||
randomItem.customProperties,
|
randomItem.customProperties,
|
||||||
randomItem.keyCode
|
randomItem.keyCode,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(itemReducer([], action)).toEqual(expectedState);
|
expect(itemReducer([], action)).toEqual(expectedState);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow the user to supply custom properties for a choice', function() {
|
it('should allow the user to supply custom properties for a choice', () => {
|
||||||
const randomChoice = {
|
const randomChoice = {
|
||||||
id: 123,
|
id: 123,
|
||||||
elementId: 321,
|
elementId: 321,
|
||||||
|
@ -1129,10 +1125,10 @@ describe('Choices', () => {
|
||||||
label: 'label',
|
label: 'label',
|
||||||
disabled: false,
|
disabled: false,
|
||||||
customProperties: {
|
customProperties: {
|
||||||
foo: 'bar'
|
foo: 'bar',
|
||||||
},
|
},
|
||||||
placeholder: false,
|
placeholder: false,
|
||||||
keyCode: null
|
keyCode: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const expectedState = [{
|
const expectedState = [{
|
||||||
|
@ -1147,7 +1143,7 @@ describe('Choices', () => {
|
||||||
score: 9999,
|
score: 9999,
|
||||||
customProperties: randomChoice.customProperties,
|
customProperties: randomChoice.customProperties,
|
||||||
placeholder: randomChoice.placeholder,
|
placeholder: randomChoice.placeholder,
|
||||||
keyCode: randomChoice.keyCode
|
keyCode: randomChoice.keyCode,
|
||||||
}];
|
}];
|
||||||
|
|
||||||
const action = addChoiceAction(
|
const action = addChoiceAction(
|
||||||
|
@ -1158,14 +1154,14 @@ describe('Choices', () => {
|
||||||
randomChoice.disabled,
|
randomChoice.disabled,
|
||||||
randomChoice.elementId,
|
randomChoice.elementId,
|
||||||
randomChoice.customProperties,
|
randomChoice.customProperties,
|
||||||
randomChoice.keyCode
|
randomChoice.keyCode,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(choiceReducer([], action)).toEqual(expectedState);
|
expect(choiceReducer([], action)).toEqual(expectedState);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should allow custom properties provided by the user on items or choices', function() {
|
describe('should allow custom properties provided by the user on items or choices', () => {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.input = document.createElement('select');
|
this.input = document.createElement('select');
|
||||||
this.input.className = 'js-choices';
|
this.input.className = 'js-choices';
|
||||||
|
@ -1180,7 +1176,7 @@ describe('Choices', () => {
|
||||||
|
|
||||||
it('should allow the user to supply custom properties for a choice that will be inherited by the item when the user selects the choice', function() {
|
it('should allow the user to supply custom properties for a choice that will be inherited by the item when the user selects the choice', function() {
|
||||||
const expectedCustomProperties = {
|
const expectedCustomProperties = {
|
||||||
isBestOptionEver: true
|
isBestOptionEver: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.choices = new Choices(this.input);
|
this.choices = new Choices(this.input);
|
||||||
|
@ -1189,7 +1185,7 @@ describe('Choices', () => {
|
||||||
label: 'My awesome choice',
|
label: 'My awesome choice',
|
||||||
selected: false,
|
selected: false,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
customProperties: expectedCustomProperties
|
customProperties: expectedCustomProperties,
|
||||||
}], 'value', 'label', true);
|
}], 'value', 'label', true);
|
||||||
|
|
||||||
this.choices.setValueByChoice('42');
|
this.choices.setValueByChoice('42');
|
||||||
|
@ -1201,7 +1197,7 @@ describe('Choices', () => {
|
||||||
|
|
||||||
it('should allow the user to supply custom properties when directly creating a selected item', function() {
|
it('should allow the user to supply custom properties when directly creating a selected item', function() {
|
||||||
const expectedCustomProperties = {
|
const expectedCustomProperties = {
|
||||||
isBestOptionEver: true
|
isBestOptionEver: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.choices = new Choices(this.input);
|
this.choices = new Choices(this.input);
|
||||||
|
@ -1209,7 +1205,7 @@ describe('Choices', () => {
|
||||||
this.choices.setValue([{
|
this.choices.setValue([{
|
||||||
value: 'bar',
|
value: 'bar',
|
||||||
label: 'foo',
|
label: 'foo',
|
||||||
customProperties: expectedCustomProperties
|
customProperties: expectedCustomProperties,
|
||||||
}]);
|
}]);
|
||||||
const selectedItems = this.choices.getValue();
|
const selectedItems = this.choices.getValue();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue