Skip to content

Commit

Permalink
fix(thumbnails): Replace remove method that is unsupported in IE11 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoffan authored Jan 29, 2021
1 parent bd66999 commit 3c37b79
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/lib/VirtualScroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class VirtualScroller {
* @return {void}
*/
destroy() {
if (this.scrollingEl) {
this.scrollingEl.remove();
if (this.anchorEl && this.scrollingEl) {
this.anchorEl.removeChild(this.scrollingEl);
}

this.scrollingEl = null;
Expand Down
15 changes: 8 additions & 7 deletions src/lib/__tests__/VirtualScroller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ describe('VirtualScroller', () => {

describe('destroy()', () => {
test('should remove the HTML element references', () => {
const scrollingEl = { remove: () => {} };
jest.spyOn(scrollingEl, 'remove').mockImplementation();
jest.spyOn(virtualScroller.anchorEl, 'removeChild').mockImplementation();

virtualScroller.scrollingEl = scrollingEl;
virtualScroller.scrollingEl = document.createElement('div');
virtualScroller.listEl = {};

virtualScroller.destroy();

expect(scrollingEl.remove).toBeCalled();
expect(virtualScroller.anchorEl.removeChild).toBeCalled();
expect(virtualScroller.scrollingEl).toBeNull();
expect(virtualScroller.listEl).toBeNull();
});
Expand Down Expand Up @@ -464,14 +463,15 @@ describe('VirtualScroller', () => {

beforeEach(() => {
stubs.dispatchEvent = jest.fn();
scrollingEl = { remove: () => {}, dispatchEvent: stubs.dispatchEvent };
scrollingEl = { dispatchEvent: stubs.dispatchEvent };

virtualScroller.totalItems = 10;
virtualScroller.itemHeight = 10;
virtualScroller.margin = 0;
virtualScroller.scrollingEl = scrollingEl;

stubs.isVisible = jest.spyOn(virtualScroller, 'isVisible').mockImplementation();
stubs.removeChild = jest.spyOn(virtualScroller.anchorEl, 'removeChild').mockImplementation();
stubs.scrollIntoView = jest.fn();

listEl = {
Expand Down Expand Up @@ -555,8 +555,9 @@ describe('VirtualScroller', () => {

describe('isVisible()', () => {
beforeEach(() => {
const scrollingEl = { scrollTop: 100, remove: () => {} };
virtualScroller.scrollingEl = scrollingEl;
jest.spyOn(virtualScroller.anchorEl, 'removeChild').mockImplementation();

virtualScroller.scrollingEl = { scrollTop: 100 };
virtualScroller.containerHeight = 100;
virtualScroller.itemHeight = 20;
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class DocBaseViewer extends BaseViewer {
// Since we are cleaning up make sure the thumbnails open class is
// removed so that the content div shifts back left
this.rootEl.classList.remove(CLASS_BOX_PREVIEW_THUMBNAILS_OPEN);
this.thumbnailsSidebarEl.remove();
this.rootEl.removeChild(this.thumbnailsSidebarEl);
this.thumbnailsSidebarEl = null;
}

Expand Down
14 changes: 8 additions & 6 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
});

describe('destroy()', () => {
beforeEach(() => {
jest.spyOn(docBase.rootEl, 'removeChild').mockImplementation();
});

test('should unbind listeners and clear the print blob', () => {
const unbindDomStub = jest.spyOn(docBase, 'unbindDOMListeners').mockImplementation();
const unbindEventBusStub = jest.spyOn(docBase, 'unbindEventBusListeners').mockImplementation();
Expand Down Expand Up @@ -313,14 +317,11 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
docBase.thumbnailsSidebar = {
destroy: jest.fn(),
};
const thumbnailsSidebarEl = {
remove: jest.fn(),
};
docBase.thumbnailsSidebarEl = thumbnailsSidebarEl;
docBase.thumbnailsSidebarEl = document.createElement('div');

docBase.destroy();
expect(docBase.thumbnailsSidebar.destroy).toBeCalled();
expect(thumbnailsSidebarEl.remove).toBeCalled();
expect(docBase.rootEl.removeChild).toBeCalled();
expect(stubs.classListRemove).toBeCalled();
});
});
Expand Down Expand Up @@ -2467,6 +2468,8 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {

describe('handleAnnotatorEvents()', () => {
beforeEach(() => {
jest.spyOn(docBase.rootEl, 'removeChild').mockImplementation();

stubs.classListAdd = jest.fn();
stubs.classListRemove = jest.fn();
stubs.handleAnnotatorEvents = jest
Expand All @@ -2478,7 +2481,6 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
add: stubs.classListAdd,
remove: stubs.classListRemove,
},
remove: jest.fn(),
};
});

Expand Down

0 comments on commit 3c37b79

Please sign in to comment.