From 176370e1751cf81fb5015c7c7e114069648d6676 Mon Sep 17 00:00:00 2001 From: Balaji K Date: Wed, 11 Oct 2023 11:46:45 +0530 Subject: [PATCH] [MM-54835] Convert LocalizedInput of 'custom_url_schemes_setting.tsx' to regular input component (#24854) --- .../custom_url_schemes_setting.test.tsx.snap | 544 ++++++++++++++---- .../custom_url_schemes_setting.test.tsx | 34 +- .../custom_url_schemes_setting.tsx | 42 +- 3 files changed, 476 insertions(+), 144 deletions(-) diff --git a/webapp/channels/src/components/admin_console/__snapshots__/custom_url_schemes_setting.test.tsx.snap b/webapp/channels/src/components/admin_console/__snapshots__/custom_url_schemes_setting.test.tsx.snap index 2305ba4214..433104f946 100644 --- a/webapp/channels/src/components/admin_console/__snapshots__/custom_url_schemes_setting.test.tsx.snap +++ b/webapp/channels/src/components/admin_console/__snapshots__/custom_url_schemes_setting.test.tsx.snap @@ -1,121 +1,465 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with multiple items 1`] = ` - - - + } + onChange={[MockFunction]} + setByEnv={false} + value={ + Array [ + "git", + "smtp", + "steam", + ] + } +> + +
+ +
+ +
+ Allows message text to link if it begins with any of the comma-separated URL schemes listed. By default, the following schemes will create links: "http", "https", "ftp", "tel", and "mailto". +
+
+
+
+ `; exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with no items 1`] = ` - - - + } + onChange={[MockFunction]} + setByEnv={false} + value={Array []} +> + +
+ +
+ +
+ Allows message text to link if it begins with any of the comma-separated URL schemes listed. By default, the following schemes will create links: "http", "https", "ftp", "tel", and "mailto". +
+
+
+
+ `; exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with one item 1`] = ` - - - + } + onChange={[MockFunction]} + setByEnv={false} + value={ + Array [ + "git", + ] + } +> + +
+ +
+ +
+ Allows message text to link if it begins with any of the comma-separated URL schemes listed. By default, the following schemes will create links: "http", "https", "ftp", "tel", and "mailto". +
+
+
+
+ `; exports[`components/AdminConsole/CustomUrlSchemeSetting renders properly when disabled 1`] = ` - - - + } + onChange={[MockFunction]} + setByEnv={false} + value={ + Array [ + "git", + "smtp", + ] + } +> + +
+ +
+ +
+ Allows message text to link if it begins with any of the comma-separated URL schemes listed. By default, the following schemes will create links: "http", "https", "ftp", "tel", and "mailto". +
+
+
+
+ `; exports[`components/AdminConsole/CustomUrlSchemeSetting renders properly when set by environment variable 1`] = ` - - - + } + onChange={[MockFunction]} + setByEnv={true} + value={ + Array [ + "git", + "smtp", + ] + } +> + +
+ +
+ +
+ Allows message text to link if it begins with any of the comma-separated URL schemes listed. By default, the following schemes will create links: "http", "https", "ftp", "tel", and "mailto". +
+ +
+ + + This setting has been set through an environment variable. It cannot be changed through the System Console. + + +
+
+
+
+
+ `; diff --git a/webapp/channels/src/components/admin_console/custom_url_schemes_setting.test.tsx b/webapp/channels/src/components/admin_console/custom_url_schemes_setting.test.tsx index de0c9f09c9..7aaf8dcc20 100644 --- a/webapp/channels/src/components/admin_console/custom_url_schemes_setting.test.tsx +++ b/webapp/channels/src/components/admin_console/custom_url_schemes_setting.test.tsx @@ -1,11 +1,11 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {shallow} from 'enzyme'; import React from 'react'; import CustomURLSchemesSetting from 'components/admin_console/custom_url_schemes_setting'; -import LocalizedInput from 'components/localized_input/localized_input'; + +import {mountWithIntl} from 'tests/helpers/intl-test-helper'; describe('components/AdminConsole/CustomUrlSchemeSetting', () => { const baseProps = { @@ -23,7 +23,7 @@ describe('components/AdminConsole/CustomUrlSchemeSetting', () => { value: [], }; - const wrapper = shallow( + const wrapper = mountWithIntl( , ); expect(wrapper).toMatchSnapshot(); @@ -37,7 +37,7 @@ describe('components/AdminConsole/CustomUrlSchemeSetting', () => { value: ['git'], }; - const wrapper = shallow( + const wrapper = mountWithIntl( , ); expect(wrapper).toMatchSnapshot(); @@ -51,7 +51,7 @@ describe('components/AdminConsole/CustomUrlSchemeSetting', () => { value: ['git', 'smtp', 'steam'], }; - const wrapper = shallow( + const wrapper = mountWithIntl( , ); expect(wrapper).toMatchSnapshot(); @@ -67,11 +67,11 @@ describe('components/AdminConsole/CustomUrlSchemeSetting', () => { onChange: jest.fn(), }; - const wrapper = shallow( + const wrapper = mountWithIntl( , ); - wrapper.find(LocalizedInput).simulate('change', {target: {value: ''}}); + wrapper.find('input').simulate('change', {target: {value: ''}}); expect(props.onChange).toBeCalledWith(baseProps.id, []); }); @@ -82,11 +82,11 @@ describe('components/AdminConsole/CustomUrlSchemeSetting', () => { onChange: jest.fn(), }; - const wrapper = shallow( + const wrapper = mountWithIntl( , ); - wrapper.find(LocalizedInput).simulate('change', {target: {value: ' steam '}}); + wrapper.find('input').simulate('change', {target: {value: ' steam '}}); expect(props.onChange).toBeCalledWith(baseProps.id, ['steam']); }); @@ -97,11 +97,11 @@ describe('components/AdminConsole/CustomUrlSchemeSetting', () => { onChange: jest.fn(), }; - const wrapper = shallow( + const wrapper = mountWithIntl( , ); - wrapper.find(LocalizedInput).simulate('change', {target: {value: 'steam, git'}}); + wrapper.find('input').simulate('change', {target: {value: 'steam, git'}}); expect(props.onChange).toBeCalledWith(baseProps.id, ['steam', 'git']); }); @@ -112,11 +112,11 @@ describe('components/AdminConsole/CustomUrlSchemeSetting', () => { onChange: jest.fn(), }; - const wrapper = shallow( + const wrapper = mountWithIntl( , ); - wrapper.find(LocalizedInput).simulate('change', {target: {value: 'ts3server, smtp, ms-excel'}}); + wrapper.find('input').simulate('change', {target: {value: 'ts3server, smtp, ms-excel'}}); expect(props.onChange).toBeCalledWith(baseProps.id, ['ts3server', 'smtp', 'ms-excel']); }); @@ -127,11 +127,11 @@ describe('components/AdminConsole/CustomUrlSchemeSetting', () => { onChange: jest.fn(), }; - const wrapper = shallow( + const wrapper = mountWithIntl( , ); - wrapper.find(LocalizedInput).simulate('change', {target: {value: ',,,,,chrome,,,,ms-excel,,'}}); + wrapper.find('input').simulate('change', {target: {value: ',,,,,chrome,,,,ms-excel,,'}}); expect(props.onChange).toBeCalledWith(baseProps.id, ['chrome', 'ms-excel']); }); @@ -143,7 +143,7 @@ describe('components/AdminConsole/CustomUrlSchemeSetting', () => { disabled: true, }; - const wrapper = shallow( + const wrapper = mountWithIntl( , ); expect(wrapper).toMatchSnapshot(); @@ -155,7 +155,7 @@ describe('components/AdminConsole/CustomUrlSchemeSetting', () => { setByEnv: true, }; - const wrapper = shallow( + const wrapper = mountWithIntl( , ); expect(wrapper).toMatchSnapshot(); diff --git a/webapp/channels/src/components/admin_console/custom_url_schemes_setting.tsx b/webapp/channels/src/components/admin_console/custom_url_schemes_setting.tsx index 1908569885..fecd5f9ec9 100644 --- a/webapp/channels/src/components/admin_console/custom_url_schemes_setting.tsx +++ b/webapp/channels/src/components/admin_console/custom_url_schemes_setting.tsx @@ -1,14 +1,9 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import PropTypes from 'prop-types'; import React, {PureComponent} from 'react'; import type {ChangeEvent} from 'react'; - -import LocalizedInput from 'components/localized_input/localized_input'; - -import {t} from 'utils/i18n'; -import * as Utils from 'utils/utils'; +import {injectIntl, type IntlShape} from 'react-intl'; import Setting from './setting'; @@ -18,24 +13,15 @@ type Props = { onChange: (id: string, valueAsArray: string[]) => void; disabled: boolean; setByEnv: boolean; + intl: IntlShape; } type State = { value: string; } -export default class CustomURLSchemesSetting extends +class CustomURLSchemesSetting extends PureComponent { - static get propTypes() { - return { - id: PropTypes.string.isRequired, - value: PropTypes.array.isRequired, - onChange: PropTypes.func.isRequired, - disabled: PropTypes.bool, - setByEnv: PropTypes.bool.isRequired, - }; - } - constructor(props: Props) { super(props); @@ -63,24 +49,24 @@ export default class CustomURLSchemesSetting extends }; render() { - const label = Utils.localizeMessage('admin.customization.customUrlSchemes', 'Custom URL Schemes:'); - const helpText = Utils.localizeMessage( - 'admin.customization.customUrlSchemesDesc', - 'Allows message text to link if it begins with any of the comma-separated URL schemes listed. By default, the following schemes will create links: "http", "https", "ftp", "tel", and "mailto".', - ); - return ( -