Skip to content

Commit

Permalink
fix: issue #257 (#264)
Browse files Browse the repository at this point in the history
Cleanup activator.current reference on deactivate.
Add test for activator.
  • Loading branch information
fodpeter authored and yotamberk committed Jan 21, 2020
1 parent 4a79838 commit 1affb70
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/shared/Activator.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ Activator.prototype.activate = function () {
* Overlay is displayed on top of the element
*/
Activator.prototype.deactivate = function () {
if (Activator.current === this) {
Activator.current = null;
}

this.active = false;
this.dom.overlay.style.display = '';
util.removeClassName(this.dom.container, 'vis-active');
Expand Down
37 changes: 37 additions & 0 deletions test/Activator.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import assert from 'assert'
import jsdom_global from 'jsdom-global'
import Activator from '../lib/shared/Activator';

const internals = {}

describe('Activator', () => {
beforeEach(() => {
internals.jsdom_global = jsdom_global('<div id="id1"></div><div id="id2"></div>');
internals.div1 = document.getElementById('id1');
internals.div2 = document.getElementById('id2');
});

afterEach(() => {
internals.jsdom_global();
});

it('should activate only one at time', () => {
const a1 = new Activator(internals.div1);
const a2 = new Activator(internals.div2);
a1.activate();
assert(internals.div1.classList.contains('vis-active'));
assert(!internals.div2.classList.contains('vis-active'));
a2.activate();
assert(!internals.div1.classList.contains('vis-active'));
assert(internals.div2.classList.contains('vis-active'));
});

it('should not throw on activate after destroying another activator', () => {
const a1 = new Activator(internals.div1);
const a2 = new Activator(internals.div2);
a1.activate();
a1.destroy();
a2.activate();
assert(internals.div2.classList.contains('vis-active'));
});
});

0 comments on commit 1affb70

Please sign in to comment.