|
| 1 | +var d3 = require('d3'); |
| 2 | + |
1 | 3 | var Plotly = require('@lib/index');
|
2 | 4 | var Lib = require('@src/lib');
|
3 | 5 | var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY;
|
@@ -54,6 +56,104 @@ describe('select box and lasso', function() {
|
54 | 56 | expect(actual.y).toBeCloseToArray(expected.y, PRECISION);
|
55 | 57 | }
|
56 | 58 |
|
| 59 | + describe('select elements', function() { |
| 60 | + var mockCopy = Lib.extendDeep({}, mock); |
| 61 | + mockCopy.layout.dragmode = 'select'; |
| 62 | + |
| 63 | + var gd; |
| 64 | + beforeEach(function(done) { |
| 65 | + gd = createGraphDiv(); |
| 66 | + |
| 67 | + Plotly.plot(gd, mockCopy.data, mockCopy.layout) |
| 68 | + .then(done); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should be appended to the zoom layer', function(done) { |
| 72 | + var x0 = 100, |
| 73 | + y0 = 200, |
| 74 | + x1 = 150, |
| 75 | + y1 = 250, |
| 76 | + x2 = 50, |
| 77 | + y2 = 50; |
| 78 | + |
| 79 | + gd.once('plotly_selecting', function() { |
| 80 | + expect(d3.selectAll('.zoomlayer > .zoombox-corners').size()) |
| 81 | + .toEqual(1); |
| 82 | + expect(d3.selectAll('.zoomlayer > .select-outline').size()) |
| 83 | + .toEqual(2); |
| 84 | + }); |
| 85 | + |
| 86 | + gd.once('plotly_selected', function() { |
| 87 | + expect(d3.selectAll('.zoomlayer > .zoombox-corners').size()) |
| 88 | + .toEqual(0); |
| 89 | + expect(d3.selectAll('.zoomlayer > .select-outline').size()) |
| 90 | + .toEqual(2); |
| 91 | + }); |
| 92 | + |
| 93 | + gd.once('plotly_deselect', function() { |
| 94 | + expect(d3.selectAll('.zoomlayer > .select-outline').size()) |
| 95 | + .toEqual(0); |
| 96 | + }); |
| 97 | + |
| 98 | + mouseEvent('mousemove', x0, y0); |
| 99 | + expect(d3.selectAll('.zoomlayer > .zoombox-corners').size()) |
| 100 | + .toEqual(0); |
| 101 | + |
| 102 | + drag([[x0, y0], [x1, y1]]); |
| 103 | + |
| 104 | + doubleClick(x2, y2, done); |
| 105 | + }); |
| 106 | + }); |
| 107 | + |
| 108 | + describe('lasso elements', function() { |
| 109 | + var mockCopy = Lib.extendDeep({}, mock); |
| 110 | + mockCopy.layout.dragmode = 'lasso'; |
| 111 | + |
| 112 | + var gd; |
| 113 | + beforeEach(function(done) { |
| 114 | + gd = createGraphDiv(); |
| 115 | + |
| 116 | + Plotly.plot(gd, mockCopy.data, mockCopy.layout) |
| 117 | + .then(done); |
| 118 | + }); |
| 119 | + |
| 120 | + it('should be appended to the zoom layer', function(done) { |
| 121 | + var x0 = 100, |
| 122 | + y0 = 200, |
| 123 | + x1 = 150, |
| 124 | + y1 = 250, |
| 125 | + x2 = 50, |
| 126 | + y2 = 50; |
| 127 | + |
| 128 | + gd.once('plotly_selecting', function() { |
| 129 | + expect(d3.selectAll('.zoomlayer > .zoombox-corners').size()) |
| 130 | + .toEqual(1); |
| 131 | + expect(d3.selectAll('.zoomlayer > .select-outline').size()) |
| 132 | + .toEqual(2); |
| 133 | + }); |
| 134 | + |
| 135 | + gd.once('plotly_selected', function() { |
| 136 | + expect(d3.selectAll('.zoomlayer > .zoombox-corners').size()) |
| 137 | + .toEqual(0); |
| 138 | + expect(d3.selectAll('.zoomlayer > .select-outline').size()) |
| 139 | + .toEqual(2); |
| 140 | + }); |
| 141 | + |
| 142 | + gd.once('plotly_deselect', function() { |
| 143 | + expect(d3.selectAll('.zoomlayer > .select-outline').size()) |
| 144 | + .toEqual(0); |
| 145 | + }); |
| 146 | + |
| 147 | + mouseEvent('mousemove', x0, y0); |
| 148 | + expect(d3.selectAll('.zoomlayer > .zoombox-corners').size()) |
| 149 | + .toEqual(0); |
| 150 | + |
| 151 | + drag([[x0, y0], [x1, y1]]); |
| 152 | + |
| 153 | + doubleClick(x2, y2, done); |
| 154 | + }); |
| 155 | + }); |
| 156 | + |
57 | 157 | describe('select events', function() {
|
58 | 158 | var mockCopy = Lib.extendDeep({}, mock);
|
59 | 159 | mockCopy.layout.dragmode = 'select';
|
|
0 commit comments