2017-10-10 13:56:36 +02:00
|
|
|
import { expect } from 'chai';
|
|
|
|
import List from './list';
|
|
|
|
import { DEFAULT_CLASSNAMES, DEFAULT_CONFIG } from '../constants';
|
|
|
|
|
2017-10-29 19:56:24 +01:00
|
|
|
describe('components/list', () => {
|
2017-10-10 13:56:36 +02:00
|
|
|
let instance;
|
|
|
|
let choicesInstance;
|
|
|
|
let choicesElement;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
choicesInstance = {
|
|
|
|
config: {
|
|
|
|
...DEFAULT_CONFIG,
|
|
|
|
},
|
|
|
|
};
|
2017-10-11 10:39:31 +02:00
|
|
|
choicesElement = document.createElement('div');
|
2017-10-10 13:56:36 +02:00
|
|
|
instance = new List(choicesInstance, choicesElement, DEFAULT_CLASSNAMES);
|
|
|
|
});
|
|
|
|
|
2017-12-18 13:06:38 +01:00
|
|
|
afterEach(() => {
|
|
|
|
document.body.innerHTML = '';
|
|
|
|
instance = null;
|
|
|
|
});
|
|
|
|
|
2017-12-10 19:00:57 +01:00
|
|
|
describe('constructor', () => {
|
|
|
|
it('assigns choices instance to class', () => {
|
|
|
|
expect(instance.parentInstance).to.eql(choicesInstance);
|
|
|
|
});
|
2017-10-10 13:56:36 +02:00
|
|
|
|
2017-12-10 19:00:57 +01:00
|
|
|
it('assigns choices element to class', () => {
|
|
|
|
expect(instance.element).to.eql(choicesElement);
|
|
|
|
});
|
2017-10-10 13:56:36 +02:00
|
|
|
|
2017-12-10 19:00:57 +01:00
|
|
|
it('assigns classnames to class', () => {
|
|
|
|
expect(instance.classNames).to.eql(DEFAULT_CLASSNAMES);
|
|
|
|
});
|
2017-10-10 13:56:36 +02:00
|
|
|
});
|
2017-10-11 10:39:31 +02:00
|
|
|
|
|
|
|
describe('clear', () => {
|
|
|
|
it('clears element\'s inner HTML', () => {
|
|
|
|
const innerHTML = 'test';
|
|
|
|
instance.element.innerHTML = innerHTML;
|
|
|
|
expect(instance.element.innerHTML).to.equal(innerHTML);
|
|
|
|
instance.clear();
|
|
|
|
expect(instance.element.innerHTML).to.equal('');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('scrollTo', () => {
|
2017-12-10 19:00:57 +01:00
|
|
|
describe('passing position', () => {
|
|
|
|
it('scrolls element to passed position', () => {
|
|
|
|
const scrollPosition = 20;
|
|
|
|
expect(instance.element.scrollTop).to.equal(0);
|
|
|
|
instance.scrollTo(scrollPosition);
|
|
|
|
expect(instance.element.scrollTop).to.equal(scrollPosition);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('not passing position', () => {
|
|
|
|
it('scrolls element to default position', () => {
|
|
|
|
expect(instance.element.scrollTop).to.equal(0);
|
|
|
|
instance.scrollTo();
|
|
|
|
expect(instance.element.scrollTop).to.equal(0);
|
|
|
|
});
|
2017-10-11 10:39:31 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('append', () => {
|
|
|
|
it('appends passed node to element', () => {
|
|
|
|
const elementToAppend = document.createElement('span');
|
|
|
|
const childClass = 'test-element';
|
|
|
|
elementToAppend.classList.add(childClass);
|
|
|
|
expect(instance.element.querySelector(`.${childClass}`)).to.equal(null);
|
|
|
|
instance.append(elementToAppend);
|
|
|
|
expect(instance.element.querySelector(`.${childClass}`)).to.equal(elementToAppend);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('getChild', () => {
|
|
|
|
let childElement;
|
|
|
|
const childClass = 'test-element';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
childElement = document.createElement('span');
|
|
|
|
childElement.classList.add(childClass);
|
|
|
|
instance.element.appendChild(childElement);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns child element', () => {
|
|
|
|
const expectedResponse = childElement;
|
|
|
|
const actualResponse = instance.getChild(`.${childClass}`);
|
|
|
|
expect(expectedResponse).to.eql(actualResponse);
|
|
|
|
});
|
|
|
|
});
|
2017-10-10 13:56:36 +02:00
|
|
|
});
|