2016-04-01 05:26:21 +08:00
|
|
|
import React, {addons} from 'react/addons';
|
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';
|
|
|
|
|
|
|
|
const ReactTestUtils = addons.TestUtils;
|
|
|
|
|
|
|
|
describe('EmojiButtonPopover', ()=> {
|
|
|
|
beforeEach(()=> {
|
|
|
|
const position = {
|
|
|
|
x: 20,
|
|
|
|
y: 40,
|
|
|
|
}
|
|
|
|
spyOn(EmojiButtonPopover.prototype, 'calcPosition').andReturn(position);
|
|
|
|
spyOn(EmojiComposerExtension, '_onSelectEmoji').andCallThrough();
|
|
|
|
this.component = renderIntoDocument(<EmojiButtonPopover />);
|
|
|
|
this.composer = renderIntoDocument(
|
|
|
|
<Contenteditable
|
|
|
|
html={'Testing!'}
|
|
|
|
onChange={jasmine.createSpy('onChange')}
|
|
|
|
extensions={[EmojiComposerExtension]} />
|
|
|
|
);
|
2016-04-01 07:10:09 +08:00
|
|
|
this.editableNode = findDOMNode(ReactTestUtils.findRenderedDOMComponentWithAttr(this.composer, 'contentEditable'));
|
2016-04-01 05:26:21 +08:00
|
|
|
this.editableNode.innerHTML = "Testing!";
|
|
|
|
const sel = document.getSelection()
|
|
|
|
const textNode = this.editableNode.childNodes[0];
|
|
|
|
sel.setBaseAndExtent(textNode, textNode.nodeValue.length, textNode, textNode.nodeValue.length);
|
2016-04-01 07:10:09 +08:00
|
|
|
this.canvas = findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(this.component, 'canvas'));
|
2016-04-01 05:26:21 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('when inserting emoji', ()=> {
|
|
|
|
it('should insert emoji on click', ()=> {
|
|
|
|
ReactTestUtils.Simulate.mouseDown(this.canvas);
|
|
|
|
waitsFor(()=> {
|
|
|
|
return EmojiComposerExtension._onSelectEmoji.calls.length > 0
|
|
|
|
});
|
|
|
|
expect(this.editableNode.textContent).toEqual("Testing!😀");
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should insert an image for missing emoji', ()=> {
|
|
|
|
const position = {
|
|
|
|
x: 140,
|
|
|
|
y: 60,
|
|
|
|
}
|
|
|
|
EmojiButtonPopover.prototype.calcPosition.andReturn(position);
|
|
|
|
ReactTestUtils.Simulate.mouseDown(this.canvas);
|
|
|
|
waitsFor(()=> {
|
|
|
|
return EmojiComposerExtension._onSelectEmoji.calls.length > 0
|
|
|
|
});
|
|
|
|
expect(this.editableNode.innerHTML.indexOf("missing-emoji") > -1).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
waitsFor(()=> {
|
|
|
|
return EmojiComposerExtension._onSelectEmoji.calls.length > 0
|
|
|
|
});
|
|
|
|
expect(this.editableNode.textContent).toEqual("Testing!😍");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|