diff --git a/src/legacy/Lightbox/index.js b/src/legacy/Lightbox/index.js
index ed31e83695..0c2dda6622 100644
--- a/src/legacy/Lightbox/index.js
+++ b/src/legacy/Lightbox/index.js
@@ -33,7 +33,7 @@ class Lightbox extends React.Component {
window.addEventListener('keydown', this.handleKeyDown, true);
window.addEventListener('resize', this.handleResize, true);
const { viewport } = this;
- if (viewport) {
+ if (viewport && viewport.clientWidth && viewport.clientHeight) {
// eslint-disable-next-line react/no-did-mount-set-state
this.setState({
viewportDimensions: {
@@ -126,7 +126,7 @@ class Lightbox extends React.Component {
onChange && onChange(index);
}
e.stopPropagation();
- target && target.scrollIntoViewIfNeeded();
+ target && target.scrollIntoViewIfNeeded && target.scrollIntoViewIfNeeded();
target && needFocus && target.parentElement.focus();
};
@@ -433,7 +433,7 @@ class Lightbox extends React.Component {
placement="top"
triggerComponent={
this.triggerPageChange(index - 1, e)}
>
this.triggerPageChange(index + 1, e)}
>
this.setZoom(-0.25)}>
+ this.setZoom(-0.25)}
+ >
{tooltips.zoomOut}
-
- {Math.round(((newHeight * 1.0) / height) * 100)}%
+
+ {`${Math.round(((newHeight * 1.0) / height) * 100)}%`}
this.setZoom(0.25)}>
+ this.setZoom(0.25)}
+ >
+
{
return {
@@ -31,7 +33,7 @@ describe('tests for ', () => {
});
it('when downloading is true the download button should turn to spinner', () => {
- const container = shallow(
+ const container = mount(
', () => {
onDownload={jest.fn()}
/>
);
- const downloadButton = container.find('.md-lightbox__download-button .icon-download_16');
+ const downloadButton = container.find(IconNext).filter({ name: 'download' });
expect(downloadButton.length).toEqual(0);
- const spinner = container.find('Spinner');
+ const spinner = container.find('.md-loading-spinner-wrapper');
expect(spinner.length).toEqual(1);
});
it('when downloading is false the download button should be visible', () => {
- const container = shallow(
+ const container = mount(
', () => {
onDownload={jest.fn()}
/>
);
- const downloadButton = container.find('.md-lightbox__control-download');
+ const downloadButton = container.find(IconNext).filter({ name: 'download' });
expect(downloadButton.length).toEqual(1);
- const spinner = container.find('.md-lightbox__control-spinner');
+ const spinner = container.find('.md-loading-spinner-wrapper');
expect(spinner.length).toEqual(0);
});
@@ -108,7 +110,7 @@ describe('tests for ', () => {
});
it('should display file meta data and name', () => {
- const container = shallow(
+ const container = mount(
', () => {
const sharedBy = container.find('.md-lightbox__header-sharer');
const timestamp = container.find('.md-lightbox__header-timestamp');
const name = container.find('.md-lightbox__header-name');
- expect(container.props()['aria-labelledby']).toStrictEqual(name.props().id);
+ expect(
+ container.find('.md-lightbox__container').props().children[0].props['aria-labelledby']
+ ).toStrictEqual(name.props().id);
expect(name.type()).toEqual('h2');
expect(name.text()).toEqual('test');
expect(timestamp.text()).toEqual('At 4/17/2018, 10:02 AM');
@@ -141,7 +145,7 @@ describe('tests for ', () => {
it('should change pages on click of next and previous', () => {
const onChangeFn = jest.fn();
- const container = shallow(
+ const container = mount(
', () => {
onDownload={jest.fn()}
/>
);
- const rightControl = container.find('.md-lightbox__page-controls--right');
- const leftControl = container.find('.md-lightbox__page-controls--left');
- rightControl.simulate('click', { stopPropagation: () => {} });
+ const rightControl = container.find(ButtonSimple).filter('.md-lightbox__page-controls--right');
+ const leftControl = container.find(ButtonSimple).filter('.md-lightbox__page-controls--left');
+ rightControl.props().onPress({ stopPropagation: () => {} });
expect(onChangeFn).toHaveBeenCalledWith(2);
- leftControl.simulate('click', { stopPropagation: () => {} });
+
+ leftControl.props().onPress({ stopPropagation: () => {} });
expect(onChangeFn).toHaveBeenCalledWith(0);
});
- it.each([true, false])('check scrollIntoViewIfNeeded and focus trigger when needFocus is %s', (needFocus) => {
- const onChangeFn = jest.fn();
- const container = shallow();
+ it.each([true, false])(
+ 'check scrollIntoViewIfNeeded and focus trigger when needFocus is %s',
+ (needFocus) => {
+ const onChangeFn = jest.fn();
+ const container = shallow(
+
+ );
- container.instance().lightBox = {
- querySelector: jest.fn().mockReturnValue({
- scrollIntoViewIfNeeded: jest.fn(),
- parentElement: {
- focus: jest.fn(),
- },
- }),
- };
+ container.instance().lightBox = {
+ querySelector: jest.fn().mockReturnValue({
+ scrollIntoViewIfNeeded: jest.fn(),
+ parentElement: {
+ focus: jest.fn(),
+ },
+ }),
+ };
- const index = 1;
- const mockEvent = { stopPropagation: jest.fn() };
+ const index = 1;
+ const mockEvent = { stopPropagation: jest.fn() };
- container.instance().triggerPageChange(index, mockEvent, needFocus);
+ container.instance().triggerPageChange(index, mockEvent, needFocus);
- expect(mockEvent.stopPropagation).toHaveBeenCalled();
- expect(container.instance().lightBox.querySelector).toHaveBeenCalledWith(`[data-index="${index}"]`);
- expect(container.instance().lightBox.querySelector().scrollIntoViewIfNeeded).toHaveBeenCalled();
- if(needFocus){
- expect(container.instance().lightBox.querySelector().parentElement.focus).toHaveBeenCalled();
- } else {
- expect(container.instance().lightBox.querySelector().parentElement.focus).not.toHaveBeenCalled();
+ expect(mockEvent.stopPropagation).toHaveBeenCalled();
+ expect(container.instance().lightBox.querySelector).toHaveBeenCalledWith(
+ `[data-index="${index}"]`
+ );
+ expect(
+ container.instance().lightBox.querySelector().scrollIntoViewIfNeeded
+ ).toHaveBeenCalled();
+ if (needFocus) {
+ expect(
+ container.instance().lightBox.querySelector().parentElement.focus
+ ).toHaveBeenCalled();
+ } else {
+ expect(
+ container.instance().lightBox.querySelector().parentElement.focus
+ ).not.toHaveBeenCalled();
+ }
}
- });
+ );
it('should close the lightbox onClose', () => {
const onCloseFn = jest.fn();
- const container = shallow(
+ const container = mount(
', () => {
onDownload={jest.fn()}
/>
);
- const closeIcon = container.find('.md-lightbox__header-item--right .md-lightbox__control');
- closeIcon.simulate('click');
+ const closeIcon = container.find(ButtonSimple).filter('.md-lightbox__control-close');
+ closeIcon.props().onPress();
expect(onCloseFn).toHaveBeenCalled();
});
it('should zoom-in and zoom-out', () => {
- const container = shallow(
+ const container = mount(
', () => {
onDownload={jest.fn()}
/>
);
- const zoomIn = container.find('.md-lightbox__viewer-controls .md-lightbox__control').at(1);
- const zoomOut = container.find('.md-lightbox__viewer-controls .md-lightbox__control').at(0);
- let zoomValue = container.find('.md-lightbox__controls .md-lightbox__control-value').at(0);
+ const zoomIn = container.find(ButtonSimple).filter({ 'data-test': 'zoom-in-button' });
+ const zoomOut = container.find(ButtonSimple).filter({ 'data-test': 'zoom-out-button' });
+ let zoomValue = container.find('.md-lightbox__controls .md-lightbox__control-zoom-level');
expect(zoomValue.text()).toEqual('100%');
- zoomIn.simulate('click');
- zoomValue = container.find('.md-lightbox__controls .md-lightbox__control-value').at(0);
+ zoomIn.props().onPress();
+ zoomValue = container.find('.md-lightbox__controls .md-lightbox__control-zoom-level');
expect(zoomValue.text()).toEqual('125%');
- zoomOut.simulate('click');
- zoomValue = container.find('.md-lightbox__controls .md-lightbox__control-value').at(0);
+ zoomOut.props().onPress();
+ zoomValue = container.find('.md-lightbox__controls .md-lightbox__control-zoom-level');
expect(zoomValue.text()).toEqual('100%');
});
@@ -325,7 +343,7 @@ describe('tests for ', () => {
it('onDownload should be called when downloading the file', () => {
const onDownloadFn = jest.fn();
- const container = shallow(
+ const container = mount(
', () => {
onDownload={onDownloadFn}
/>
);
- const downloadIcon = container.find('.md-lightbox__control-download');
- downloadIcon.simulate('click');
+ const downloadIcon = container.find(ButtonSimple).filter('.md-lightbox__control-download');
+ downloadIcon.props().onPress();
expect(onDownloadFn).toHaveBeenCalled();
});
@@ -368,9 +386,9 @@ describe('tests for ', () => {
]}
/>
);
- const downloadButton = container.find('.md-lightbox__download-button .icon-download_16');
+ const downloadButton = container.find(IconNext).filter({ name: 'download' });
expect(downloadButton.length).toEqual(0);
- const spinner = container.find('Spinner');
+ const spinner = container.find('.md-loading-spinner-wrapper');
expect(spinner.length).toEqual(0);
});
diff --git a/src/legacy/Lightbox/tests/index.spec.js.snap b/src/legacy/Lightbox/tests/index.spec.js.snap
index edbd9e7283..94d0b30e50 100644
--- a/src/legacy/Lightbox/tests/index.spec.js.snap
+++ b/src/legacy/Lightbox/tests/index.spec.js.snap
@@ -102,16 +102,16 @@ exports[`tests for should match SnapShot 1`] = `
@@ -132,7 +132,7 @@ exports[`tests for should match SnapShot 1`] = `
/>
should match SnapShot 1`] = `
+
-
+ Zoom out
- 0
- %
+ 100%
+
-
+ Zoom in
should match SnapShot 1`] = `
1
+
@@ -297,84 +291,275 @@ exports[`tests for should match SnapShot 1`] = `
className="md-lightbox__header-item--right"
>
+
+
}
- tooltip="Exit"
- tooltipTrigger="MouseEnter"
- width={null}
+ type="label"
>
- Exit
-
+
+
}
- delay={0}
- direction="bottom-right"
- doesAnchorToggle={true}
- hideDelay={0}
- hoverDelay={500}
- includeFocusOnHover={true}
- isContained={true}
- onClose={null}
- overflowType="auto"
- popoverTrigger="MouseEnter"
- showArrow={true}
- showDelay={0}
- startOpen={false}
+ variant="small"
>
-
-
-
-
-
+ render={[Function]}
+ trigger="mouseenter focus"
+ >
+
+
+
+
+
+
+
+
+
+
+ }
+ />
+
+
+
+
+ Exit
+
@@ -408,8 +593,8 @@ exports[`tests for should match SnapShot 1`] = `
className="md-lightbox__viewport-wrapper"
style={
Object {
- "height": "0px",
- "width": "0px",
+ "height": "100px",
+ "width": "100px",
}
}
>
@@ -436,156 +621,559 @@ exports[`tests for should match SnapShot 1`] = `
style={Object {}}
>
+
+
+ }
+ type="label"
>
- Zoom out
-
+
+
}
- delay={0}
- doesAnchorToggle={true}
- hideDelay={0}
- hoverDelay={500}
- includeFocusOnHover={true}
- onClose={null}
- overflowType="auto"
- popoverTrigger="MouseEnter"
- showArrow={true}
- showDelay={0}
- startOpen={false}
+ variant="small"
>
-
-
-
-
-
+ render={[Function]}
+ trigger="mouseenter focus"
+ >
+
+
+
+
+
+
+
+
+
+
+ }
+ />
+
+
+
+
+ Zoom out
+
- 0
- %
+ 100%
+
+
+ }
+ type="label"
>
- Zoom in
-
+
+
}
- delay={0}
- doesAnchorToggle={true}
- hideDelay={0}
- hoverDelay={500}
- includeFocusOnHover={true}
- onClose={null}
- overflowType="auto"
- popoverTrigger="MouseEnter"
- showArrow={true}
- showDelay={0}
- startOpen={false}
+ variant="small"
>
-
-
-
-
-
+ render={[Function]}
+ trigger="mouseenter focus"
+ >
+
+
+
+
+
+
+
+
+
+
+ }
+ />
+
+
+
+
+ Zoom in
+
should match SnapShot 1`] = `
1
-
+
+
+ }
+ type="label"
>
-
-
+
+
+ }
+ variant="small"
>
-
- Download
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
}
/>
-
-
-
-
-
+
+
+
+
+
+ Download
+
+