From 366d1613b768c7154a423357f06683f0064e7cbd Mon Sep 17 00:00:00 2001 From: Deepakumar V U <31596670+deepakumarvu@users.noreply.github.com> Date: Mon, 6 Nov 2023 15:49:38 +0530 Subject: [PATCH] [MM-55106] Replace usage of LocalizedIcon in 'system_notice.tsx' with i/span tags (#25268) --- .../root/__snapshots__/root.test.tsx.snap | 2 +- .../__snapshots__/system_notice.test.tsx.snap | 1281 ++++++++++++++--- .../system_notice/system_notice.test.tsx | 30 +- .../system_notice/system_notice.tsx | 14 +- 4 files changed, 1075 insertions(+), 252 deletions(-) diff --git a/webapp/channels/src/components/root/__snapshots__/root.test.tsx.snap b/webapp/channels/src/components/root/__snapshots__/root.test.tsx.snap index c95df50d77..1495099598 100644 --- a/webapp/channels/src/components/root/__snapshots__/root.test.tsx.snap +++ b/webapp/channels/src/components/root/__snapshots__/root.test.tsx.snap @@ -94,7 +94,7 @@ exports[`components/Root Routes Should mount public product routes 1`] = ` - + diff --git a/webapp/channels/src/components/system_notice/__snapshots__/system_notice.test.tsx.snap b/webapp/channels/src/components/system_notice/__snapshots__/system_notice.test.tsx.snap index 8e06026188..91169f088e 100644 --- a/webapp/channels/src/components/system_notice/__snapshots__/system_notice.test.tsx.snap +++ b/webapp/channels/src/components/system_notice/__snapshots__/system_notice.test.tsx.snap @@ -1,342 +1,1161 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`components/SystemNotice should match snapshot for admin, admin notice 1`] = ` -
- -
-
- some title -
- some body -
- - + + + + + + + + + + + +
- - + + + Only visible to System Admins + + +
+
+ + +
- + `; exports[`components/SystemNotice should match snapshot for admin, regular notice 1`] = ` -
- -
-
- some title + + + + + + + + + + + +
- some body
- - + + +
- + `; exports[`components/SystemNotice should match snapshot for regular user, admin and regular notice 1`] = ` -
- -
-
- some title2 + + + + + + + + + + + +
- some body2
- - + + +
- + `; -exports[`components/SystemNotice should match snapshot for regular user, admin notice 1`] = `""`; +exports[`components/SystemNotice should match snapshot for regular user, admin notice 1`] = ` + +`; -exports[`components/SystemNotice should match snapshot for regular user, dismissed notice 1`] = `""`; +exports[`components/SystemNotice should match snapshot for regular user, dismissed notice 1`] = ` + +`; -exports[`components/SystemNotice should match snapshot for regular user, dont show again notice 1`] = `""`; +exports[`components/SystemNotice should match snapshot for regular user, dont show again notice 1`] = ` + +`; -exports[`components/SystemNotice should match snapshot for regular user, no notice 1`] = `""`; +exports[`components/SystemNotice should match snapshot for regular user, no notice 1`] = ` + +`; exports[`components/SystemNotice should match snapshot for regular user, regular notice 1`] = ` -
- -
-
- some title + + + + + + + + + + + +
- some body
- - + + +
- +
`; -exports[`components/SystemNotice should match snapshot for show function returning false 1`] = `""`; +exports[`components/SystemNotice should match snapshot for show function returning false 1`] = ` + +`; exports[`components/SystemNotice should match snapshot for show function returning true 1`] = ` -
- -
-
- some title + + + + + + + + + + + +
- some body
- - + + +
- +
`; exports[`components/SystemNotice should match snapshot for with allowForget equal false 1`] = ` -
- -
-
- some title + + + + + + + + + + + +
- some body
- + some title +
+ some body +
+ +
- +
`; exports[`components/SystemNotice should match snapshot when a custom icon is passed 1`] = ` -
+ icon + , + "name": "notice1", + "show": [Function], + "title": "some title", + }, + ] + } + preferences={Object {}} + serverVersion="5.1" >
- - icon - -
-
- some title + + icon +
- some body
- - + + +
- +
`; diff --git a/webapp/channels/src/components/system_notice/system_notice.test.tsx b/webapp/channels/src/components/system_notice/system_notice.test.tsx index 84d902025a..35b7d25a42 100644 --- a/webapp/channels/src/components/system_notice/system_notice.test.tsx +++ b/webapp/channels/src/components/system_notice/system_notice.test.tsx @@ -1,11 +1,12 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {shallow} from 'enzyme'; import React from 'react'; import SystemNotice from 'components/system_notice/system_notice'; +import {mountWithIntl, type MockIntl} from 'tests/helpers/intl-test-helper'; + describe('components/SystemNotice', () => { const baseProps = { currentUserId: 'someid', @@ -17,6 +18,9 @@ describe('components/SystemNotice', () => { license: {IsLicensed: 'true'}, config: {}, analytics: {TOTAL_USERS: 300}, + intl: { + formatMessage: jest.fn(), + } as MockIntl, actions: { savePreferences: jest.fn(), dismissNotice: jest.fn(), @@ -25,19 +29,19 @@ describe('components/SystemNotice', () => { }; test('should match snapshot for regular user, regular notice', () => { - const wrapper = shallow(); + const wrapper = mountWithIntl(); expect(wrapper).toMatchSnapshot(); }); test('should match snapshot for regular user, no notice', () => { const props = {...baseProps, notices: []}; - const wrapper = shallow(); + const wrapper = mountWithIntl(); expect(wrapper).toMatchSnapshot(); }); test('should match snapshot for regular user, admin notice', () => { const props = {...baseProps, notices: [{...baseProps.notices[0], adminOnly: true}]}; - const wrapper = shallow(); + const wrapper = mountWithIntl(); expect(wrapper).toMatchSnapshot(); }); @@ -47,55 +51,55 @@ describe('components/SystemNotice', () => { {...baseProps.notices[0], adminOnly: true}, {...baseProps.notices[0], name: 'notice2', title: 'some title2', body: 'some body2'}, ]}; - const wrapper = shallow(); + const wrapper = mountWithIntl(); expect(wrapper).toMatchSnapshot(); }); test('should match snapshot for admin, regular notice', () => { const props = {...baseProps, isSystemAdmin: true}; - const wrapper = shallow(); + const wrapper = mountWithIntl(); expect(wrapper).toMatchSnapshot(); }); test('should match snapshot for admin, admin notice', () => { const props = {...baseProps, isSystemAdmin: true, notices: [{...baseProps.notices[0], adminOnly: true}]}; - const wrapper = shallow(); + const wrapper = mountWithIntl(); expect(wrapper).toMatchSnapshot(); }); test('should match snapshot for regular user, dismissed notice', () => { const props = {...baseProps, dismissedNotices: {notice1: true}}; - const wrapper = shallow(); + const wrapper = mountWithIntl(); expect(wrapper).toMatchSnapshot(); }); test('should match snapshot for regular user, dont show again notice', () => { const props = {...baseProps, preferences: {notice1: {}}}; - const wrapper = shallow(); + const wrapper = mountWithIntl(); expect(wrapper).toMatchSnapshot(); }); test('should match snapshot for show function returning false', () => { const props = {...baseProps, notices: [{...baseProps.notices[0], show: () => false}]}; - const wrapper = shallow(); + const wrapper = mountWithIntl(); expect(wrapper).toMatchSnapshot(); }); test('should match snapshot for show function returning true', () => { const props = {...baseProps, notices: [{...baseProps.notices[0], show: () => true}]}; - const wrapper = shallow(); + const wrapper = mountWithIntl(); expect(wrapper).toMatchSnapshot(); }); test('should match snapshot for with allowForget equal false', () => { const props = {...baseProps, notices: [{...baseProps.notices[0], allowForget: false}]}; - const wrapper = shallow(); + const wrapper = mountWithIntl(); expect(wrapper).toMatchSnapshot(); }); test('should match snapshot when a custom icon is passed', () => { const props = {...baseProps, notices: [{...baseProps.notices[0], icon: {'icon'}}]}; - const wrapper = shallow(); + const wrapper = mountWithIntl(); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/webapp/channels/src/components/system_notice/system_notice.tsx b/webapp/channels/src/components/system_notice/system_notice.tsx index 97cc7f9ca5..4c8132a8cf 100644 --- a/webapp/channels/src/components/system_notice/system_notice.tsx +++ b/webapp/channels/src/components/system_notice/system_notice.tsx @@ -2,21 +2,19 @@ // See LICENSE.txt for license information. import React from 'react'; -import {FormattedMessage} from 'react-intl'; +import {FormattedMessage, injectIntl, type WrappedComponentProps} from 'react-intl'; import type {AnalyticsRow} from '@mattermost/types/admin'; import type {Channel} from '@mattermost/types/channels'; import type {ClientConfig, ClientLicense} from '@mattermost/types/config'; import type {PreferenceType} from '@mattermost/types/preferences'; -import LocalizedIcon from 'components/localized_icon'; import type {Notice} from 'components/system_notice/types'; import MattermostLogo from 'components/widgets/icons/mattermost_logo'; import {Preferences} from 'utils/constants'; -import {t} from 'utils/i18n'; -type Props = { +interface Props extends WrappedComponentProps { currentUserId: string; notices: Notice[]; preferences: {[key: string]: any}; @@ -33,7 +31,7 @@ type Props = { getStandardAnalytics(teamId?: string): void; }; } -export default class SystemNotice extends React.PureComponent { +export class SystemNotice extends React.PureComponent { componentDidMount() { if (this.props.isSystemAdmin) { this.props.actions.getStandardAnalytics(); @@ -114,9 +112,9 @@ export default class SystemNotice extends React.PureComponent { if (notice.adminOnly) { visibleMessage = (
- { ); } } + +export default injectIntl(SystemNotice);