X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fpathological_cases.js;h=0bcab0b79c03dba3533b6a0f5e0b5e14b7047c26;hb=ac928d203b05de4a8d43ad89667347865e98bb7c;hp=502c8fdb62c4c499928a7909e7551f4636879e89;hpb=fa460473ef9397759466361ff32de56a4f8fa956;p=dygraphs.git diff --git a/auto_tests/tests/pathological_cases.js b/auto_tests/tests/pathological_cases.js index 502c8fd..0bcab0b 100644 --- a/auto_tests/tests/pathological_cases.js +++ b/auto_tests/tests/pathological_cases.js @@ -4,27 +4,37 @@ * * @author dan@dygraphs.com (Dan Vanderkam) */ -var pathologicalCasesTestCase = TestCase("pathological-cases"); -pathologicalCasesTestCase.prototype.setUp = function() { - document.body.innerHTML = "
"; -}; +import Dygraph from '../../src/dygraph'; +import Util from './Util'; -pathologicalCasesTestCase.prototype.tearDown = function() { -}; +describe("pathological-cases", function() { -pathologicalCasesTestCase.prototype.testZeroPoint = function() { +cleanupAfterEach(); + +var restoreConsole; +var logs = {}; +beforeEach(function() { + restoreConsole = Util.captureConsole(logs); +}); + +afterEach(function() { + restoreConsole(); +}); + +var graph = document.getElementById("graph"); + +it('testZeroPoint', function() { var opts = { width: 480, height: 320 }; var data = "X,Y\n"; - var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, opts); -}; +}); -pathologicalCasesTestCase.prototype.testOnePoint = function() { +it('testOnePoint', function() { var opts = { width: 480, height: 320 @@ -32,11 +42,10 @@ pathologicalCasesTestCase.prototype.testOnePoint = function() { var data = "X,Y\n" + "1,2\n"; - var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, opts); -}; +}); -pathologicalCasesTestCase.prototype.testCombinations = function() { +it('testCombinations', function() { var dataSets = { empty: [], onePoint: [[10, 2]], @@ -68,8 +77,8 @@ pathologicalCasesTestCase.prototype.testCombinations = function() { padded: { includeZero: true, drawAxesAtZero: true, - xRangePad: 0.02, - yRangePad: 0.04 + xRangePad: 2, + yRangePad: 4 } }; @@ -93,7 +102,7 @@ pathologicalCasesTestCase.prototype.testCombinations = function() { var h = document.createElement('h3'); h.appendChild(document.createTextNode(baseName + ' ' + variantName)); - document.body.appendChild(h); + graph.appendChild(h); for (var dataName in dataSets) { var data = dataSets[dataName]; @@ -105,18 +114,28 @@ pathologicalCasesTestCase.prototype.testCombinations = function() { var gdiv = document.createElement('div'); gdiv.style.display = 'inline-block'; box.appendChild(gdiv); - document.body.appendChild(box); + graph.appendChild(box); var cols = data && data[0] ? data[0].length : 0; opts.labels = ['X', 'A', 'B', 'C'].slice(0, cols); var g = new Dygraph(gdiv, data, opts); + + if (dataName == 'empty') { + assert.deepEqual(logs, { + log: [], warn: [], + error: ["Can't plot empty data set"] + }); + logs.error = []; // reset + } else { + assert.deepEqual(logs, {log: [], warn: [], error: []}); + } } } } -}; +}); -pathologicalCasesTestCase.prototype.testNullLegend = function() { +it('testNullLegend', function() { var opts = { width: 480, height: 320, @@ -125,13 +144,52 @@ pathologicalCasesTestCase.prototype.testNullLegend = function() { var data = "X,Y\n" + "1,2\n"; - var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, opts); -}; +}); -pathologicalCasesTestCase.prototype.testDivAsString = function() { +it('testDivAsString', function() { var data = "X,Y\n" + "1,2\n"; var g = new Dygraph('graph', data, {}); -} +}); + + +it('testConstantSeriesNegative', function() { + var data = "X,Y\n" + + "1,-1\n" + + "2,-1\n"; + + var g = new Dygraph('graph', data, {}); + // This check could be loosened to + // g.yAxisRange()[0] < g.yAxisRange()[1] if it breaks in the future. + assert.deepEqual([-1.1, -0.9], g.yAxisRange()); +}); + + +it('testConstantSeriesNegativeIncludeZero', function() { + var data = "X,Y\n" + + "1,-1\n" + + "2,-1\n"; + + var g = new Dygraph('graph', data, {includeZero: true}); + // This check could be loosened to + // g.yAxisRange()[0] < g.yAxisRange()[1] if it breaks in the future. + assert.deepEqual([-1.1, 0], g.yAxisRange()); +}); + +it('should throw with non-existent divs', function() { + var data = "X,Y\n" + + "1,-1\n" + + "2,1\n"; + + assert.throws(function() { + new Dygraph(null, data); + }, /non-existent div/); + + assert.throws(function() { + new Dygraph('non-existent-div-id', data); + }, /non-existent div/); +}); + +});