Add further component tests

This commit is contained in:
Josh Johnson 2017-12-19 13:08:57 +00:00
parent 905f31abf1
commit 9c9a4c115a
8 changed files with 146 additions and 8 deletions

View file

@ -50,7 +50,7 @@
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.2.1",
"jasmine-core": "2.4.1",
"jsdom": "^11.3.0",
"jsdom": "^11.5.1",
"mocha": "^3.4.2",
"node-sass": "^3.4.2",
"nodemon": "^1.9.1",

View file

@ -135,6 +135,16 @@ describe('components/container', () => {
expect(instance.shouldFlip(100)).to.equal(true);
});
});
describe('position config option set to "bottom"', () => {
beforeEach(() => {
instance.config.position = 'bottom';
});
it('returns false', () => {
expect(instance.shouldFlip(100)).to.equal(false);
});
});
});
});
@ -241,10 +251,20 @@ describe('components/container', () => {
focusStub.restore();
});
it('focuses element if isFocussed flag is set to false', () => {
instance.isFocussed = false;
instance.focus();
expect(focusStub.callCount).to.equal(1);
describe('isFocussed flag being set to false', () => {
it('focuses element', () => {
instance.isFocussed = false;
instance.focus();
expect(focusStub.called).to.equal(true);
});
});
describe('isFocussed flag being set to true', () => {
it('does not focus element', () => {
instance.isFocussed = true;
instance.focus();
expect(focusStub.called).to.equal(false);
});
});
});

View file

@ -68,4 +68,67 @@ describe('components/wrappedElement', () => {
expect(instance.element.getAttribute('data-choice-orig-style')).to.equal(null);
});
});
describe('enable', () => {
beforeEach(() => {
instance.disable();
});
it('removes disabled attribute', () => {
expect(instance.element.hasAttribute('disabled')).to.equal(true);
instance.enable();
expect(instance.element.hasAttribute('disabled')).to.equal(false);
});
it('sets elements disabled state to false', () => {
expect(instance.element.disabled).to.equal(true);
instance.enable();
expect(instance.element.disabled).to.equal(false);
});
it('sets isDisabled flag to false', () => {
expect(instance.isDisabled).to.equal(true);
instance.enable();
expect(instance.isDisabled).to.equal(false);
});
});
describe('disable', () => {
beforeEach(() => {
instance.enable();
});
it('sets disabled attribute (to blank string)', () => {
expect(instance.element.hasAttribute('disabled')).to.equal(false);
instance.disable();
expect(instance.element.getAttribute('disabled')).to.equal('');
});
it('sets elements disabled state to true', () => {
expect(instance.element.disabled).to.equal(false);
instance.disable();
expect(instance.element.disabled).to.equal(true);
});
it('sets isDisabled flag to true', () => {
expect(instance.isDisabled).to.equal(false);
instance.disable();
expect(instance.isDisabled).to.equal(true);
});
});
describe('triggerEvent', () => {
it('fires event on element using passed eventType and data', (done) => {
const data = {
test: true,
};
instance.element.addEventListener('testEvent', ({ detail }) => {
expect(detail).to.eql(data);
done();
});
instance.triggerEvent('testEvent', data);
});
});
});

View file

@ -26,7 +26,7 @@ export default class WrappedInput extends WrappedElement {
}
disable() {
super.enable();
super.disable();
}
setValue(items) {

View file

@ -1,4 +1,6 @@
import { expect } from 'chai';
import { stub } from 'sinon';
import WrappedElement from './wrapped-element';
import WrappedInput from './wrapped-input';
import { DEFAULT_CLASSNAMES, DEFAULT_CONFIG } from '../constants';
@ -22,6 +24,25 @@ describe('components/wrappedInput', () => {
instance = null;
});
describe('inherited methods', () => {
['getElement', 'conceal', 'reveal', 'enable', 'disable'].forEach((method) => {
describe(method, () => {
beforeEach(() => {
stub(WrappedElement.prototype, method);
});
afterEach(() => {
WrappedElement.prototype[method].restore();
});
it(`calls super.${method}`, () => {
instance[method]();
expect(WrappedElement.prototype[method].called).to.equal(true);
});
});
});
});
describe('setValue', () => {
const data = [
{

View file

@ -26,7 +26,7 @@ export default class WrappedSelect extends WrappedElement {
}
disable() {
super.enable();
super.disable();
}
getPlaceholderOption() {

View file

@ -1,4 +1,6 @@
import { expect } from 'chai';
import { stub } from 'sinon';
import WrappedElement from './wrapped-element';
import WrappedSelect from './wrapped-select';
import { DEFAULT_CLASSNAMES, DEFAULT_CONFIG } from '../constants';
@ -21,4 +23,36 @@ describe('components/wrappedSelect', () => {
document.body.innerHTML = '';
instance = null;
});
describe('inherited methods', () => {
['getElement', 'conceal', 'reveal', 'enable', 'disable'].forEach((method) => {
describe(method, () => {
it(`calls super.${method}`, () => {
stub(WrappedElement.prototype, method);
instance[method]();
expect(WrappedElement.prototype[method].called).to.equal(true);
});
});
});
});
// describe('getPlaceholderOption', () => {
// });
// describe('getOptions', () => {
// });
// describe('getOptionGroups', () => {
// });
// describe('setOptions', () => {
// });
// describe('appendDocFragment', () => {
// });
});

View file

@ -559,7 +559,7 @@ export const sortByScore = (a, b) => a.score - b.score;
* @return {Object} Triggered event
*/
export const dispatchEvent = (element, type, customArgs = null) => {
const event = new CustomEvent(type, {
const event = new window.CustomEvent(type, {
detail: customArgs,
bubbles: true,
cancelable: true,