Commit 79f92349 authored by Eduardo Sanz García's avatar Eduardo Sanz García Committed by Eduardo

Remove element bucket-bar upon destruction

This was never an issue because the parent elements are destroyed,
however for completeness is better to add it.

In addition, I modified the test so that all the elements created are
added to a single parent container who is deleted after each test.
parent 274908cd
...@@ -37,6 +37,7 @@ export default class BucketBar { ...@@ -37,6 +37,7 @@ export default class BucketBar {
window.removeEventListener('resize', this.updateFunc); window.removeEventListener('resize', this.updateFunc);
window.removeEventListener('scroll', this.updateFunc); window.removeEventListener('scroll', this.updateFunc);
this._contentContainer.removeEventListener('scroll', this.updateFunc); this._contentContainer.removeEventListener('scroll', this.updateFunc);
this.element.remove();
} }
update() { update() {
......
...@@ -7,15 +7,16 @@ describe('BucketBar', () => { ...@@ -7,15 +7,16 @@ describe('BucketBar', () => {
let fakeBucketUtil; let fakeBucketUtil;
let bucketBars; let bucketBars;
let bucketProps; let bucketProps;
let container;
const createBucketBar = function (options) { const createBucketBar = function (options) {
const element = document.createElement('div'); const bucketBar = new BucketBar(container, fakeAnnotator, options);
const bucketBar = new BucketBar(element, fakeAnnotator, options);
bucketBars.push(bucketBar); bucketBars.push(bucketBar);
return bucketBar; return bucketBar;
}; };
beforeEach(() => { beforeEach(() => {
container = document.createElement('div');
bucketBars = []; bucketBars = [];
bucketProps = {}; bucketProps = {};
fakeAnnotator = { fakeAnnotator = {
...@@ -44,6 +45,7 @@ describe('BucketBar', () => { ...@@ -44,6 +45,7 @@ describe('BucketBar', () => {
bucketBars.forEach(bucketBar => bucketBar.destroy()); bucketBars.forEach(bucketBar => bucketBar.destroy());
$imports.$restore(); $imports.$restore();
sandbox.restore(); sandbox.restore();
container.remove();
}); });
it('should render buckets for existing anchors when constructed', () => { it('should render buckets for existing anchors when constructed', () => {
...@@ -81,22 +83,22 @@ describe('BucketBar', () => { ...@@ -81,22 +83,22 @@ describe('BucketBar', () => {
}); });
context('when `contentContainer` is specified', () => { context('when `contentContainer` is specified', () => {
let container; let contentContainer;
beforeEach(() => { beforeEach(() => {
container = document.createElement('div'); contentContainer = document.createElement('div');
document.body.appendChild(container); document.body.appendChild(contentContainer);
}); });
afterEach(() => { afterEach(() => {
container.remove(); contentContainer.remove();
}); });
it('should update buckets when any scrollable scrolls', () => { it('should update buckets when any scrollable scrolls', () => {
createBucketBar({ contentContainer: container }); createBucketBar({ contentContainer });
fakeBucketUtil.anchorBuckets.resetHistory(); fakeBucketUtil.anchorBuckets.resetHistory();
container.dispatchEvent(new Event('scroll')); contentContainer.dispatchEvent(new Event('scroll'));
assert.calledOnce(fakeBucketUtil.anchorBuckets); assert.calledOnce(fakeBucketUtil.anchorBuckets);
}); });
...@@ -119,6 +121,12 @@ describe('BucketBar', () => { ...@@ -119,6 +121,12 @@ describe('BucketBar', () => {
bucketBar.update(); bucketBar.update();
assert.notCalled(window.requestAnimationFrame); assert.notCalled(window.requestAnimationFrame);
}); });
it('deletes the bucketbar element after destroy method is called', () => {
const bucketBar = createBucketBar();
bucketBar.destroy();
assert.isFalse(container.hasChildNodes());
});
}); });
it('should stop listening for scroll events when destroyed', () => { it('should stop listening for scroll events when destroyed', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment