Skip to content
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

fix(thumbnails): Replace remove method that is unsupported in IE11 #1323

Merged
merged 1 commit into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? Not sure I see it being used in any test

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not really. I did it so it would fit in better with the other spy on the line above. I can remove it if it's concerning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not concerning, already approved

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