2017-10-13 14:43:58 +02:00
|
|
|
import { expect } from 'chai';
|
2017-12-19 14:08:57 +01:00
|
|
|
import { stub } from 'sinon';
|
|
|
|
import WrappedElement from './wrapped-element';
|
2017-10-13 14:43:58 +02:00
|
|
|
import WrappedInput from './wrapped-input';
|
2018-05-21 18:01:03 +02:00
|
|
|
import { DEFAULT_CLASSNAMES } from '../constants';
|
2017-10-13 14:43:58 +02:00
|
|
|
|
2017-10-29 19:56:24 +01:00
|
|
|
describe('components/wrappedInput', () => {
|
2017-10-13 14:43:58 +02:00
|
|
|
let instance;
|
2017-12-20 16:10:01 +01:00
|
|
|
let element;
|
2018-05-21 18:01:03 +02:00
|
|
|
const delimiter = '-';
|
2017-10-13 14:43:58 +02:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-12-20 16:10:01 +01:00
|
|
|
element = document.createElement('input');
|
2018-05-21 18:01:03 +02:00
|
|
|
instance = new WrappedInput({
|
|
|
|
element,
|
|
|
|
classNames: DEFAULT_CLASSNAMES,
|
|
|
|
delimiter,
|
|
|
|
});
|
2017-10-13 14:43:58 +02:00
|
|
|
});
|
2017-12-18 13:06:38 +01:00
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
document.body.innerHTML = '';
|
|
|
|
instance = null;
|
|
|
|
});
|
|
|
|
|
2017-12-20 16:10:01 +01:00
|
|
|
describe('constructor', () => {
|
|
|
|
it('assigns choices element to class', () => {
|
|
|
|
expect(instance.element).to.eql(element);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('assigns classnames to class', () => {
|
|
|
|
expect(instance.classNames).to.eql(DEFAULT_CLASSNAMES);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 14:08:57 +01:00
|
|
|
describe('inherited methods', () => {
|
2018-05-28 14:55:44 +02:00
|
|
|
['conceal', 'reveal', 'enable', 'disable'].forEach(method => {
|
2017-12-19 14:08:57 +01:00
|
|
|
describe(method, () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
stub(WrappedElement.prototype, method);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
WrappedElement.prototype[method].restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`calls super.${method}`, () => {
|
2017-12-20 13:38:16 +01:00
|
|
|
expect(WrappedElement.prototype[method].called).to.equal(false);
|
2017-12-19 14:08:57 +01:00
|
|
|
instance[method]();
|
|
|
|
expect(WrappedElement.prototype[method].called).to.equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-24 13:54:45 +02:00
|
|
|
describe('value setter', () => {
|
2017-12-18 13:06:38 +01:00
|
|
|
const data = [
|
|
|
|
{
|
|
|
|
id: 'ID 1',
|
|
|
|
value: 'Value 1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'ID 2',
|
|
|
|
value: 'Value 2',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'ID 3',
|
|
|
|
value: 'Value 3',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
it('sets delimited value of element based on passed data', () => {
|
|
|
|
expect(instance.element.value).to.equal('');
|
2018-04-24 13:54:45 +02:00
|
|
|
instance.value = data;
|
2018-05-28 14:55:44 +02:00
|
|
|
expect(instance.value).to.equal(
|
|
|
|
`Value 1${delimiter}Value 2${delimiter}Value 3`,
|
|
|
|
);
|
2017-12-18 13:06:38 +01:00
|
|
|
});
|
|
|
|
});
|
2017-10-13 14:43:58 +02:00
|
|
|
});
|