2016-04-01 09:14:05 +08:00
|
|
|
import React from 'react';
|
2017-06-25 16:24:25 +08:00
|
|
|
import ReactTestUtils from 'react-dom/test-utils';
|
2016-04-01 09:14:05 +08:00
|
|
|
|
2016-04-01 07:10:09 +08:00
|
|
|
import {findDOMNode} from 'react-dom';
|
2016-04-01 05:26:21 +08:00
|
|
|
import {renderIntoDocument} from '../../../spec/nylas-test-utils';
|
|
|
|
import Contenteditable from '../../../src/components/contenteditable/contenteditable';
|
|
|
|
import EmojiButtonPopover from '../lib/emoji-button-popover';
|
|
|
|
import EmojiComposerExtension from '../lib/emoji-composer-extension';
|
|
|
|
|
2016-05-05 05:03:15 +08:00
|
|
|
describe('EmojiButtonPopover', function emojiButtonPopover() {
|
2016-05-06 13:30:34 +08:00
|
|
|
beforeEach(() => {
|
2016-04-01 09:14:05 +08:00
|
|
|
this.position = {
|
2016-04-01 05:26:21 +08:00
|
|
|
x: 20,
|
|
|
|
y: 40,
|
|
|
|
}
|
2016-04-01 09:14:05 +08:00
|
|
|
spyOn(EmojiButtonPopover.prototype, 'calcPosition').andReturn(this.position);
|
2016-04-01 05:26:21 +08:00
|
|
|
spyOn(EmojiComposerExtension, '_onSelectEmoji').andCallThrough();
|
2016-04-01 09:14:05 +08:00
|
|
|
|
2016-04-01 05:26:21 +08:00
|
|
|
this.component = renderIntoDocument(<EmojiButtonPopover />);
|
2016-04-01 09:14:05 +08:00
|
|
|
this.canvas = findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(this.component, 'canvas'));
|
|
|
|
|
2016-04-01 05:26:21 +08:00
|
|
|
this.composer = renderIntoDocument(
|
|
|
|
<Contenteditable
|
2016-04-13 01:27:24 +08:00
|
|
|
value={''}
|
2016-04-01 05:26:21 +08:00
|
|
|
onChange={jasmine.createSpy('onChange')}
|
2016-05-07 05:36:11 +08:00
|
|
|
extensions={[EmojiComposerExtension]}
|
|
|
|
/>
|
2016-04-01 05:26:21 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
describe('when inserting emoji', () => {
|
|
|
|
it('should insert emoji on click', () => {
|
2016-04-01 05:26:21 +08:00
|
|
|
ReactTestUtils.Simulate.mouseDown(this.canvas);
|
2016-04-01 09:14:05 +08:00
|
|
|
expect(EmojiComposerExtension._onSelectEmoji).toHaveBeenCalled();
|
2016-04-01 05:26:21 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
describe('when searching for emoji', () => {
|
|
|
|
it('should filter for matches', () => {
|
2016-04-01 07:10:09 +08:00
|
|
|
this.searchNode = findDOMNode(ReactTestUtils.findRenderedDOMComponentWithClass(this.component, 'search'))
|
2016-04-01 05:26:21 +08:00
|
|
|
const event = {
|
|
|
|
target: {
|
|
|
|
value: "heart",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ReactTestUtils.Simulate.change(this.searchNode, event);
|
|
|
|
ReactTestUtils.Simulate.mouseDown(this.canvas);
|
2016-04-01 09:14:05 +08:00
|
|
|
expect(EmojiComposerExtension._onSelectEmoji).toHaveBeenCalled();
|
2016-04-01 05:26:21 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|