From ee5f3a4a78cd9a4cc2ed259ce599db95765f24ce Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 11 Jun 2019 14:56:08 +0300 Subject: Message editing --- vnext/src/ui/__tests__/MessageInput-test.js | 59 +++++++++++++++-------------- 1 file changed, 31 insertions(+), 28 deletions(-) (limited to 'vnext/src/ui/__tests__') diff --git a/vnext/src/ui/__tests__/MessageInput-test.js b/vnext/src/ui/__tests__/MessageInput-test.js index 7ac69ed0..9603d1fe 100644 --- a/vnext/src/ui/__tests__/MessageInput-test.js +++ b/vnext/src/ui/__tests__/MessageInput-test.js @@ -12,31 +12,35 @@ const testMessage = { to: {} }; -window.matchMedia = window.matchMedia || function () { +window.matchMedia = window.matchMedia || function() { return { matches: true, - addListener: function () { }, - removeListener: function () { } + addListener: function() { }, + removeListener: function() { } }; }; +function createMessageInput(data, onFocus, onSend, draft) { + return create(, { + createNodeMock: (element) => { + if (element.type === 'textarea') { + // mock a focus function + return { + focus: onFocus, + style: {} + }; + } + return null; + } + }); +} + it('Gives immediate focus on to textarea on load', () => { let focused = false; act(() => { - create( { }} />, { - createNodeMock: (element) => { - if (element.type === 'textarea') { - // mock a focus function - return { - focus: () => { - focused = true; - }, - style: {} - }; - } - return null; - } - }); + createMessageInput(testMessage, () => { + focused = true; + }, () => { }); }); expect(focused).toEqual(true, 'textarea was not focused'); }); @@ -46,17 +50,7 @@ it('Submits on ctrl-enter', () => { const onSend = jest.fn(); var messageInput = null; act(() => { - messageInput = create(, { - createNodeMock: (element) => { - if (element.type === 'textarea') { - return { - focus: () => { }, - style: {} - }; - } - return null; - } - }); + messageInput = createMessageInput(testMessage, () => {}, onSend); }); let textarea = messageInput.root.findByType('textarea'); act(() => { @@ -93,3 +87,12 @@ it('Submits on ctrl-enter', () => { }); expect(textarea.props.value).toEqual('', 'Value should be cleared after submit'); }); + +it('Show draft text', () => { + var messageInput; + act(() => { + messageInput = createMessageInput(testMessage, () => {}, () => {}, 'yo'); + }); + let textarea = messageInput.root.findByType('textarea'); + expect(textarea.props.value).toEqual('yo', 'Value should match draft'); +}); -- cgit v1.2.3