Fix hover tests

This commit is contained in:
Bryan Housel
2017-04-24 10:05:02 -04:00
parent 14ebd273b5
commit 149cbbe350
2 changed files with 20 additions and 9 deletions

View File

@@ -123,13 +123,16 @@ export function behaviorHover() {
};
hover.off = function() {
_selection.selectAll('.hover')
hover.off = function(selection) {
selection.selectAll('.hover')
.classed('hover', false);
_selection.selectAll('.hover-suppressed')
selection.selectAll('.hover-suppressed')
.classed('hover-suppressed', false);
selection
.classed('hover-disabled', false);
_selection
selection
.on('mouseover.hover', null)
.on('mouseout.hover', null)
.on('mousedown.hover', null);

View File

@@ -16,7 +16,12 @@ describe('iD.behaviorHover', function() {
it('removes the .hover class from all elements', function () {
container.append('span').attr('class', 'hover');
container.call(iD.behaviorHover(context).off);
expect(container.select('span')).not.to.be.classed('hover');
expect(container.select('span').classed('hover')).to.be.false;
});
it('removes the .hover-disabled class from the surface element', function () {
container.attr('class', 'hover-disabled');
container.call(iD.behaviorHover(context).off);
expect(container.classed('hover-disabled')).to.be.false;
});
});
@@ -63,34 +68,37 @@ describe('iD.behaviorHover', function() {
describe('alt keydown', function () {
it('replaces the .hover class with .hover-suppressed', function () {
container.append('span').attr('class', 'hover');
container.call(iD.behaviorHover(context).altDisables(true));
happen.keydown(window, {keyCode: 18});
happen.keydown(window, {keyCode: 18});
expect(container.selectAll('.hover').nodes()).to.have.length(0);
expect(container.selectAll('.hover-suppressed').nodes()).to.have.length(1);
happen.keyup(window, {keyCode: 18});
});
it('adds the .hover-disabled class to the surface', function () {
container.call(iD.behaviorHover(context).altDisables(true));
happen.keydown(window, {keyCode: 18});
expect(container.classed('hover-disabled')).to.be.true;
happen.keyup(window, {keyCode: 18});
});
});
describe('alt keyup', function () {
it('replaces the .hover-suppressed class with .hover', function () {
container.append('span').attr('class', 'hover-suppressed');
container.call(iD.behaviorHover(context).altDisables(true));
happen.keyup(window, {keyCode: 18});
happen.keydown(window, {keyCode: 18});
happen.keyup(window, {keyCode: 18});
expect(container.selectAll('.hover').nodes()).to.have.length(1);
expect(container.selectAll('.hover-suppressed').nodes()).to.have.length(0);
});
it('removes the .hover-disabled class from the surface', function () {
container.call(iD.behaviorHover(context).altDisables(true));
happen.keydown(window, {keyCode: 18});
happen.keyup(window, {keyCode: 18});
expect(container.classed('hover-disabled')).to.be.false;