| 1 | /** |
| 2 | * @fileoverview Test cases for resizing. |
| 3 | * |
| 4 | * @author konigsberg@google.com (Robert Konigsberg) |
| 5 | */ |
| 6 | var ResizeTestCase = TestCase("resize"); |
| 7 | |
| 8 | ResizeTestCase.prototype.setUp = function() { |
| 9 | document.body.innerHTML = "<div id='graph'></div>"; |
| 10 | }; |
| 11 | |
| 12 | ResizeTestCase.prototype.tearDown = function() { |
| 13 | }; |
| 14 | |
| 15 | ResizeTestCase.prototype.testResizeMaintainsMouseOperations = function() { |
| 16 | document.body.innerHTML = |
| 17 | '<div id="graph" style="width: 640px; height: 480px;"></div>' + |
| 18 | '</div>'; |
| 19 | var graph = document.getElementById("graph"); |
| 20 | |
| 21 | var callbackCount = 0; |
| 22 | var callback = function() { |
| 23 | callbackCount++; |
| 24 | } |
| 25 | |
| 26 | // Strum the mouse along the y-coordinate y, from 0 to x2. These are DOM values. |
| 27 | var strum = function(g, y, x2) { |
| 28 | DygraphOps.dispatchMouseDown_Point(g, 0, y); |
| 29 | for (var x = 0; x < x2; x++) { |
| 30 | DygraphOps.dispatchMouseMove_Point(g, x, y); |
| 31 | } |
| 32 | DygraphOps.dispatchMouseUp_Point(g, x2 - 1, y); |
| 33 | } |
| 34 | |
| 35 | g = new Dygraph(graph, |
| 36 | "Date,Y\n" + |
| 37 | "2010/01/01,100\n" + |
| 38 | "2010/02/01,200\n" + |
| 39 | "2010/03/01,300\n" + |
| 40 | "2010/04/01,400\n" + |
| 41 | "2010/05/01,300\n" + |
| 42 | "2010/06/01,100\n", |
| 43 | { highlightCallback : callback }); |
| 44 | |
| 45 | strum(g, 300, 640); |
| 46 | assertEquals(6, callbackCount); |
| 47 | |
| 48 | document.getElementById("graph").style.width = "500px"; |
| 49 | g.resize(); |
| 50 | |
| 51 | callbackCount = 0; |
| 52 | strum(g, 300, 500); |
| 53 | assertEquals(6, callbackCount); |
| 54 | }; |