@@ -1343,17 +1258,12 @@ exports[`components/integrations/AbstractCommand should match snapshot, displays
-
diff --git a/webapp/channels/src/components/integrations/abstract_command.test.tsx b/webapp/channels/src/components/integrations/abstract_command.test.tsx
index d052b5a0f2..00ac9aa6ea 100644
--- a/webapp/channels/src/components/integrations/abstract_command.test.tsx
+++ b/webapp/channels/src/components/integrations/abstract_command.test.tsx
@@ -1,13 +1,14 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
-import {shallow} from 'enzyme';
import React from 'react';
import type {FormEvent} from 'react';
import {FormattedMessage} from 'react-intl';
import AbstractCommand from 'components/integrations/abstract_command';
+import type {AbstractCommand as AbstractCommandClass} from 'components/integrations/abstract_command';
+import {shallowWithIntl} from 'tests/helpers/intl-test-helper';
import {TestHelper} from 'utils/test_helper';
describe('components/integrations/AbstractCommand', () => {
@@ -56,14 +57,14 @@ describe('components/integrations/AbstractCommand', () => {
};
test('should match snapshot', () => {
- const wrapper = shallow
(
+ const wrapper = shallowWithIntl(
,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot when header/footer/loading is a string', () => {
- const wrapper = shallow(
+ const wrapper = shallowWithIntl(
{
test('should match snapshot, displays client error', () => {
const newSeverError = 'server error';
const props = {...baseProps, serverError: newSeverError};
- const wrapper = shallow(
+ const wrapper = shallowWithIntl(
,
);
@@ -89,7 +90,7 @@ describe('components/integrations/AbstractCommand', () => {
});
test('should call action function', () => {
- const wrapper = shallow(
+ const wrapper = shallowWithIntl(
,
);
@@ -100,9 +101,10 @@ describe('components/integrations/AbstractCommand', () => {
});
test('should match object returned by getStateFromCommand', () => {
- const wrapper = shallow(
+ const wrapper = shallowWithIntl(
,
);
+ const instance = wrapper.instance() as AbstractCommandClass;
const expectedOutput = {
autocomplete: true,
@@ -119,63 +121,65 @@ describe('components/integrations/AbstractCommand', () => {
username: 'username',
};
- expect(wrapper.instance().getStateFromCommand(command)).toEqual(expectedOutput);
+ expect(instance.getStateFromCommand(command)).toEqual(expectedOutput);
});
test('should match state when method is called', () => {
- const wrapper = shallow(
+ const wrapper = shallowWithIntl(
,
);
+ const instance = wrapper.instance() as AbstractCommandClass;
+
const displayName = 'new display_name';
const displayNameEvent = {preventDefault: jest.fn(), target: {value: displayName}} as any;
- wrapper.instance().updateDisplayName(displayNameEvent);
+ instance.updateDisplayName(displayNameEvent);
expect(wrapper.state('displayName')).toEqual(displayName);
const description = 'new description';
const descriptionEvent = {preventDefault: jest.fn(), target: {value: description}} as any;
- wrapper.instance().updateDescription(descriptionEvent);
+ instance.updateDescription(descriptionEvent);
expect(wrapper.state('description')).toEqual(description);
const trigger = 'new trigger';
const triggerEvent = {preventDefault: jest.fn(), target: {value: trigger}} as any;
- wrapper.instance().updateTrigger(triggerEvent);
+ instance.updateTrigger(triggerEvent);
expect(wrapper.state('trigger')).toEqual(trigger);
const url = 'new url';
const urlEvent = {preventDefault: jest.fn(), target: {value: url}} as any;
- wrapper.instance().updateUrl(urlEvent);
+ instance.updateUrl(urlEvent);
expect(wrapper.state('url')).toEqual(url);
const method = 'P';
const methodEvent = {preventDefault: jest.fn(), target: {value: method}} as any;
- wrapper.instance().updateMethod(methodEvent);
+ instance.updateMethod(methodEvent);
expect(wrapper.state('method')).toEqual(method);
const username = 'new username';
const usernameEvent = {preventDefault: jest.fn(), target: {value: username}} as any;
- wrapper.instance().updateUsername(usernameEvent);
+ instance.updateUsername(usernameEvent);
expect(wrapper.state('username')).toEqual(username);
const iconUrl = 'new iconUrl';
const iconUrlEvent = {preventDefault: jest.fn(), target: {value: iconUrl}} as any;
- wrapper.instance().updateIconUrl(iconUrlEvent);
+ instance.updateIconUrl(iconUrlEvent);
expect(wrapper.state('iconUrl')).toEqual(iconUrl);
const trueUpdateAutocompleteEvent = {target: {checked: true}} as any;
const falseeUpdateAutocompleteEvent = {target: {checked: false}} as any;
- wrapper.instance().updateAutocomplete(trueUpdateAutocompleteEvent);
+ instance.updateAutocomplete(trueUpdateAutocompleteEvent);
expect(wrapper.state('autocomplete')).toEqual(true);
- wrapper.instance().updateAutocomplete(falseeUpdateAutocompleteEvent);
+ instance.updateAutocomplete(falseeUpdateAutocompleteEvent);
expect(wrapper.state('autocomplete')).toEqual(false);
const autocompleteHint = 'new autocompleteHint';
const autocompleteHintEvent = {preventDefault: jest.fn(), target: {value: autocompleteHint}} as any;
- wrapper.instance().updateAutocompleteHint(autocompleteHintEvent);
+ instance.updateAutocompleteHint(autocompleteHintEvent);
expect(wrapper.state('autocompleteHint')).toEqual(autocompleteHint);
const autocompleteDescription = 'new autocompleteDescription';
const autocompleteDescriptionEvent = {preventDefault: jest.fn(), target: {value: autocompleteDescription}} as any;
- wrapper.instance().updateAutocompleteDescription(autocompleteDescriptionEvent);
+ instance.updateAutocompleteDescription(autocompleteDescriptionEvent);
expect(wrapper.state('autocompleteDescription')).toEqual(autocompleteDescription);
});
@@ -188,13 +192,14 @@ describe('components/integrations/AbstractCommand', () => {
},
);
const props = {...baseProps, action: newAction};
- const wrapper = shallow(
+ const wrapper = shallowWithIntl(
,
);
+ const instance = wrapper.instance() as AbstractCommandClass;
expect(newAction).toHaveBeenCalledTimes(0);
const evt = {preventDefault: jest.fn()} as unknown as FormEvent;
- const handleSubmit = wrapper.instance().handleSubmit;
+ const handleSubmit = instance.handleSubmit;
handleSubmit(evt);
expect(wrapper.state('saving')).toEqual(true);
expect(wrapper.state('clientError')).toEqual('');
diff --git a/webapp/channels/src/components/integrations/abstract_command.tsx b/webapp/channels/src/components/integrations/abstract_command.tsx
index ce4f81620c..03f93c97d2 100644
--- a/webapp/channels/src/components/integrations/abstract_command.tsx
+++ b/webapp/channels/src/components/integrations/abstract_command.tsx
@@ -3,8 +3,7 @@
import React from 'react';
import type {ChangeEvent} from 'react';
-import {FormattedMessage} from 'react-intl';
-import type {MessageDescriptor} from 'react-intl';
+import {FormattedMessage, type MessageDescriptor, injectIntl, type IntlShape} from 'react-intl';
import {Link} from 'react-router-dom';
import type {Command} from '@mattermost/types/integrations';
@@ -13,11 +12,9 @@ import type {Team} from '@mattermost/types/teams';
import BackstageHeader from 'components/backstage/components/backstage_header';
import ExternalLink from 'components/external_link';
import FormError from 'components/form_error';
-import LocalizedInput from 'components/localized_input/localized_input';
import SpinnerButton from 'components/spinner_button';
import {Constants, DeveloperLinks} from 'utils/constants';
-import {t} from 'utils/i18n';
import * as Utils from 'utils/utils';
const REQUEST_POST = 'P';
@@ -64,6 +61,8 @@ type Props = {
* The async function to run when the action button is pressed
*/
action: (command: Command) => Promise;
+
+ intl: IntlShape;
}
type State= {
@@ -81,7 +80,7 @@ type State= {
autocompleteDescription: string;
}
-export default class AbstractCommand extends React.PureComponent {
+export class AbstractCommand extends React.PureComponent {
constructor(props: Props) {
super(props);
@@ -330,14 +329,17 @@ export default class AbstractCommand extends React.PureComponent {
/>
-
{
/>
-
{
/>
-
{
/>
-
{
/>
-
{
/>
-
{
);
}
}
+
+export default injectIntl(AbstractCommand);
diff --git a/webapp/channels/src/components/integrations/add_command/__snapshots__/add_command.test.tsx.snap b/webapp/channels/src/components/integrations/add_command/__snapshots__/add_command.test.tsx.snap
index ca34aa2a56..77ef7a90b1 100644
--- a/webapp/channels/src/components/integrations/add_command/__snapshots__/add_command.test.tsx.snap
+++ b/webapp/channels/src/components/integrations/add_command/__snapshots__/add_command.test.tsx.snap
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/integrations/AddCommand should match snapshot 1`] = `
-