mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-20 22:46:33 +02:00
103 lines
4.1 KiB
JavaScript
103 lines
4.1 KiB
JavaScript
import Choices from '../../assets/scripts/src/choices.js';
|
|
|
|
describe('Choices', function() {
|
|
|
|
beforeEach(function() {
|
|
this.input = document.createElement('input');
|
|
this.input.type = "text";
|
|
this.input.className = 'js-choices';
|
|
|
|
document.body.appendChild(this.input);
|
|
|
|
this.choices = new Choices(this.input);
|
|
});
|
|
|
|
afterEach(function() {
|
|
this.choices.destroy();
|
|
});
|
|
|
|
describe('should initialize Choices', function() {
|
|
|
|
it('should be defined', function() {
|
|
expect(this.choices).toBeDefined();
|
|
});
|
|
|
|
it('should have initalised', function() {
|
|
expect(this.choices.initialised).toBe(true);
|
|
});
|
|
|
|
it('should have a blank state', function() {
|
|
const blankState = {
|
|
items: [],
|
|
groups: [],
|
|
choices: [],
|
|
};
|
|
expect(this.choices.currentState).toEqual(blankState);
|
|
});
|
|
|
|
it('should expose public methods', function(){
|
|
expect(this.choices.init).toEqual(jasmine.any(Function));
|
|
expect(this.choices.destroy).toEqual(jasmine.any(Function));
|
|
expect(this.choices.highlightItem).toEqual(jasmine.any(Function));
|
|
expect(this.choices.unhighlightItem).toEqual(jasmine.any(Function));
|
|
expect(this.choices.highlightAll).toEqual(jasmine.any(Function));
|
|
expect(this.choices.unhighlightAll).toEqual(jasmine.any(Function));
|
|
expect(this.choices.removeItemsByValue).toEqual(jasmine.any(Function));
|
|
expect(this.choices.removeActiveItems).toEqual(jasmine.any(Function));
|
|
expect(this.choices.removeHighlightedItems).toEqual(jasmine.any(Function));
|
|
expect(this.choices.showDropdown).toEqual(jasmine.any(Function));
|
|
expect(this.choices.hideDropdown).toEqual(jasmine.any(Function));
|
|
expect(this.choices.toggleDropdown).toEqual(jasmine.any(Function));
|
|
expect(this.choices.setValue).toEqual(jasmine.any(Function));
|
|
expect(this.choices.clearValue).toEqual(jasmine.any(Function));
|
|
expect(this.choices.disable).toEqual(jasmine.any(Function));
|
|
expect(this.choices.ajax).toEqual(jasmine.any(Function));
|
|
expect(this.choices.clearInput).toEqual(jasmine.any(Function));
|
|
expect(this.choices.clearInput).toEqual(jasmine.any(Function));
|
|
});
|
|
});
|
|
|
|
describe('should create markup', function() {
|
|
it('should hide passed input', function() {
|
|
expect(this.choices.passedElement.style.display).toEqual('none');
|
|
});
|
|
it('should create an outer container', function() {
|
|
expect(this.choices.containerOuter).toEqual(jasmine.any(HTMLElement));
|
|
});
|
|
it('should create an inner container', function() {
|
|
expect(this.choices.containerInner).toEqual(jasmine.any(HTMLElement));
|
|
});
|
|
it('should create a choice list', function() {
|
|
expect(this.choices.choiceList).toEqual(jasmine.any(HTMLElement));
|
|
});
|
|
it('should create an item list', function() {
|
|
expect(this.choices.itemList).toEqual(jasmine.any(HTMLElement));
|
|
});
|
|
it('should create an input', function() {
|
|
expect(this.choices.input).toEqual(jasmine.any(HTMLElement));
|
|
});
|
|
it('should create a dropdown', function() {
|
|
expect(this.choices.dropdown).toEqual(jasmine.any(HTMLElement));
|
|
});
|
|
});
|
|
|
|
describe('should allow inputted values', function() {
|
|
it('should set value via using setValue()', function() {
|
|
this.choices.setValue(['test1', 'test2']);
|
|
expect(this.choices.currentState.items.length).toEqual(2);
|
|
});
|
|
it('should accept a user inputted value', function() {
|
|
this.choices.input.focus();
|
|
this.choices.input.value = 'test';
|
|
|
|
this.choices._onKeyDown({
|
|
target: this.choices.input,
|
|
keyCode: 13,
|
|
ctrlKey: false
|
|
});
|
|
|
|
expect(this.choices.currentState.items[0].value).toContain('test');
|
|
});
|
|
});
|
|
});
|