Extract hover behavior

This commit is contained in:
John Firebaugh
2012-12-07 14:43:42 -05:00
parent fb4b4fff57
commit 2d3ce6c125
13 changed files with 84 additions and 52 deletions
+3
View File
@@ -66,6 +66,7 @@
<script src='../js/id/behavior/drag_accuracy_handle.js'></script>
<script src='../js/id/behavior/drag_node.js'></script>
<script src='../js/id/behavior/drag_way.js'></script>
<script src='../js/id/behavior/hover.js'></script>
<script src='../js/id/modes.js'></script>
<script src='../js/id/modes/add_area.js'></script>
@@ -111,6 +112,8 @@
<script src="spec/actions/remove_relation_member.js"></script>
<script src="spec/actions/reverse_way.js"></script>
<script src="spec/behavior/hover.js"></script>
<script src="spec/format/geojson.js"></script>
<script src="spec/format/xml.js"></script>
+2
View File
@@ -38,6 +38,8 @@
<script src="spec/actions/remove_relation_member.js"></script>
<script src="spec/actions/reverse_way.js"></script>
<script src="spec/behavior/hover.js"></script>
<script src="spec/format/geojson.js"></script>
<script src="spec/format/xml.js"></script>
+36
View File
@@ -0,0 +1,36 @@
describe("iD.behavior.Hover", function() {
var container;
beforeEach(function() {
container = d3.select('body').append('div');
});
afterEach(function() {
container.remove();
});
describe("mouseover", function () {
it("adds the 'hover' class to all elements to which the same datum is bound", function () {
container.selectAll('span')
.data(['a', 'b', 'a', 'b'])
.enter().append('span').attr('class', Object);
container.call(iD.behavior.Hover());
container.selectAll('.a').trigger('mouseover');
expect(container.selectAll('.a.hover')[0]).to.have.length(2);
expect(container.selectAll('.b.hover')[0]).to.have.length(0);
});
});
describe("mouseout", function () {
it("removes the 'hover' class from all elements", function () {
container.append('span').attr('class', 'hover');
container.call(iD.behavior.Hover());
container.selectAll('.hover').trigger('mouseout');
expect(container.selectAll('.hover')[0]).to.have.length(0);
});
});
});