Skip to content

Commit a05080d

Browse files
committed
Update legend mouse wheel test
1 parent c96581c commit a05080d

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

test/jasmine/tests/legend_scroll_test.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var Plotly = require('@lib/index');
22
var Lib = require('@src/lib');
3+
var constants = require('@src/components/legend/constants');
34

45
var createGraph = require('../assets/create_graph_div');
56
var destroyGraph = require('../assets/destroy_graph_div');
@@ -55,14 +56,23 @@ describe('The legend', function() {
5556
});
5657

5758
it('should scroll when there\'s a wheel event', function() {
58-
var scrollBox = legend.getElementsByClassName('scrollbox')[0];
59-
60-
legend.dispatchEvent(scrollTo(100));
61-
62-
// Compare against -5 because of a scroll factor of 20
63-
// ( 100 / 20 === 5 )
64-
expect(scrollBox.getAttribute('transform')).toBe('translate(0, -5)');
65-
expect(scrollBox.getAttribute('data-scroll')).toBe('-5');
59+
var scrollBox = legend.getElementsByClassName('scrollbox')[0],
60+
legendHeight = getBBox(legend).height,
61+
scrollBoxYMax = gd._fullLayout.legend.height - legendHeight,
62+
scrollBarYMax = legendHeight -
63+
constants.scrollBarHeight -
64+
2 * constants.scrollBarMargin,
65+
initialDataScroll = scrollBox.getAttribute('data-scroll'),
66+
wheelDeltaY = 100,
67+
finalDataScroll = '' + Lib.constrain(initialDataScroll -
68+
wheelDeltaY / scrollBarYMax * scrollBoxYMax,
69+
-scrollBoxYMax, 0);
70+
71+
legend.dispatchEvent(scrollTo(wheelDeltaY));
72+
73+
expect(scrollBox.getAttribute('data-scroll')).toBe(finalDataScroll);
74+
expect(scrollBox.getAttribute('transform')).toBe(
75+
'translate(0, ' + finalDataScroll + ')');
6676
});
6777

6878
it('should constrain scrolling to the contents', function() {

0 commit comments

Comments
 (0)