-
Notifications
You must be signed in to change notification settings - Fork 344
fix(video-annotations): sidebar button fix to not propagate mousedown event #4388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c21b392
fix(sidebar-toggle): prevent mousdown event propagation
bfoxx1906 cbd7267
fix(sidebar-toggle): prevent mousdown event propagation
bfoxx1906 e1fc472
feat(video-annotations): removing preventDefault call
bfoxx1906 15424c2
Update src/components/sidebar-toggle-button/SidebarToggleButton.js
bfoxx1906 2a75a08
Update src/components/sidebar-toggle-button/__tests__/SidebarToggleBu…
bfoxx1906 3a3e8c6
Merge branch 'master' into sidebar-button-fix
bfoxx1906 b5f2fb9
Merge branch 'master' into sidebar-button-fix
bfoxx1906 cd67036
fix(sidebar): addressing pr comments
bfoxx1906 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 66 additions & 26 deletions
92
src/components/sidebar-toggle-button/__tests__/SidebarToggleButton.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(<SidebarToggleButton isOpen />); | ||
| 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(<SidebarToggleButton isOpen={isOpen} direction={direction} />, { | ||
| 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(<SidebarToggleButton isOpen={false} />); | ||
| 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 | ||
| <div onMouseDown={onMouseDown}> | ||
| <SidebarToggleButton isOpen onClick={onClick} /> | ||
| </div>, | ||
| { | ||
| 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(<SidebarToggleButton isOpen={false} />); | ||
|
|
||
| expect(wrapper.find('PlainButton').hasClass('bdl-is-collapsed')).toBeTruthy(); | ||
| }); | ||
|
|
||
| test('should render correctly as left oriented toggle when open', () => { | ||
| const wrapper = mount(<SidebarToggleButton direction="left" isOpen />); | ||
|
|
||
| expect(wrapper).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('should render correctly as left oriented toggle when closed', () => { | ||
| const wrapper = mount(<SidebarToggleButton direction="left" isOpen={false} />); | ||
|
|
||
| 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(<SidebarToggleButton isOpen onClick={onClick} />, { | ||
| 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(); | ||
| }, | ||
| ); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.