mattermost-mobile/app/screens/edit_post/edit_post.test.js
Amit Uttam 446f95ff6b
MM-21368 Notify user when editing message that's too long (#4371)
* MM-21368 Notify user when editing message that's too long

* Disable 'Save' button to prevent edits from being posted
* Display error message specific to the message size and allows max, instead of the current, default "Invalid Message" error.

* Split message length error into text (left justified) and counts (right justified)

UX guidance from PR review

* UX Review: Wrap for longer error text + spacing adjustment

* UX Review: Align split messages to top + add spacing in-between

* UX Review: Align error message box padding with content
2020-06-10 13:01:40 -03:00

96 lines
2.6 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {Keyboard} from 'react-native';
import Preferences from '@mm-redux/constants/preferences';
import {shallowWithIntl} from 'test/intl-test-helper';
import EditPost from './edit_post';
describe('EditPost', () => {
const baseProps = {
actions: {
editPost: jest.fn(),
},
post: {},
theme: Preferences.THEMES.default,
isLandscape: false,
};
test('should match snapshot', () => {
const wrapper = shallowWithIntl(
<EditPost {...baseProps}/>,
);
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should dismiss keyboard on close', () => {
Keyboard.dismiss = jest.fn();
expect(Keyboard.dismiss).not.toHaveBeenCalled();
const wrapper = shallowWithIntl(
<EditPost {...baseProps}/>,
);
wrapper.instance().close();
expect(Keyboard.dismiss).toHaveBeenCalledTimes(1);
});
test('should handle edit post action error', async () => {
const error = 'error';
const props = {
...baseProps,
actions: {
editPost: jest.fn().mockResolvedValueOnce({error}),
},
};
const wrapper = shallowWithIntl(
<EditPost {...props}/>,
);
const instance = wrapper.instance();
instance.emitEditing = jest.fn();
instance.setState = jest.fn();
await instance.onEditPost();
expect(instance.emitEditing.mock.calls).toEqual([
[true],
[false],
]);
expect(instance.setState.mock.calls).toEqual([
[{editing: true, error: null, errorExtra: null}],
[{editing: false, error}, instance.focus],
]);
});
test('should handle edit post action success', async () => {
const props = {
...baseProps,
actions: {
editPost: jest.fn().mockResolvedValueOnce({}),
},
};
const wrapper = shallowWithIntl(
<EditPost {...props}/>,
);
const instance = wrapper.instance();
instance.emitEditing = jest.fn();
instance.setState = jest.fn();
await instance.onEditPost();
expect(instance.emitEditing.mock.calls).toEqual([
[true],
[false],
]);
expect(instance.setState.mock.calls).toEqual([
[{editing: true, error: null, errorExtra: null}],
[{editing: false}, instance.close],
]);
});
});