diff --git a/src/components/sidebar-toggle-button/SidebarToggleButton.js b/src/components/sidebar-toggle-button/SidebarToggleButton.js index 2d66846097..c62760b738 100644 --- a/src/components/sidebar-toggle-button/SidebarToggleButton.js +++ b/src/components/sidebar-toggle-button/SidebarToggleButton.js @@ -48,14 +48,28 @@ const SidebarToggleButton = ({ return isOpen ? : ; }; + // Adding this to stop the mousedown event from being propagated up to box-annotations as + // that will cause the active annotation to no longer be active which means that it will not be displayed. + // This causes video annotations not to work properly. + const mouseDownHandler = (event: SyntheticMouseEvent) => { + event.stopPropagation(); + }; + if (isPreviewModernizationEnabled) { const tooltipPositionModernized = direction === DIRECTION_LEFT ? DIRECTION_RIGHT : DIRECTION_LEFT; return ( {/* Workaround to attach BP tooltip to legacy button, remove span when buttons are migrated to BP */} - - + + {renderButton()} @@ -64,7 +78,14 @@ const SidebarToggleButton = ({ } return ( - + {renderButton()} diff --git a/src/components/sidebar-toggle-button/__tests__/SidebarToggleButton.test.js b/src/components/sidebar-toggle-button/__tests__/SidebarToggleButton.test.js index 9cfc881dc8..e00f10abbd 100644 --- a/src/components/sidebar-toggle-button/__tests__/SidebarToggleButton.test.js +++ b/src/components/sidebar-toggle-button/__tests__/SidebarToggleButton.test.js @@ -1,35 +1,75 @@ import * as React from 'react'; +import { screen, fireEvent } from '@testing-library/react'; +import { render } from '../../../test-utils/testing-library'; import SidebarToggleButton from '..'; describe('components/sidebar-toggle-button/SidebarToggleButton', () => { - test('should render correctly as open', () => { - const wrapper = mount(); + test.each` + isOpen | direction + ${true} | ${'left'} + ${false} | ${'left'} + ${true} | ${'right'} + ${false} | ${'right'} + `( + 'should render correct button correctly when open is $isOpen and direction is $direction and isPreviewModernizationEnabled is false', + ({ isOpen, direction }) => { + render(, { + wrapperProps: { features: { previewModernization: { enabled: false } } }, + }); - expect(wrapper).toMatchSnapshot(); - }); + const button = screen.getByRole('button'); + let iconClassName = ''; + let iconNotDisplayedClassName = ''; + if (direction === 'left') { + iconClassName = isOpen ? 'icon-show' : 'icon-hide'; + iconNotDisplayedClassName = isOpen ? 'icon-hide' : 'icon-show'; + } else { + iconClassName = isOpen ? 'icon-hide' : 'icon-show'; + iconNotDisplayedClassName = isOpen ? 'icon-show' : 'icon-hide'; + } + const icon = button.querySelector(`.${iconClassName}`); + const iconNotDisplayed = button.querySelector(`.${iconNotDisplayedClassName}`); + expect(icon).toBeInTheDocument(); + expect(iconNotDisplayed).not.toBeInTheDocument(); + const isCollapsed = button.classList.contains('bdl-is-collapsed'); + expect(isCollapsed).toBe(!isOpen); + }, + ); - test('should render correctly as closed', () => { - const wrapper = mount(); + test.each([true, false])( + 'should stop the mousedown event from being propagated up to box-annotations if isPreviewModernizationEnabled is %s', + isPreviewModernizationEnabled => { + const onMouseDown = jest.fn(); + const onClick = jest.fn(); + render( + // eslint-disable-next-line jsx-a11y/no-static-element-interactions +
+ +
, + { + wrapperProps: { features: { previewModernization: { enabled: isPreviewModernizationEnabled } } }, + }, + ); + const button = screen.getByRole('button'); + fireEvent.mouseDown(button); + expect(onMouseDown).not.toHaveBeenCalled(); + }, + ); - expect(wrapper).toMatchSnapshot(); - }); - - test('should have the proper class when it is collapsed', () => { - const wrapper = mount(); - - expect(wrapper.find('PlainButton').hasClass('bdl-is-collapsed')).toBeTruthy(); - }); - - test('should render correctly as left oriented toggle when open', () => { - const wrapper = mount(); - - expect(wrapper).toMatchSnapshot(); - }); - - test('should render correctly as left oriented toggle when closed', () => { - const wrapper = mount(); - - expect(wrapper).toMatchSnapshot(); - }); + test.each([true, false])( + 'should show proper button isPreviewModernizationEnabled is %s and click handler should work', + isPreviewModernizationEnabled => { + const onClick = jest.fn(); + render(, { + wrapperProps: { features: { previewModernization: { enabled: isPreviewModernizationEnabled } } }, + }); + const button = screen.getByRole('button'); + expect(button).toHaveClass('bdl-SidebarToggleButton'); + const isModernized = button.classList.contains('bdl-SidebarToggleButton--modernized'); + expect(isModernized).toBe(isPreviewModernizationEnabled); + fireEvent.click(button); + expect(onClick).toHaveBeenCalled(); + }, + ); }); diff --git a/src/components/sidebar-toggle-button/__tests__/__snapshots__/SidebarToggleButton.test.js.snap b/src/components/sidebar-toggle-button/__tests__/__snapshots__/SidebarToggleButton.test.js.snap deleted file mode 100644 index d25c9f336a..0000000000 --- a/src/components/sidebar-toggle-button/__tests__/__snapshots__/SidebarToggleButton.test.js.snap +++ /dev/null @@ -1,389 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`components/sidebar-toggle-button/SidebarToggleButton should render correctly as closed 1`] = ` - - - - } - classPrefix="tooltip" - constraints={ - [ - { - "attachment": "together", - "to": "window", - }, - ] - } - enabled={false} - renderElementTag="div" - renderElementTo={null} - targetAttachment="middle left" - > - - - - - - - -`; - -exports[`components/sidebar-toggle-button/SidebarToggleButton should render correctly as left oriented toggle when closed 1`] = ` - - - - } - classPrefix="tooltip" - constraints={ - [ - { - "attachment": "together", - "to": "window", - }, - ] - } - enabled={false} - renderElementTag="div" - renderElementTo={null} - targetAttachment="middle right" - > - - - - - - - -`; - -exports[`components/sidebar-toggle-button/SidebarToggleButton should render correctly as left oriented toggle when open 1`] = ` - - - - } - classPrefix="tooltip" - constraints={ - [ - { - "attachment": "together", - "to": "window", - }, - ] - } - enabled={false} - renderElementTag="div" - renderElementTo={null} - targetAttachment="middle right" - > - - - - - - - -`; - -exports[`components/sidebar-toggle-button/SidebarToggleButton should render correctly as open 1`] = ` - - - - } - classPrefix="tooltip" - constraints={ - [ - { - "attachment": "together", - "to": "window", - }, - ] - } - enabled={false} - renderElementTag="div" - renderElementTo={null} - targetAttachment="middle left" - > - - - - - - - -`;