Skip to content

Commit 61be675

Browse files
committed
Merge branch 'master' of github.com:box/box-ui-elements into react-tether-upgrade-3.0.3
2 parents 82ddb4f + f885f8c commit 61be675

File tree

8 files changed

+460
-438
lines changed

8 files changed

+460
-438
lines changed

src/components/sidebar-toggle-button/SidebarToggleButton.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,28 @@ const SidebarToggleButton = ({
4848
return isOpen ? <IconHide height={16} width={16} /> : <IconShow height={16} width={16} />;
4949
};
5050

51+
// Adding this to stop the mousedown event from being propagated up to box-annotations as
52+
// that will cause the active annotation to no longer be active which means that it will not be displayed.
53+
// This causes video annotations not to work properly.
54+
const mouseDownHandler = (event: SyntheticMouseEvent<HTMLButtonElement>) => {
55+
event.stopPropagation();
56+
};
57+
5158
if (isPreviewModernizationEnabled) {
5259
const tooltipPositionModernized = direction === DIRECTION_LEFT ? DIRECTION_RIGHT : DIRECTION_LEFT;
5360

5461
return (
5562
<BPTooltip content={intlText} side={tooltipPositionModernized}>
5663
{/* Workaround to attach BP tooltip to legacy button, remove span when buttons are migrated to BP */}
57-
<span>
58-
<PlainButton aria-label={intlText} className={classes} onClick={onClick} type="button" {...rest}>
64+
<span onMouseDown={mouseDownHandler} role="presentation">
65+
<PlainButton
66+
aria-label={intlText}
67+
className={classes}
68+
onClick={onClick}
69+
onMouseDown={mouseDownHandler}
70+
type="button"
71+
{...rest}
72+
>
5973
{renderButton()}
6074
</PlainButton>
6175
</span>
@@ -64,7 +78,14 @@ const SidebarToggleButton = ({
6478
}
6579
return (
6680
<Tooltip position={tooltipPosition} text={intlText}>
67-
<PlainButton aria-label={intlText} className={classes} onClick={onClick} type="button" {...rest}>
81+
<PlainButton
82+
aria-label={intlText}
83+
className={classes}
84+
onClick={onClick}
85+
onMouseDown={mouseDownHandler}
86+
type="button"
87+
{...rest}
88+
>
6889
{renderButton()}
6990
</PlainButton>
7091
</Tooltip>
Lines changed: 66 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,75 @@
11
import * as React from 'react';
2+
import { screen, fireEvent } from '@testing-library/react';
23

4+
import { render } from '../../../test-utils/testing-library';
35
import SidebarToggleButton from '..';
46

57
describe('components/sidebar-toggle-button/SidebarToggleButton', () => {
6-
test('should render correctly as open', () => {
7-
const wrapper = mount(<SidebarToggleButton isOpen />);
8+
test.each`
9+
isOpen | direction
10+
${true} | ${'left'}
11+
${false} | ${'left'}
12+
${true} | ${'right'}
13+
${false} | ${'right'}
14+
`(
15+
'should render correct button correctly when open is $isOpen and direction is $direction and isPreviewModernizationEnabled is false',
16+
({ isOpen, direction }) => {
17+
render(<SidebarToggleButton isOpen={isOpen} direction={direction} />, {
18+
wrapperProps: { features: { previewModernization: { enabled: false } } },
19+
});
820

9-
expect(wrapper).toMatchSnapshot();
10-
});
21+
const button = screen.getByRole('button');
22+
let iconClassName = '';
23+
let iconNotDisplayedClassName = '';
24+
if (direction === 'left') {
25+
iconClassName = isOpen ? 'icon-show' : 'icon-hide';
26+
iconNotDisplayedClassName = isOpen ? 'icon-hide' : 'icon-show';
27+
} else {
28+
iconClassName = isOpen ? 'icon-hide' : 'icon-show';
29+
iconNotDisplayedClassName = isOpen ? 'icon-show' : 'icon-hide';
30+
}
31+
const icon = button.querySelector(`.${iconClassName}`);
32+
const iconNotDisplayed = button.querySelector(`.${iconNotDisplayedClassName}`);
33+
expect(icon).toBeInTheDocument();
34+
expect(iconNotDisplayed).not.toBeInTheDocument();
35+
const isCollapsed = button.classList.contains('bdl-is-collapsed');
36+
expect(isCollapsed).toBe(!isOpen);
37+
},
38+
);
1139

12-
test('should render correctly as closed', () => {
13-
const wrapper = mount(<SidebarToggleButton isOpen={false} />);
40+
test.each([true, false])(
41+
'should stop the mousedown event from being propagated up to box-annotations if isPreviewModernizationEnabled is %s',
42+
isPreviewModernizationEnabled => {
43+
const onMouseDown = jest.fn();
44+
const onClick = jest.fn();
45+
render(
46+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
47+
<div onMouseDown={onMouseDown}>
48+
<SidebarToggleButton isOpen onClick={onClick} />
49+
</div>,
50+
{
51+
wrapperProps: { features: { previewModernization: { enabled: isPreviewModernizationEnabled } } },
52+
},
53+
);
54+
const button = screen.getByRole('button');
55+
fireEvent.mouseDown(button);
56+
expect(onMouseDown).not.toHaveBeenCalled();
57+
},
58+
);
1459

15-
expect(wrapper).toMatchSnapshot();
16-
});
17-
18-
test('should have the proper class when it is collapsed', () => {
19-
const wrapper = mount(<SidebarToggleButton isOpen={false} />);
20-
21-
expect(wrapper.find('PlainButton').hasClass('bdl-is-collapsed')).toBeTruthy();
22-
});
23-
24-
test('should render correctly as left oriented toggle when open', () => {
25-
const wrapper = mount(<SidebarToggleButton direction="left" isOpen />);
26-
27-
expect(wrapper).toMatchSnapshot();
28-
});
29-
30-
test('should render correctly as left oriented toggle when closed', () => {
31-
const wrapper = mount(<SidebarToggleButton direction="left" isOpen={false} />);
32-
33-
expect(wrapper).toMatchSnapshot();
34-
});
60+
test.each([true, false])(
61+
'should show proper button isPreviewModernizationEnabled is %s and click handler should work',
62+
isPreviewModernizationEnabled => {
63+
const onClick = jest.fn();
64+
render(<SidebarToggleButton isOpen onClick={onClick} />, {
65+
wrapperProps: { features: { previewModernization: { enabled: isPreviewModernizationEnabled } } },
66+
});
67+
const button = screen.getByRole('button');
68+
expect(button).toHaveClass('bdl-SidebarToggleButton');
69+
const isModernized = button.classList.contains('bdl-SidebarToggleButton--modernized');
70+
expect(isModernized).toBe(isPreviewModernizationEnabled);
71+
fireEvent.click(button);
72+
expect(onClick).toHaveBeenCalled();
73+
},
74+
);
3575
});

0 commit comments

Comments
 (0)