From b74c2194b237a580c9c76c58d2a5aae36b0aa44f Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Wed, 8 Jan 2025 01:04:43 -0700 Subject: [PATCH] MM-61926 Channel Conversion Text and add test (#29498) * update text, add tests * remove commented lines * lint fix * i18n-extract * add additional changes * update test, change other text * update test names --------- Co-authored-by: Mattermost Build --- .../channel/details/channel_modes.tsx | 3 +- .../convert_channel_modal.test.tsx | 55 +++++++++++++++++++ .../convert_channel_modal.tsx | 7 +-- webapp/channels/src/i18n/en.json | 3 +- 4 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 webapp/channels/src/components/convert_channel_modal/convert_channel_modal.test.tsx diff --git a/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/channel_modes.tsx b/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/channel_modes.tsx index d1ccc2929a..4fc64368fa 100644 --- a/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/channel_modes.tsx +++ b/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/channel_modes.tsx @@ -89,7 +89,8 @@ const AllowAllToggle: React.SFC = (props: Props): JSX.Element | null => { ) : ( )}} /> ) } diff --git a/webapp/channels/src/components/convert_channel_modal/convert_channel_modal.test.tsx b/webapp/channels/src/components/convert_channel_modal/convert_channel_modal.test.tsx new file mode 100644 index 0000000000..0d5ca6c5ae --- /dev/null +++ b/webapp/channels/src/components/convert_channel_modal/convert_channel_modal.test.tsx @@ -0,0 +1,55 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import {fireEvent, waitForElementToBeRemoved} from '@testing-library/react'; +import React from 'react'; + +import {General} from 'mattermost-redux/constants'; + +import ConvertChannelModal from 'components/convert_channel_modal/convert_channel_modal'; + +import {renderWithContext, screen, userEvent} from 'tests/react_testing_utils'; + +describe('component/ConvertChannelModal', () => { + const updateChannelPrivacy = jest.fn().mockImplementation(() => Promise.resolve({})); + const baseProps = { + onExited: jest.fn(), + channelId: 'owsyt8n43jfxjpzh9np93mx1wa', + channelDisplayName: 'Channel Display Name', + actions: { + updateChannelPrivacy, + }, + }; + + test('should render the title and buttons correctly', () => { + renderWithContext(); + + expect(screen.getByText('Convert Channel Display Name to a Private Channel?')).toBeInTheDocument(); + expect(screen.getByRole('button', {name: 'No, cancel'})).toBeInTheDocument(); + expect(screen.getByRole('button', {name: 'Yes, convert to private channel'})).toBeInTheDocument(); + }); + + test('should match call updateChannelPrivacy when convert is clicked', () => { + renderWithContext(); + userEvent.click(screen.getByRole('button', {name: 'Yes, convert to private channel'})); + + expect(updateChannelPrivacy).toHaveBeenCalledTimes(1); + expect(updateChannelPrivacy).toHaveBeenCalledWith(baseProps.channelId, General.PRIVATE_CHANNEL); + }); + + test('should not call updateChannelPrivacy when Close button is clicked', async () => { + renderWithContext(); + fireEvent.click(screen.getByRole('button', {name: 'Close'})); + + await waitForElementToBeRemoved(() => screen.getByText('Convert Channel Display Name to a Private Channel?')); + expect(updateChannelPrivacy).not.toHaveBeenCalled(); + }); + + test('should not call updateChannelPrivacy when other Cancel is clicked', async () => { + renderWithContext(); + fireEvent.click(screen.getByRole('button', {name: 'No, cancel'})); + + await waitForElementToBeRemoved(() => screen.getByText('Convert Channel Display Name to a Private Channel?')); + expect(updateChannelPrivacy).not.toHaveBeenCalled(); + }); +}); diff --git a/webapp/channels/src/components/convert_channel_modal/convert_channel_modal.tsx b/webapp/channels/src/components/convert_channel_modal/convert_channel_modal.tsx index 61cce837d1..b4d7c5990a 100644 --- a/webapp/channels/src/components/convert_channel_modal/convert_channel_modal.tsx +++ b/webapp/channels/src/components/convert_channel_modal/convert_channel_modal.tsx @@ -91,12 +91,6 @@ export default class ConvertChannelModal extends React.PureComponent

-

- -

Learn More", "admin.channel_settings.channel_details.unarchiveChannel": "Unarchive Channel", @@ -3460,7 +3460,6 @@ "confirm_switch_to_yearly_modal.title": "Confirm switch to annual plan", "convert_channel.cancel": "No, cancel", "convert_channel.confirm": "Yes, convert to private channel", - "convert_channel.question2": "The change is permanent and cannot be undone.", "convert_channel.title": "Convert {display_name} to a Private Channel?", "convertChannel.question1": "When you convert {display_name} to a private channel, history and membership are preserved. Publicly shared files remain accessible to anyone with the link. Membership in a private channel is by invitation only.", "convertChannel.question3": "Are you sure you want to convert {display_name} to a private channel?",