From dd1e5bc9d091fef3cf4e9236a3ec652aec49bd10 Mon Sep 17 00:00:00 2001 From: Balaji K Date: Mon, 30 Oct 2023 10:14:01 +0530 Subject: [PATCH] [MM-55123] Replace the usage of LocalizedIcon in 'loading_spinner.tsx' with i/span tags (#25139) --- .../loading_image_preview.test.tsx.snap | 8 +- .../__snapshots__/pdf_preview.test.jsx.snap | 4 +- .../__snapshots__/data_grid.test.tsx.snap | 4 +- .../apps_form_component.test.tsx.snap | 3 +- .../src/components/login/login.test.tsx | 15 +- .../src/components/login/login_mfa.test.tsx | 8 +- .../action_button/action_button.test.tsx | 18 +-- .../loading_spinner.test.tsx.snap | 28 ++++ .../loading_wrapper.test.tsx.snap | 134 +++++++++++++----- .../widgets/loading/loading_spinner.test.tsx | 46 +----- .../widgets/loading/loading_spinner.tsx | 25 ++-- .../widgets/loading/loading_wrapper.test.tsx | 5 +- 12 files changed, 175 insertions(+), 123 deletions(-) create mode 100644 webapp/channels/src/components/widgets/loading/__snapshots__/loading_spinner.test.tsx.snap diff --git a/webapp/channels/src/components/__snapshots__/loading_image_preview.test.tsx.snap b/webapp/channels/src/components/__snapshots__/loading_image_preview.test.tsx.snap index 047424e4d4..daef7ac95a 100644 --- a/webapp/channels/src/components/__snapshots__/loading_image_preview.test.tsx.snap +++ b/webapp/channels/src/components/__snapshots__/loading_image_preview.test.tsx.snap @@ -4,9 +4,7 @@ exports[`components/LoadingImagePreview should match snapshot 1`] = `
- + @@ -19,9 +17,7 @@ exports[`components/LoadingImagePreview should match snapshot 2`] = `
- + diff --git a/webapp/channels/src/components/__snapshots__/pdf_preview.test.jsx.snap b/webapp/channels/src/components/__snapshots__/pdf_preview.test.jsx.snap index dfed5722cf..3bb96304b6 100644 --- a/webapp/channels/src/components/__snapshots__/pdf_preview.test.jsx.snap +++ b/webapp/channels/src/components/__snapshots__/pdf_preview.test.jsx.snap @@ -4,9 +4,7 @@ exports[`component/PDFPreview should match snapshot, loading 1`] = `
- +
`; diff --git a/webapp/channels/src/components/admin_console/data_grid/__snapshots__/data_grid.test.tsx.snap b/webapp/channels/src/components/admin_console/data_grid/__snapshots__/data_grid.test.tsx.snap index 9ce41e5db3..e0291b7061 100644 --- a/webapp/channels/src/components/admin_console/data_grid/__snapshots__/data_grid.test.tsx.snap +++ b/webapp/channels/src/components/admin_console/data_grid/__snapshots__/data_grid.test.tsx.snap @@ -19,9 +19,7 @@ exports[`components/admin_console/data_grid/DataGrid should match snapshot while
- + -
diff --git a/webapp/channels/src/components/login/login.test.tsx b/webapp/channels/src/components/login/login.test.tsx index 2d04413214..293a77eafb 100644 --- a/webapp/channels/src/components/login/login.test.tsx +++ b/webapp/channels/src/components/login/login.test.tsx @@ -1,7 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {shallow, mount} from 'enzyme'; +import {shallow} from 'enzyme'; import React from 'react'; import {IntlProvider} from 'react-intl'; import {MemoryRouter} from 'react-router-dom'; @@ -20,6 +20,7 @@ import SaveButton from 'components/save_button'; import Input from 'components/widgets/inputs/input/input'; import PasswordInput from 'components/widgets/inputs/password_input/password_input'; +import {mountWithIntl} from 'tests/helpers/intl-test-helper'; import Constants, {WindowSizes} from 'utils/constants'; import type {GlobalState} from 'types/store'; @@ -152,7 +153,7 @@ describe('components/login/Login', () => { LocalStorageStore.setWasLoggedIn(true); mockConfig.EnableSignInWithEmail = 'true'; - const wrapper = mount( + const wrapper = mountWithIntl( , ); @@ -174,7 +175,7 @@ describe('components/login/Login', () => { messages: {}, }; - const wrapper = mount( + const wrapper = mountWithIntl( @@ -195,7 +196,7 @@ describe('components/login/Login', () => { messages: {}, }; - const wrapper = mount( + const wrapper = mountWithIntl( , @@ -210,7 +211,7 @@ describe('components/login/Login', () => { LocalStorageStore.setWasLoggedIn(true); mockConfig.EnableSignInWithEmail = 'true'; - const wrapper = mount( + const wrapper = mountWithIntl( , @@ -231,7 +232,7 @@ describe('components/login/Login', () => { LocalStorageStore.setWasLoggedIn(true); mockConfig.EnableSignInWithEmail = 'true'; - const wrapper = mount( + const wrapper = mountWithIntl( , @@ -297,7 +298,7 @@ describe('components/login/Login', () => { mockConfig.EnableSignInWithEmail = 'true'; const redirectPath = '/boards/team/teamID/boardID'; mockLocation.search = '?redirect_to=' + redirectPath; - mount( + mountWithIntl( , diff --git a/webapp/channels/src/components/login/login_mfa.test.tsx b/webapp/channels/src/components/login/login_mfa.test.tsx index 8c7544d1f5..e391952068 100644 --- a/webapp/channels/src/components/login/login_mfa.test.tsx +++ b/webapp/channels/src/components/login/login_mfa.test.tsx @@ -1,12 +1,14 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {shallow, mount} from 'enzyme'; +import {shallow} from 'enzyme'; import React from 'react'; import LoginMfa from 'components/login/login_mfa'; import SaveButton from 'components/save_button'; +import {mountWithIntl} from 'tests/helpers/intl-test-helper'; + describe('components/login/LoginMfa', () => { const baseProps = { loginId: 'login_id', @@ -24,7 +26,7 @@ describe('components/login/LoginMfa', () => { }); test('should handle token entered', () => { - const wrapper = mount( + const wrapper = mountWithIntl( , ); @@ -44,7 +46,7 @@ describe('components/login/LoginMfa', () => { }); test('should handle submit', () => { - const wrapper = mount( + const wrapper = mountWithIntl( , ); diff --git a/webapp/channels/src/components/post_view/message_attachments/action_button/action_button.test.tsx b/webapp/channels/src/components/post_view/message_attachments/action_button/action_button.test.tsx index d6c9a8b66a..d4510304f7 100644 --- a/webapp/channels/src/components/post_view/message_attachments/action_button/action_button.test.tsx +++ b/webapp/channels/src/components/post_view/message_attachments/action_button/action_button.test.tsx @@ -7,7 +7,7 @@ import {Preferences} from 'mattermost-redux/constants'; import type {Theme} from 'mattermost-redux/selectors/entities/preferences'; import {changeOpacity} from 'mattermost-redux/utils/theme_utils'; -import {render, screen, userEvent} from 'tests/react_testing_utils'; +import {screen, userEvent, renderWithIntl} from 'tests/react_testing_utils'; import ActionButton from './action_button'; @@ -19,7 +19,7 @@ describe('components/post_view/message_attachments/action_button.jsx', () => { }; test('should match default component state with given props', () => { - render(); + renderWithIntl(); const button = screen.getByRole('button'); expect(button).toHaveAttribute('data-action-cookie', 'cookie-contents'); @@ -30,7 +30,7 @@ describe('components/post_view/message_attachments/action_button.jsx', () => { }); test('should call handleAction on click', () => { - render(); + renderWithIntl(); const button = screen.getByRole('button'); @@ -45,7 +45,7 @@ describe('components/post_view/message_attachments/action_button.jsx', () => { action: {...baseProps.action, style: 'onlineIndicator'}, }; - render(); + renderWithIntl(); const button = screen.getByRole('button'); @@ -60,7 +60,7 @@ describe('components/post_view/message_attachments/action_button.jsx', () => { action: {...baseProps.action, style: 'danger'}, }; - render(); + renderWithIntl(); const button = screen.getByRole('button'); @@ -74,7 +74,7 @@ describe('components/post_view/message_attachments/action_button.jsx', () => { action: {...baseProps.action, style: 'success'}, }; - render(); + renderWithIntl(); const button = screen.getByRole('button'); expect(button).toHaveStyle(`background-color: ${changeOpacity('#339970', 0.08)}`); @@ -87,7 +87,7 @@ describe('components/post_view/message_attachments/action_button.jsx', () => { action: {...baseProps.action, style: '#28a745'}, }; - render(); + renderWithIntl(); const button = screen.getByRole('button'); expect(button).toHaveStyle(`background-color: ${changeOpacity(props.action.style, 0.08)}`); @@ -100,7 +100,7 @@ describe('components/post_view/message_attachments/action_button.jsx', () => { action: {...baseProps.action, style: '#wrong'}, }; - render(); + renderWithIntl(); const button = screen.getByRole('button'); expect(button.style.length).toBe(0); @@ -112,7 +112,7 @@ describe('components/post_view/message_attachments/action_button.jsx', () => { action: {...baseProps.action, style: undefined}, }; - render(); + renderWithIntl(); const button = screen.getByRole('button'); expect(button.style.length).toBe(0); diff --git a/webapp/channels/src/components/widgets/loading/__snapshots__/loading_spinner.test.tsx.snap b/webapp/channels/src/components/widgets/loading/__snapshots__/loading_spinner.test.tsx.snap new file mode 100644 index 0000000000..e9155fc29b --- /dev/null +++ b/webapp/channels/src/components/widgets/loading/__snapshots__/loading_spinner.test.tsx.snap @@ -0,0 +1,28 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`components/widgets/loadingLoadingSpinner showing spinner with text 1`] = ` + + + test + +`; + +exports[`components/widgets/loadingLoadingSpinner showing spinner without text 1`] = ` + + + +`; diff --git a/webapp/channels/src/components/widgets/loading/__snapshots__/loading_wrapper.test.tsx.snap b/webapp/channels/src/components/widgets/loading/__snapshots__/loading_wrapper.test.tsx.snap index 34bad6be62..21def44daa 100644 --- a/webapp/channels/src/components/widgets/loading/__snapshots__/loading_wrapper.test.tsx.snap +++ b/webapp/channels/src/components/widgets/loading/__snapshots__/loading_wrapper.test.tsx.snap @@ -19,32 +19,64 @@ exports[`components/widgets/loading/LoadingWrapper showing spinner with text 1`] loading={true} text="test" > - - - + - - test - - + test + +
+ `; @@ -52,30 +84,62 @@ exports[`components/widgets/loading/LoadingWrapper showing spinner without text - - - + - - - + + + `; diff --git a/webapp/channels/src/components/widgets/loading/loading_spinner.test.tsx b/webapp/channels/src/components/widgets/loading/loading_spinner.test.tsx index e0f6213a2b..001fbebbf8 100644 --- a/webapp/channels/src/components/widgets/loading/loading_spinner.test.tsx +++ b/webapp/channels/src/components/widgets/loading/loading_spinner.test.tsx @@ -1,53 +1,19 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {shallow} from 'enzyme'; import React from 'react'; +import {shallowWithIntl} from 'tests/helpers/intl-test-helper'; + import LoadingSpinner from './loading_spinner'; describe('components/widgets/loadingLoadingSpinner', () => { test('showing spinner with text', () => { - const wrapper = shallow(); - expect(wrapper).toMatchInlineSnapshot(` - - - test - - `); + const wrapper = shallowWithIntl(); + expect(wrapper).toMatchSnapshot(); }); test('showing spinner without text', () => { - const wrapper = shallow(); - expect(wrapper).toMatchInlineSnapshot(` - - - - `); + const wrapper = shallowWithIntl(); + expect(wrapper).toMatchSnapshot(); }); }); diff --git a/webapp/channels/src/components/widgets/loading/loading_spinner.tsx b/webapp/channels/src/components/widgets/loading/loading_spinner.tsx index f9089f8fa4..da626db7cc 100644 --- a/webapp/channels/src/components/widgets/loading/loading_spinner.tsx +++ b/webapp/channels/src/components/widgets/loading/loading_spinner.tsx @@ -1,19 +1,17 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import React from 'react'; - -import LocalizedIcon from 'components/localized_icon'; - -import {t} from 'utils/i18n'; +import React, {PureComponent} from 'react'; +import type {ReactNode, CSSProperties} from 'react'; +import {injectIntl, type IntlShape} from 'react-intl'; type Props = { - text: React.ReactNode; - style?: React.CSSProperties; + text?: ReactNode; + style?: CSSProperties; + intl: IntlShape; } - -export default class LoadingSpinner extends React.PureComponent { - public static defaultProps: Props = { +class LoadingSpinner extends PureComponent { + public static defaultProps: Partial = { text: null, }; @@ -25,13 +23,14 @@ export default class LoadingSpinner extends React.PureComponent { style={this.props.style} data-testid='loadingSpinner' > - {this.props.text} ); } } + +export default injectIntl(LoadingSpinner); diff --git a/webapp/channels/src/components/widgets/loading/loading_wrapper.test.tsx b/webapp/channels/src/components/widgets/loading/loading_wrapper.test.tsx index fc76b35386..9f76e16374 100644 --- a/webapp/channels/src/components/widgets/loading/loading_wrapper.test.tsx +++ b/webapp/channels/src/components/widgets/loading/loading_wrapper.test.tsx @@ -1,9 +1,10 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {mount} from 'enzyme'; import React from 'react'; +import {mountWithIntl} from 'tests/helpers/intl-test-helper'; + import LoadingWrapper from './loading_wrapper'; describe('components/widgets/loading/LoadingWrapper', () => { @@ -31,7 +32,7 @@ describe('components/widgets/loading/LoadingWrapper', () => { ]; for (const testCase of testCases) { test(testCase.name, () => { - const wrapper = mount( + const wrapper = mountWithIntl(