aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/ui/__tests__
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-06-11 14:56:08 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:55 +0300
commitee5f3a4a78cd9a4cc2ed259ce599db95765f24ce (patch)
tree7e0243d335af5b93c49d5d29ce80988bbed8b220 /vnext/src/ui/__tests__
parentbe48cd1cccacc0cf5b0f6c84455ab54a6a7bf672 (diff)
Message editing
Diffstat (limited to 'vnext/src/ui/__tests__')
-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');
+});