Skip to content

Commit

Permalink
wl - Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wpliao1989 committed Sep 12, 2018
1 parent 3643bce commit 6a46c9c
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/components/ImageCarousel.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import assert from 'assert';
import { shallow } from 'enzyme';
import React from 'react';
import sinon from 'sinon';

import {
Icon,
ImageCarousel,
Modal,
UncontrolledCarousel
} from '../../src';

describe('<ImageCarousel />', () => {
it('should render a modal with desired props', () => {
const component = shallow(<ImageCarousel isOpen />);
const modal = component.find(Modal);

assert.strictEqual(modal.prop('backdrop'), true);
assert.strictEqual(modal.prop('fade'), false);
assert.strictEqual(modal.prop('isOpen'), true);
});

it('should render a close button', () => {
const component = shallow(<ImageCarousel />);
const external = shallow(component.prop('external'));
const icon = external.find(Icon);

assert.strictEqual(icon.prop('name'), 'times');
});

it('should render a carousel', () => {
const items = [{ src: 'empire' }, { src: 'phantom' }, { src: 'force' }];
const component = shallow(<ImageCarousel items={items} />);
const external = shallow(component.prop('external'));
const carousel = external.find(UncontrolledCarousel);

assert.deepStrictEqual(carousel.prop('items'), [{ src: 'empire' }, { src: 'phantom' }, { src: 'force' }]);
assert.strictEqual(carousel.prop('indicators'), true);
assert.strictEqual(carousel.prop('controls'), true);
assert.strictEqual(carousel.prop('autoPlay'), false);
});

it('should call toggle when ESC is pressed', () => {
const spy = sinon.spy();
shallow(<ImageCarousel toggle={spy} />);

const event = new KeyboardEvent('keyup', { key: 'Escape' });
document.dispatchEvent(event);

assert(spy.calledOnce);
});

it('should not call toggle when other keys are pressed', () => {
const spy = sinon.spy();
shallow(<ImageCarousel toggle={spy} />);

const event = new KeyboardEvent('keyup', { key: 'Backspace' });
document.dispatchEvent(event);

assert(spy.notCalled);
});

describe('close button', () => {
it('should call toggle on click', () => {
const spy = sinon.spy();
const component = shallow(<ImageCarousel toggle={spy} />);
const external = shallow(component.prop('external'));
const icon = external.find(Icon);

icon.simulate('click');

assert(spy.calledOnce);
});
});
});

0 comments on commit 6a46c9c

Please sign in to comment.