diff --git a/webapp/channels/src/components/user_settings/security/__snapshots__/user_settings_security.test.tsx.snap b/webapp/channels/src/components/user_settings/security/__snapshots__/user_settings_security.test.tsx.snap index e4837e5b96..fb9724c662 100644 --- a/webapp/channels/src/components/user_settings/security/__snapshots__/user_settings_security.test.tsx.snap +++ b/webapp/channels/src/components/user_settings/security/__snapshots__/user_settings_security.test.tsx.snap @@ -24,15 +24,10 @@ exports[`components/user_settings/display/UserSettingsDisplay should match snaps
-
- - - - - - - - - - - { const original = jest.requireActual('utils/utils'); @@ -45,40 +47,43 @@ describe('components/user_settings/display/UserSettingsDisplay', () => { experimentalEnableAuthenticationTransfer: true, passwordConfig: {} as ReturnType, militaryTime: false, + intl: { + formatMessage: jest.fn(({id, defaultMessage}) => defaultMessage || id), + } as MockIntl, }; test('should match snapshot, enable google', () => { const props = {...requiredProps, enableSaml: false}; - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); test('should match snapshot, enable gitlab', () => { const props = {...requiredProps, enableSignUpWithGoogle: false, enableSaml: false, enableSignUpWithGitLab: true}; - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); test('should match snapshot, enable office365', () => { const props = {...requiredProps, enableSignUpWithGoogle: false, enableSaml: false, enableSignUpWithOffice365: true}; - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); test('should match snapshot, enable openID', () => { const props = {...requiredProps, enableSignUpWithGoogle: false, enableSaml: false, enableSignUpWithOpenId: true}; - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); test('componentDidMount() should have called getAuthorizedOAuthApps', () => { const props = {...requiredProps, enableOAuthServiceProvider: true}; - shallow(); + shallow(); expect(requiredProps.actions.getAuthorizedOAuthApps).toHaveBeenCalled(); }); @@ -93,7 +98,7 @@ describe('components/user_settings/display/UserSettingsDisplay', () => { enableOAuthServiceProvider: true, }; - const wrapper = shallow(); + const wrapper = shallow(); await promise; @@ -110,7 +115,7 @@ describe('components/user_settings/display/UserSettingsDisplay', () => { enableOAuthServiceProvider: true, }; - const wrapper = shallow(); + const wrapper = shallow(); await promise; @@ -118,9 +123,9 @@ describe('components/user_settings/display/UserSettingsDisplay', () => { }); test('submitPassword() should not have called updateUserPassword', async () => { - const wrapper = shallow(); + const wrapper = shallow(); - await (wrapper.instance() as UserSettingsSecurity).submitPassword(); + await wrapper.instance().submitPassword(); expect(requiredProps.actions.updateUserPassword).toHaveBeenCalledTimes(0); }); @@ -130,7 +135,7 @@ describe('components/user_settings/display/UserSettingsDisplay', () => { ...requiredProps, actions: {...requiredProps.actions, updateUserPassword}, }; - const wrapper = shallow(); + const wrapper = shallow(); const password = 'psw'; const state = { @@ -140,7 +145,7 @@ describe('components/user_settings/display/UserSettingsDisplay', () => { }; wrapper.setState(state); - await (wrapper.instance() as UserSettingsSecurity).submitPassword(); + await wrapper.instance().submitPassword(); expect(updateUserPassword).toHaveBeenCalled(); expect(updateUserPassword).toHaveBeenCalledWith( @@ -160,9 +165,9 @@ describe('components/user_settings/display/UserSettingsDisplay', () => { preventDefault: jest.fn(), }; - const wrapper = shallow(); + const wrapper = shallow(); wrapper.setState({authorizedApps: []}); - (wrapper.instance() as UserSettingsSecurity).deauthorizeApp(event); + wrapper.instance().deauthorizeApp(event); expect(requiredProps.actions.deauthorizeOAuthApp).toHaveBeenCalled(); expect(requiredProps.actions.deauthorizeOAuthApp).toHaveBeenCalledWith( @@ -177,16 +182,16 @@ describe('components/user_settings/display/UserSettingsDisplay', () => { actions: {...requiredProps.actions, deauthorizeOAuthApp: () => promise}, }; - const wrapper: any = shallow(); + const wrapper = shallow(); const appId = 'appId'; - const apps = [{id: appId}, {id: '2'}]; + const apps = [{id: appId}, {id: '2'}] as OAuthApp[]; const event: any = { currentTarget: {getAttribute: jest.fn().mockReturnValue(appId)}, preventDefault: jest.fn(), }; wrapper.setState({authorizedApps: apps}); - (wrapper.instance() as UserSettingsSecurity).deauthorizeApp(event); + wrapper.instance().deauthorizeApp(event); await promise; @@ -201,13 +206,13 @@ describe('components/user_settings/display/UserSettingsDisplay', () => { actions: {...requiredProps.actions, deauthorizeOAuthApp: () => promise}, }; - const wrapper: any = shallow(); + const wrapper = shallow(); const event: any = { currentTarget: {getAttribute: jest.fn().mockReturnValue('appId')}, preventDefault: jest.fn(), }; - (wrapper.instance() as UserSettingsSecurity).deauthorizeApp(event); + wrapper.instance().deauthorizeApp(event); await promise; diff --git a/webapp/channels/src/components/user_settings/security/user_settings_security.tsx b/webapp/channels/src/components/user_settings/security/user_settings_security.tsx index a1e1d76ebb..bab05c9017 100644 --- a/webapp/channels/src/components/user_settings/security/user_settings_security.tsx +++ b/webapp/channels/src/components/user_settings/security/user_settings_security.tsx @@ -4,7 +4,8 @@ /* eslint-disable max-lines */ import React from 'react'; -import {FormattedDate, FormattedMessage, FormattedTime} from 'react-intl'; +import type {IntlShape} from 'react-intl'; +import {FormattedDate, FormattedMessage, FormattedTime, injectIntl} from 'react-intl'; import {Link} from 'react-router-dom'; import type {OAuthApp} from '@mattermost/types/integrations'; @@ -15,14 +16,12 @@ import type {ActionResult} from 'mattermost-redux/types/actions'; import AccessHistoryModal from 'components/access_history_modal'; import ActivityLogModal from 'components/activity_log_modal'; import ExternalLink from 'components/external_link'; -import LocalizedIcon from 'components/localized_icon'; import SettingItem from 'components/setting_item'; import SettingItemMax from 'components/setting_item_max'; import ToggleModalButton from 'components/toggle_modal_button'; import icon50 from 'images/icon50x50.png'; import Constants from 'utils/constants'; -import {t} from 'utils/i18n'; import * as Utils from 'utils/utils'; import MfaSection from './mfa_section'; @@ -65,6 +64,7 @@ type Props = { passwordConfig: ReturnType; militaryTime: boolean; actions: Actions; + intl: IntlShape; }; type State = { @@ -78,7 +78,7 @@ type State = { authorizedApps: OAuthApp[]; }; -export default class SecurityTab extends React.PureComponent { +export class SecurityTab extends React.PureComponent { constructor(props: Props) { super(props); this.state = this.getDefaultState(); @@ -123,10 +123,10 @@ export default class SecurityTab extends React.PureComponent { if (currentPassword === '') { this.setState({ - passwordError: Utils.localizeMessage( - 'user.settings.security.currentPasswordError', - 'Please enter your current password.', - ), + passwordError: this.props.intl.formatMessage({ + id: 'user.settings.security.currentPasswordError', + defaultMessage: 'Please enter your current password.', + }), serverError: '', }); return; @@ -146,10 +146,11 @@ export default class SecurityTab extends React.PureComponent { if (newPassword !== confirmPassword) { const defaultState = Object.assign(this.getDefaultState(), { - passwordError: Utils.localizeMessage( - 'user.settings.security.passwordMatchError', - 'The new passwords you entered do not match.', - ), + passwordError: this.props.intl.formatMessage({ + id: 'user.settings.security.passwordMatchError', + defaultMessage: + 'The new passwords you entered do not match.', + }), serverError: '', }); this.setState(defaultState); @@ -267,10 +268,10 @@ export default class SecurityTab extends React.PureComponent { type='password' onChange={this.updateCurrentPassword} value={this.state.currentPassword} - aria-label={Utils.localizeMessage( - 'user.settings.security.currentPassword', - 'Current Password', - )} + aria-label={this.props.intl.formatMessage({ + id: 'user.settings.security.currentPassword', + defaultMessage: 'Current Password', + })} /> , @@ -293,10 +294,10 @@ export default class SecurityTab extends React.PureComponent { type='password' onChange={this.updateNewPassword} value={this.state.newPassword} - aria-label={Utils.localizeMessage( - 'user.settings.security.newPassword', - 'New Password', - )} + aria-label={this.props.intl.formatMessage({ + id: 'user.settings.security.newPassword', + defaultMessage: 'New Password', + })} /> , @@ -319,10 +320,10 @@ export default class SecurityTab extends React.PureComponent { type='password' onChange={this.updateConfirmPassword} value={this.state.confirmPassword} - aria-label={Utils.localizeMessage( - 'user.settings.security.retypePassword', - 'Retype New Password', - )} + aria-label={this.props.intl.formatMessage({ + id: 'user.settings.security.retypePassword', + defaultMessage: 'Retype New Password', + })} /> , @@ -721,10 +722,10 @@ export default class SecurityTab extends React.PureComponent { max = ( { { { type='button' className='close' data-dismiss='modal' - aria-label={Utils.localizeMessage('user.settings.security.close', 'Close')} + aria-label={this.props.intl.formatMessage({ + id: 'user.settings.security.close', + defaultMessage: 'Close', + })} onClick={this.props.closeModal} > @@ -1003,9 +1007,12 @@ export default class SecurityTab extends React.PureComponent { className='modal-title' >
-
@@ -1044,9 +1051,12 @@ export default class SecurityTab extends React.PureComponent { dialogType={AccessHistoryModal} id='viewAccessHistory' > - { dialogType={ActivityLogModal} id='viewAndLogOutOfActiveSessions' > - { ); } } + +export default injectIntl(SecurityTab);