X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fscrolling_div.js;h=c9dec0c76ab10cace5de4e1535cbc8f2b5e29c76;hb=refs%2Ftags%2Fv2.0.0;hp=93a6fc658204b924773e0e9564ec9b103c1d285c;hpb=bf06e350a2e24db8f7da48e9ba3589b41b9d2338;p=dygraphs.git
diff --git a/auto_tests/tests/scrolling_div.js b/auto_tests/tests/scrolling_div.js
index 93a6fc6..c9dec0c 100644
--- a/auto_tests/tests/scrolling_div.js
+++ b/auto_tests/tests/scrolling_div.js
@@ -3,9 +3,15 @@
*
* @author konigsberg@google.com (Robert Konigsbrg)
*/
-var ScrollingDivTestCase = TestCase("scrolling-div");
-ScrollingDivTestCase.prototype.setUp = function() {
+import Dygraph from '../../src/dygraph';
+import DygraphOps from './DygraphOps';
+
+describe("scrolling-div", function() {
+
+var point, g;
+
+beforeEach(function() {
var LOREM_IPSUM =
"
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\n" +
@@ -16,14 +22,19 @@ var LOREM_IPSUM =
"non proident, sunt in culpa qui officia deserunt mollit anim id est\n" +
"laborum.
";
- document.body.innerHTML =
- "" +
- "
" +
+ var testDiv = document.getElementById('graph');
+ testDiv.innerHTML =
+ "
";
+ // The old test runner had an 8px margin on the body
+ // The Mocha test runner does not. We set it on the test div to keep the
+ // coordinates the same.
+ testDiv.style.margin = '8px';
+
var data = [
[ 10, 1 ],
[ 20, 3 ],
@@ -34,32 +45,51 @@ var LOREM_IPSUM =
[ 70, 4 ],
[ 80, 6 ] ];
- var graph = document.getElementById("graph");
+ var graph = document.getElementById("graph-inner");
- this.point = null;
- var self = this;
- this.g = new Dygraph(graph, data,
+ point = null;
+ g = new Dygraph(graph, data,
{
labels : ['a', 'b'],
drawPoints : true,
highlightCircleSize : 6,
- pointClickCallback : function(evt, point) {
- self.point = point;
+ pointClickCallback : function(evt, p) {
+ point = p;
}
}
);
-};
-
-ScrollingDivTestCase.prototype.tearDown = function() {
+});
+
+// This is usually something like 15, but for OS X Lion and its auto-hiding
+// scrollbars, it's 0. This is a large enough difference that we need to
+// consider it when synthesizing clicks.
+// Adapted from http://davidwalsh.name/detect-scrollbar-width
+var detectScrollbarWidth = function() {
+ // Create the measurement node
+ var scrollDiv = document.createElement("div");
+ scrollDiv.style.width = "100px";
+ scrollDiv.style.height = "100px";
+ scrollDiv.style.overflow = "scroll";
+ scrollDiv.style.position = "absolute";
+ scrollDiv.style.top = "-9999px";
+ document.body.appendChild(scrollDiv);
+
+ // Get the scrollbar width
+ var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
+
+ // Delete the DIV
+ document.body.removeChild(scrollDiv);
+
+ return scrollbarWidth;
};
/**
* This tests that when the nested div is unscrolled, things work normally.
*/
-ScrollingDivTestCase.prototype.testUnscrolledDiv = function() {
+it('testUnscrolledDiv', function() {
- window.location.href="#TOP";
+ document.getElementById('scroller').scrollTop = 0;
var clickOn4_40 = {
clientX: 244,
@@ -68,117 +98,33 @@ ScrollingDivTestCase.prototype.testUnscrolledDiv = function() {
screenY: 320
};
- DygraphOps.dispatchCanvasEvent(this.g, DygraphOps.createEvent(clickOn4_40, { type : 'mousemove' }));
- DygraphOps.dispatchCanvasEvent(this.g, DygraphOps.createEvent(clickOn4_40, { type : 'mousedown' }));
- DygraphOps.dispatchCanvasEvent(this.g, DygraphOps.createEvent(clickOn4_40, { type : 'mouseup' }));
+ DygraphOps.dispatchCanvasEvent(g, DygraphOps.createEvent(clickOn4_40, { type : 'mousemove' }));
+ DygraphOps.dispatchCanvasEvent(g, DygraphOps.createEvent(clickOn4_40, { type : 'mousedown' }));
+ DygraphOps.dispatchCanvasEvent(g, DygraphOps.createEvent(clickOn4_40, { type : 'mouseup' }));
- assertEquals(40, this.point.xval);
- assertEquals(4, this.point.yval);
-};
+ assert.equal(40, point.xval);
+ assert.equal(4, point.yval);
+});
/**
* This tests that when the nested div is scrolled, things work normally.
*/
-ScrollingDivTestCase.prototype.testScrolledDiv = function() {
- window.location.href="#BOTTOM";
+it('testScrolledDiv', function() {
+ document.getElementById('scroller').scrollTop = 117;
var clickOn4_40 = {
clientX: 244,
- clientY: 20,
+ clientY: 30 - detectScrollbarWidth(),
screenX: 416,
screenY: 160
};
- DygraphOps.dispatchCanvasEvent(this.g, DygraphOps.createEvent(clickOn4_40, { type : 'mousemove' }));
- DygraphOps.dispatchCanvasEvent(this.g, DygraphOps.createEvent(clickOn4_40, { type : 'mousedown' }));
- DygraphOps.dispatchCanvasEvent(this.g, DygraphOps.createEvent(clickOn4_40, { type : 'mouseup' }));
+ DygraphOps.dispatchCanvasEvent(g, DygraphOps.createEvent(clickOn4_40, { type : 'mousemove' }));
+ DygraphOps.dispatchCanvasEvent(g, DygraphOps.createEvent(clickOn4_40, { type : 'mousedown' }));
+ DygraphOps.dispatchCanvasEvent(g, DygraphOps.createEvent(clickOn4_40, { type : 'mouseup' }));
- assertEquals(40, this.point.xval);
- assertEquals(4, this.point.yval);
-};
+ assert.equal(40, point.xval);
+ assert.equal(4, point.yval);
+});
-/*
-NORMAL
-
-mousedown
-MouseEvent
-
-defaultPrevented?
-detail?
-returnValue?
-
-srcElement
-target
-toElement
-
-type: "mousedown"
-
-pageX: 244
-pageY: 131
-layerX: 233
-layerY: 281
-offsetX: 236
-offsetY: 235
-which: 1
-x: 244
-y: 131
-
-mouseup
-MouseEvent
-
-clientX: 244
-clientY: 131
-screenX: 416
-screenY: 320
-type: "mouseup"
-
-pageX: 244
-pageY: 131
-layerX: 233
-layerY: 281
-offsetX: 236
-offsetY: 235
-which: 1
-x: 244
-y: 131
-
-
-SCROLLED
-
-mousedown
-MouseEvent
-
-clientX: 244
-clientY: 20
-pageX: 244
-pageY: 20
-screenX: 417
-screenY: 160
-type: "mousedown"
-
-layerX: 233
-layerY: 170
-offsetX: 236
-offsetY: 124
-which: 1
-x: 244
-y: 20
-
-mouseup
-MouseEvent
-
-clientX: 244
-clientY: 20
-layerX: 233
-layerY: 170
-offsetX: 236
-offsetY: 124
-pageX: 244
-pageY: 20
-screenX: 417
-screenY: 160
-type: "mouseup"
-which: 1
-x: 244
-y: 20
-*/
\ No newline at end of file
+});