Skip to content

Commit

Permalink
Issue #552 emoji menu (#1008)
Browse files Browse the repository at this point in the history
* Fixed uncoverd lines for emoji-menu/get-style test.

* New structure for correct testing.

* Added index test for emoji-menu.
  • Loading branch information
IanCStewart authored and Sjaak Luthart committed Jan 2, 2018
1 parent 056ae90 commit 3e27d06
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 12 deletions.
12 changes: 1 addition & 11 deletions src/emoji-menu/index.jsx → src/emoji-menu/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import emojione from 'emojione';
import _ from 'lodash';
import Radium from 'radium';
import compose from 'recompose/compose';
import onClickOutside from 'react-onclickoutside';
import EventListener from 'react-event-listener';
import emojis from './emoji';
import EmojiCategory from './emoji-category';
import EmojiModifiers from './emoji-modifiers';
import EmojiCategories from './emoji-categories';
import Storage from './storage';
import getStyles from './get-styles';
import themeable from '../themeable';
import colors from '../settings/colors';

const storage = new Storage();
Expand Down Expand Up @@ -204,14 +200,8 @@ class EmojiMenu extends Component {
}
}

const enhance = compose(
themeable(),
onClickOutside,
Radium
);

EmojiMenu.propTypes = propTypes;
EmojiMenu.defaultProps = defaultProps;
EmojiMenu.displayName = displayName;

export default enhance(EmojiMenu);
export default EmojiMenu;
13 changes: 13 additions & 0 deletions src/emoji-menu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Radium from 'radium';
import compose from 'recompose/compose';
import onClickOutside from 'react-onclickoutside';
import themeable from '../themeable';
import EmojiMenu from './component';

const enhance = compose(
themeable(),
onClickOutside,
Radium
);

export default enhance(EmojiMenu);
16 changes: 15 additions & 1 deletion test/emoji-menu/get-styles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('EmojiMenu.getStyles', () => {
});
});

describe('modifierHeader', () => {
describe('header', () => {
it('should get styles', () => {
const style = getStyles.header();

Expand All @@ -88,6 +88,20 @@ describe('EmojiMenu.getStyles', () => {
});
});

describe('modifiers', () => {
it('should get styles', () => {
const style = getStyles.modifiers();

expect(style).to.deep.equal(styles.modifiers);
});

it('should combine styles', () => {
const style = getStyles.modifiers({ color: 'red' });

expect(style).to.have.property('color', 'red');
});
});

describe('modifier', () => {
it('should get styles', () => {
const style = getStyles.modifier();
Expand Down
62 changes: 62 additions & 0 deletions test/emoji-menu/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* eslint-env mocha */
/* eslint react/jsx-filename-extension: [0] */
import React from 'react';
import chai, { expect } from 'chai';
import { shallow } from 'enzyme';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import EventListener from 'react-event-listener';
import EmojiMenu from '../../src/emoji-menu/component';
import EmojiModifiers from '../../src/emoji-menu/emoji-modifiers';
import EmojiCategory from '../../src/emoji-menu/emoji-category';
import EmojiCategories from '../../src/emoji-menu/emoji-categories';
import getStyles from '../../src/emoji-menu/get-styles';

chai.use(sinonChai);

describe('EmojiFilter', () => {
const props = {
style: {},
hideMenu: () => {},
sendEmoji: () => {},
color: '#1BA6C4'
};

beforeEach(() => {
global.navigator = { userAgent: 'all' };
});

afterEach(() => {
global.navigator = undefined;
});

it('should be an instanceOf AdminBadge', () => {
const component = shallow(<EmojiMenu {...props} />);

expect(component.instance()).to.be.instanceOf(EmojiMenu);
});

it('should render root elements', () => {
const component = shallow(<EmojiMenu {...props} />);

expect(component.find('section')).to.have.length(0);
expect(component.find(EmojiModifiers)).to.have.length(0);
expect(component.find(EmojiCategory)).to.have.length(0);
expect(component.find(EmojiCategories)).to.have.length(0);
expect(component.find(EventListener)).to.have.length(0);

component.setProps({ open: true });
expect(component.find(EmojiModifiers)).to.have.length(1);
expect(component.find(EmojiCategory)).to.have.length(1);
expect(component.find(EmojiCategories)).to.have.length(1);
expect(component.find(EventListener)).to.have.length(1);
});

it('should get root styles', () => {
const spy = sinon.spy(getStyles, 'root');
const component = shallow(<EmojiMenu {...props} />);

component.setProps({ open: true });
expect(spy).to.have.been.calledWith(props.style);
});
});

0 comments on commit 3e27d06

Please sign in to comment.