Files
mattermost-webapp/components/message_submit_error.test.jsx
Michael Kochell 4453f86f87 [MM-8338] Option to send as message when an invalid slash command is entered (#1969)
* general feature complete. changed functionality is scoped to create_post.jsx

* textbox now keeps focus after slash command error. submitting twice will force submit the message.

update create_post test

* move "message submit error" into its own component

* handle server error type correctly, and fix some i18n references

* move tests to be next to source code

* fix nested `FormattedMessage` components
2018-11-20 16:38:50 +05:30

56 lines
1.7 KiB
React

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {shallow} from 'enzyme';
import MessageSubmitError from 'components/message_submit_error.jsx';
describe('components/MessageSubmitError', () => {
const baseProps = {
handleSubmit: jest.fn(),
};
it('should display the submit link if the error is for an invalid slash command', () => {
const error = {
message: 'No command found',
server_error_id: 'api.command.execute_command.not_found.app_error',
};
const submittedMessage = 'fakecommand some text';
const props = {
...baseProps,
error,
submittedMessage,
};
const wrapper = shallow(
<MessageSubmitError {...props}/>
);
expect(wrapper.find('[id="message_submit_error.invalidCommand"]').exists()).toBe(true);
expect(wrapper.text()).not.toEqual('No command found');
});
it('should not display the submit link if the error is not for an invalid slash command', () => {
const error = {
message: 'Some server error',
server_error_id: 'api.other_error',
};
const submittedMessage = '/fakecommand some text';
const props = {
...baseProps,
error,
submittedMessage,
};
const wrapper = shallow(
<MessageSubmitError {...props}/>
);
expect(wrapper.find('[id="message_submit_error.invalidCommand"]').exists()).toBe(false);
expect(wrapper.text()).toEqual('Some server error');
});
});