aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/ui/__tests__/MessageInput-test.js
diff options
context:
space:
mode:
Diffstat (limited to 'vnext/src/ui/__tests__/MessageInput-test.js')
-rw-r--r--vnext/src/ui/__tests__/MessageInput-test.js59
1 files changed, 31 insertions, 28 deletions
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(<MessageInput data={data} onSend={onSend} text={draft} />, {
+ 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(<MessageInput data={testMessage} onSend={() => { }} />, {
- 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(<MessageInput data={testMessage} onSend={onSend} />, {
- 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');
+});