From 5a8b00e3d0573f855c98282233e49f8b33ab01d6 Mon Sep 17 00:00:00 2001
From: Rita Anene <92169163+Camillarhi@users.noreply.github.com>
Date: Fri, 23 Aug 2024 03:57:36 +0100
Subject: [PATCH] [MM-60153] Migrate tooltips of
"components/advanced_text_editor/toggle_formatting_bar.tsx" to WithTooltip
(#27982)
---
.../toggle_formatting_bar.test.tsx | 66 +++++++++++++++++++
.../toggle_formatting_bar.tsx | 42 +++++-------
2 files changed, 83 insertions(+), 25 deletions(-)
create mode 100644 webapp/channels/src/components/advanced_text_editor/toggle_formatting_bar.test.tsx
diff --git a/webapp/channels/src/components/advanced_text_editor/toggle_formatting_bar.test.tsx b/webapp/channels/src/components/advanced_text_editor/toggle_formatting_bar.test.tsx
new file mode 100644
index 0000000000..203f611566
--- /dev/null
+++ b/webapp/channels/src/components/advanced_text_editor/toggle_formatting_bar.test.tsx
@@ -0,0 +1,66 @@
+// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
+// See LICENSE.txt for license information.
+
+import React from 'react';
+
+import {renderWithContext, fireEvent, screen} from 'tests/react_testing_utils';
+
+import ToggleFormattingBar from './toggle_formatting_bar';
+
+jest.mock('components/with_tooltip', () => {
+ return ({children}: { children: React.ReactNode }) =>
{children}
;
+});
+
+describe('ToggleFormattingBar Component', () => {
+ it('should render correctly with default props', () => {
+ renderWithContext(
+ ,
+ );
+
+ expect(screen.getAllByLabelText('Format letter Case Icon')[0]).toBeInTheDocument();
+ });
+
+ it('should call onClick handler when clicked', () => {
+ const onClick = jest.fn();
+ renderWithContext(
+ ,
+ );
+
+ fireEvent.click(screen.getByLabelText('formatting'));
+ expect(onClick).toHaveBeenCalledTimes(1);
+ });
+
+ it('should not be clickable when disabled', () => {
+ const onClick = jest.fn();
+ renderWithContext(
+ ,
+ );
+
+ fireEvent.click(screen.getByLabelText('formatting'));
+ expect(onClick).not.toHaveBeenCalled();
+ });
+
+ it('should have the correct id based on active prop', () => {
+ renderWithContext(
+ ,
+ );
+
+ expect(screen.getByRole('button')).toHaveAttribute('id', 'toggleFormattingBarButton');
+ });
+});
diff --git a/webapp/channels/src/components/advanced_text_editor/toggle_formatting_bar.tsx b/webapp/channels/src/components/advanced_text_editor/toggle_formatting_bar.tsx
index 5e31527993..40b4cbd6cc 100644
--- a/webapp/channels/src/components/advanced_text_editor/toggle_formatting_bar.tsx
+++ b/webapp/channels/src/components/advanced_text_editor/toggle_formatting_bar.tsx
@@ -7,10 +7,7 @@ import {useIntl} from 'react-intl';
import {ChevronDownIcon, ChevronUpIcon, FormatLetterCaseIcon} from '@mattermost/compass-icons/components';
import KeyboardShortcutSequence, {KEYBOARD_SHORTCUTS} from 'components/keyboard_shortcuts/keyboard_shortcuts_sequence';
-import OverlayTrigger from 'components/overlay_trigger';
-import Tooltip from 'components/tooltip';
-
-import Constants from 'utils/constants';
+import WithTooltip from 'components/with_tooltip';
import {IconContainer} from './formatting_bar/formatting_icon';
@@ -26,32 +23,27 @@ const ToggleFormattingBar = (props: ToggleFormattingBarProps): JSX.Element => {
const buttonAriaLabel = formatMessage({id: 'accessibility.button.formatting', defaultMessage: 'formatting'});
const iconAriaLabel = formatMessage({id: 'generic_icons.format_letter_case', defaultMessage: 'Format letter Case Icon'});
- const tooltip = active ? (
-
-
-
+ const title = active ? (
+
) : (
-
-
-
+
);
const ChevronIcon = active ? ChevronUpIcon : ChevronDownIcon;
return (
-
{
aria-label={iconAriaLabel}
/>
-
+
);
};