* MM-21176 Preserve text on input if command fails * Add unit test for execute command success
This commit is contained in:
parent
765545570f
commit
1f83ccbb6d
2 changed files with 30 additions and 4 deletions
|
|
@ -333,6 +333,34 @@ describe('PostTextBox', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should preseve post message in the input field if the command failed', async () => {
|
||||
const props = {...baseProps};
|
||||
const errorResult = {error: {message: 'Error message'}};
|
||||
props.actions.executeCommand = jest.fn().
|
||||
mockResolvedValueOnce(errorResult).
|
||||
mockResolvedValue({data: 'success'});
|
||||
|
||||
const wrapper = shallowWithIntl(
|
||||
<PostTextbox {...props}/>
|
||||
);
|
||||
|
||||
const msg = '/fail preserve this text in the post draft';
|
||||
const instance = wrapper.instance();
|
||||
instance.handleTextChange(msg);
|
||||
expect(wrapper.state('value')).toBe(msg);
|
||||
|
||||
// On error, should prompt Alert dialog and should remain text value
|
||||
await instance.sendCommand(msg);
|
||||
expect(Alert.alert).toHaveBeenCalledTimes(1);
|
||||
expect(Alert.alert).toHaveBeenCalledWith('Error Executing Command', errorResult.error.message);
|
||||
expect(wrapper.state('value')).toBe(msg);
|
||||
|
||||
// On success, should not prompt Alert dialog and should change text value to empty
|
||||
await instance.sendCommand(msg);
|
||||
expect(Alert.alert).toHaveBeenCalledTimes(1);
|
||||
expect(wrapper.state('value')).toBe('');
|
||||
});
|
||||
|
||||
describe('Paste images', () => {
|
||||
test('should show error dialog if error occured', () => {
|
||||
jest.spyOn(Alert, 'alert').mockReturnValue(null);
|
||||
|
|
|
|||
|
|
@ -599,10 +599,9 @@ export default class PostTextBoxBase extends PureComponent {
|
|||
}
|
||||
|
||||
const {error} = await actions.executeCommand(msg, channelId, rootId);
|
||||
this.setState({sendingMessage: false});
|
||||
|
||||
if (error) {
|
||||
this.handleTextChange(msg);
|
||||
this.changeDraft(msg);
|
||||
Alert.alert(
|
||||
intl.formatMessage({
|
||||
id: 'mobile.commands.error_title',
|
||||
|
|
@ -610,12 +609,11 @@ export default class PostTextBoxBase extends PureComponent {
|
|||
}),
|
||||
error.message
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
this.handleTextChange('');
|
||||
this.changeDraft('');
|
||||
|
||||
this.setState({sendingMessage: false});
|
||||
};
|
||||
|
||||
sendReaction = (emoji) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue