From 9fea24b5852222bde3ae32710c38b20d2560f8f4 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 11 Jan 2021 11:32:21 -0500 Subject: [PATCH 1/4] use newPlot intead of plot in various tests --- devtools/test_dashboard/devtools.js | 2 +- test/jasmine/assets/check_component.js | 4 +- test/jasmine/assets/check_event_data.js | 2 +- test/jasmine/assets/fail_test.js | 2 +- test/jasmine/bundle_tests/bar_test.js | 2 +- test/jasmine/bundle_tests/choropleth_test.js | 2 +- test/jasmine/bundle_tests/contour_test.js | 2 +- test/jasmine/bundle_tests/core_test.js | 2 +- test/jasmine/bundle_tests/finance_test.js | 2 +- .../bundle_tests/histogram2dcontour_test.js | 2 +- test/jasmine/bundle_tests/mathjax_test.js | 2 +- test/jasmine/tests/geo_test.js | 143 +++++++++++------- test/jasmine/tests/gl2d_plot_interact_test.js | 17 ++- test/jasmine/tests/gl3d_plot_interact_test.js | 83 ++++++---- test/jasmine/tests/legend_test.js | 30 ++-- test/jasmine/tests/localize_test.js | 2 +- test/jasmine/tests/mapbox_test.js | 13 +- test/jasmine/tests/parcoords_test.js | 4 +- test/jasmine/tests/plot_promise_test.js | 28 ++-- 19 files changed, 210 insertions(+), 134 deletions(-) diff --git a/devtools/test_dashboard/devtools.js b/devtools/test_dashboard/devtools.js index 1dc1da2e4a3..a8228ec08c5 100644 --- a/devtools/test_dashboard/devtools.js +++ b/devtools/test_dashboard/devtools.js @@ -60,7 +60,7 @@ var Tabs = { var mockURL = '/test/image/mocks/' + mockName + '.json'; d3.json(mockURL, function(err, fig) { - Plotly.plot(Tabs.fresh(id), fig); + Plotly.newPlot(Tabs.fresh(id), fig); console.warn('Plotting:', mockURL); }); diff --git a/test/jasmine/assets/check_component.js b/test/jasmine/assets/check_component.js index 42ed8a9c6c2..1a2b6bc9a9b 100644 --- a/test/jasmine/assets/check_component.js +++ b/test/jasmine/assets/check_component.js @@ -38,7 +38,7 @@ module.exports = function checkComponent(Plotly) { beforeEach(function(done) { gd = createGraphDiv(); - Plotly.plot(gd, mock.data, mock.layout).then(done); + Plotly.newPlot(gd, mock.data, mock.layout).then(done); }); afterEach(destroyGraphDiv); @@ -74,7 +74,7 @@ module.exports = function checkComponent(Plotly) { beforeEach(function(done) { gd = createGraphDiv(); - Plotly.plot(gd, mock.data, mock.layout).then(done); + Plotly.newPlot(gd, mock.data, mock.layout).then(done); }); afterEach(destroyGraphDiv); diff --git a/test/jasmine/assets/check_event_data.js b/test/jasmine/assets/check_event_data.js index 8280491f53e..2bb59020888 100644 --- a/test/jasmine/assets/check_event_data.js +++ b/test/jasmine/assets/check_event_data.js @@ -14,7 +14,7 @@ module.exports = function checkEventData(mock, x, y, additionalFields) { beforeEach(function(done) { gd = createGraphDiv(); - Plotly.plot(gd, mockCopy.data, mockCopy.layout) + Plotly.newPlot(gd, mockCopy.data, mockCopy.layout) .then(done); }); diff --git a/test/jasmine/assets/fail_test.js b/test/jasmine/assets/fail_test.js index 32cb8a178f9..7cfa485c9d2 100644 --- a/test/jasmine/assets/fail_test.js +++ b/test/jasmine/assets/fail_test.js @@ -7,7 +7,7 @@ * * @example * - * Plotly.plot(...) + * Plotly.newPlot(...) * .then(function(gd) { * assert(...); * assert(...); diff --git a/test/jasmine/bundle_tests/bar_test.js b/test/jasmine/bundle_tests/bar_test.js index ae4e3726af6..c893a1c9c30 100644 --- a/test/jasmine/bundle_tests/bar_test.js +++ b/test/jasmine/bundle_tests/bar_test.js @@ -15,7 +15,7 @@ describe('Bundle with bar', function() { var mock = require('@mocks/bar_line.json'); beforeEach(function(done) { - Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done); + Plotly.newPlot(createGraphDiv(), mock.data, mock.layout).then(done); }); afterEach(destroyGraphDiv); diff --git a/test/jasmine/bundle_tests/choropleth_test.js b/test/jasmine/bundle_tests/choropleth_test.js index 38d4e5604c3..1efc4e206f7 100644 --- a/test/jasmine/bundle_tests/choropleth_test.js +++ b/test/jasmine/bundle_tests/choropleth_test.js @@ -26,7 +26,7 @@ describe('Bundle with choropleth', function() { afterEach(destroyGraphDiv); it('should graph choropleth traces', function(done) { - Plotly.plot(gd, mock.data, mock.layout) + Plotly.newPlot(gd, mock.data, mock.layout) .then(function() { var nodes = d3.selectAll('g.trace.choropleth'); diff --git a/test/jasmine/bundle_tests/contour_test.js b/test/jasmine/bundle_tests/contour_test.js index 2213a1b138c..3d9ba77f081 100644 --- a/test/jasmine/bundle_tests/contour_test.js +++ b/test/jasmine/bundle_tests/contour_test.js @@ -15,7 +15,7 @@ describe('Bundle with contour', function() { var mock = require('@mocks/contour_scatter.json'); beforeEach(function(done) { - Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done); + Plotly.newPlot(createGraphDiv(), mock.data, mock.layout).then(done); }); afterEach(destroyGraphDiv); diff --git a/test/jasmine/bundle_tests/core_test.js b/test/jasmine/bundle_tests/core_test.js index d029210f3ef..65610b9c5a5 100644 --- a/test/jasmine/bundle_tests/core_test.js +++ b/test/jasmine/bundle_tests/core_test.js @@ -14,7 +14,7 @@ describe('Bundle with core only', function() { beforeEach(function(done) { gd = createGraphDiv(); - Plotly.plot(gd, mock.data, mock.layout).then(done); + Plotly.newPlot(gd, mock.data, mock.layout).then(done); }); afterEach(destroyGraphDiv); diff --git a/test/jasmine/bundle_tests/finance_test.js b/test/jasmine/bundle_tests/finance_test.js index 0c35bf7df35..f78b76df327 100644 --- a/test/jasmine/bundle_tests/finance_test.js +++ b/test/jasmine/bundle_tests/finance_test.js @@ -28,7 +28,7 @@ describe('Bundle with finance trace type', function() { }); it('should graph ohlc and candlestick traces', function(done) { - Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(function() { + Plotly.newPlot(createGraphDiv(), mock.data, mock.layout).then(function() { var gSubplot = d3.select('g.cartesianlayer'); expect(gSubplot.selectAll('g.trace.ohlc').size()).toEqual(1); diff --git a/test/jasmine/bundle_tests/histogram2dcontour_test.js b/test/jasmine/bundle_tests/histogram2dcontour_test.js index 00fd58f08da..acd1c2fb322 100644 --- a/test/jasmine/bundle_tests/histogram2dcontour_test.js +++ b/test/jasmine/bundle_tests/histogram2dcontour_test.js @@ -16,7 +16,7 @@ describe('Bundle with histogram2dcontour and histogram', function() { var mock = require('@mocks/2dhistogram_contour_subplots.json'); beforeEach(function(done) { - Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done); + Plotly.newPlot(createGraphDiv(), mock.data, mock.layout).then(done); }); afterEach(destroyGraphDiv); diff --git a/test/jasmine/bundle_tests/mathjax_test.js b/test/jasmine/bundle_tests/mathjax_test.js index 092b1400be6..e082a37e6b3 100644 --- a/test/jasmine/bundle_tests/mathjax_test.js +++ b/test/jasmine/bundle_tests/mathjax_test.js @@ -56,7 +56,7 @@ describe('Test MathJax:', function() { function testTitleScoot(fig, opts) { var xCategories = opts.xCategories; - return Plotly.plot(gd, fig) + return Plotly.newPlot(gd, fig) .then(function() { assertNoIntersect('base'); }) .then(function() { return Plotly.relayout(gd, 'xaxis.titlefont.size', 40); }) .then(function() { assertNoIntersect('large title font size'); }) diff --git a/test/jasmine/tests/geo_test.js b/test/jasmine/tests/geo_test.js index 3652a2db99d..d83ace42a66 100644 --- a/test/jasmine/tests/geo_test.js +++ b/test/jasmine/tests/geo_test.js @@ -1216,7 +1216,7 @@ describe('Test geo interactions', function() { } gd.calcdata = undefined; - Plotly.plot(gd); + Plotly.newPlot(gd, gd.data, gd.layout); i++; }, INTERVAL); }); @@ -1247,7 +1247,7 @@ describe('Test geo interactions', function() { } gd.calcdata = undefined; - Plotly.plot(gd); + Plotly.newPlot(gd, gd.data, gd.layout); i++; }, INTERVAL); }); @@ -1278,7 +1278,7 @@ describe('Test geo interactions', function() { } gd.calcdata = undefined; - Plotly.plot(gd); + Plotly.newPlot(gd, gd.data, gd.layout); i++; }, INTERVAL); }); @@ -1293,7 +1293,8 @@ describe('Test geo interactions', function() { trace1.locations.shift(); gd.calcdata = undefined; - Plotly.plot(gd).then(function() { + Plotly.newPlot(gd, gd.data, gd.layout) + .then(function() { expect(countTraces('scattergeo')).toBe(1); expect(countTraces('choropleth')).toBe(1); @@ -1319,7 +1320,8 @@ describe('Test geo interactions', function() { trace1.z = zQueue; gd.calcdata = undefined; - Plotly.plot(gd).then(function() { + Plotly.newPlot(gd, gd.data, gd.layout) + .then(function() { expect(countTraces('scattergeo')).toBe(1); expect(countTraces('choropleth')).toBe(1); @@ -2108,16 +2110,16 @@ describe('Test geo zoom/pan/drag interactions:', function() { var eventData; var dblClickCnt = 0; - afterEach(destroyGraphDiv); + beforeEach(function() { gd = createGraphDiv(); }); - function plot(fig) { - gd = createGraphDiv(); + afterEach(destroyGraphDiv); + var newPlot = function(fig) { return Plotly.newPlot(gd, fig).then(function() { gd.on('plotly_relayout', function(d) { eventData = d; }); gd.on('plotly_doubleclick', function() { dblClickCnt++; }); }); - } + }; function assertEventData(msg, eventKeys) { if(eventKeys === 'dblclick') { @@ -2196,7 +2198,7 @@ describe('Test geo zoom/pan/drag interactions:', function() { } it('- base case', function(done) { - plot(fig).then(function() { + newPlot(fig).then(function() { _assert('base', [ [-90, 0], [-90, 0], 1 ], [ @@ -2261,7 +2263,7 @@ describe('Test geo zoom/pan/drag interactions:', function() { it('- fitbounds case', function(done) { fig.layout.geo.fitbounds = 'locations'; - plot(fig).then(function() { + newPlot(fig).then(function() { _assert('base', [ [undefined, 0], [undefined, undefined], undefined ], [ @@ -2345,7 +2347,7 @@ describe('Test geo zoom/pan/drag interactions:', function() { } it('- base case', function(done) { - plot(fig).then(function() { + newPlot(fig).then(function() { _assert('base', [ [-75, 45], 1 ], [ @@ -2408,7 +2410,7 @@ describe('Test geo zoom/pan/drag interactions:', function() { it('- fitbounds case', function(done) { fig.layout.geo.fitbounds = 'locations'; - plot(fig).then(function() { + newPlot(fig).then(function() { _assert('base', [ [undefined, undefined], undefined ], [ @@ -2496,7 +2498,7 @@ describe('Test geo zoom/pan/drag interactions:', function() { } it('- base case', function(done) { - plot(fig).then(function() { + newPlot(fig).then(function() { _assert('base', [ [15, 57.5], 1, ], [ @@ -2549,7 +2551,7 @@ describe('Test geo zoom/pan/drag interactions:', function() { it('- fitbounds case', function(done) { fig.layout.geo.fitbounds = 'locations'; - plot(fig).then(function() { + newPlot(fig).then(function() { _assert('base', [ [undefined, undefined], undefined, ], [ @@ -2631,7 +2633,7 @@ describe('Test geo zoom/pan/drag interactions:', function() { assertEventData(msg, eventKeys); } - plot(fig).then(function() { + newPlot(fig).then(function() { _assert('base', [ [-96.6, 38.7], 1, ], [ @@ -2689,7 +2691,7 @@ describe('Test geo zoom/pan/drag interactions:', function() { fig.layout.width = 700; fig.layout.height = 500; - plot(fig) + newPlot(fig) .then(function() { return scroll([131, 159], [-200, 200]); }) .then(function() { // scrolling outside subplot frame should log errors, @@ -2719,7 +2721,7 @@ describe('Test geo zoom/pan/drag interactions:', function() { assertEventData(msg, eventKeys); } - plot(fig) + newPlot(fig) .then(function() { _assert('base', [1], [101.9], undefined); }) @@ -2730,12 +2732,24 @@ describe('Test geo zoom/pan/drag interactions:', function() { ['geo.projection.rotation.lon', 'geo.center.lon', 'geo.center.lat', 'geo.projection.scale'] ); }) - .then(function() { return Plotly.plot(gd, [], {}, {scrollZoom: false}); }) + .then(function() { + return newPlot({ + data: gd.data, + layout: gd.layout, + config: {scrollZoom: false} + }); + }) .then(function() { return scroll([200, 250], [-200, -200]); }) .then(function() { _assert('with scrollZoom:false', [1.3], [134.4], undefined); }) - .then(function() { return Plotly.plot(gd, [], {}, {scrollZoom: 'geo'}); }) + .then(function() { + return newPlot({ + data: gd.data, + layout: gd.layout, + config: {scrollZoom: 'geo'} + }); + }) .then(function() { return scroll([200, 250], [-200, -200]); }) .then(function() { _assert('with scrollZoom:geo', @@ -2745,44 +2759,59 @@ describe('Test geo zoom/pan/drag interactions:', function() { }) .then(done, done.fail); }); +}); - describe('plotly_relayouting', function() { - var mocks = { - 'non-clipped': require('@mocks/geo_winkel-tripel'), - 'clipped': require('@mocks/geo_orthographic'), - 'scoped': require('@mocks/geo_europe-bubbles') - }; - ['non-clipped', 'clipped', 'scoped'].forEach(function(zoomHandler) { - ['pan'].forEach(function(dragmode) { - it('should emit events on ' + dragmode + ' for ' + zoomHandler, function(done) { - var events = []; var path = [[300, 300], [350, 300], [350, 400]]; - var relayoutCnt = 0; var relayoutEvent; - var fig = Lib.extendDeep({}, mocks[zoomHandler]); - fig.layout.dragmode = dragmode; - fig.layout.width = 700; - fig.layout.height = 500; - - gd = createGraphDiv(); - Plotly.newPlot(gd, fig) - .then(function() { - gd.on('plotly_relayout', function(e) { - relayoutCnt++; - relayoutEvent = e; - }); - gd.on('plotly_relayouting', function(e) { - events.push(e); - }); - return drag({path: path, noCover: true}); - }) - .then(function() { - expect(events.length).toEqual(path.length - 1); - expect(relayoutCnt).toEqual(1); - Object.keys(relayoutEvent).sort().forEach(function(key) { - expect(Object.keys(events[0])).toContain(key); - }); - }) - .then(done, done.fail); - }); +describe('plotly_relayouting', function() { + var gd; + var events; + var relayoutCnt; + var relayoutEvent; + + beforeEach(function() { gd = createGraphDiv(); }); + + afterEach(destroyGraphDiv); + + var newPlot = function(fig) { + events = []; + relayoutCnt = 0; + + return Plotly.newPlot(gd, fig).then(function() { + gd.on('plotly_relayout', function(e) { + relayoutCnt++; + relayoutEvent = e; + }); + gd.on('plotly_relayouting', function(e) { + events.push(e); + }); + }); + }; + + var mocks = { + 'non-clipped': require('@mocks/geo_winkel-tripel'), + 'clipped': require('@mocks/geo_orthographic'), + 'scoped': require('@mocks/geo_europe-bubbles') + }; + ['non-clipped', 'clipped', 'scoped'].forEach(function(zoomHandler) { + ['pan'].forEach(function(dragmode) { + it('should emit events on ' + dragmode + ' for ' + zoomHandler, function(done) { + var path = [[300, 300], [350, 300], [350, 400]]; + var fig = Lib.extendDeep({}, mocks[zoomHandler]); + fig.layout.dragmode = dragmode; + fig.layout.width = 700; + fig.layout.height = 500; + + newPlot(fig) + .then(function() { + return drag({path: path, noCover: true}); + }) + .then(function() { + expect(events.length).toEqual(path.length - 1); + expect(relayoutCnt).toEqual(1); + Object.keys(relayoutEvent).sort().forEach(function(key) { + expect(Object.keys(events[0])).toContain(key); + }); + }) + .then(done, done.fail); }); }); }); diff --git a/test/jasmine/tests/gl2d_plot_interact_test.js b/test/jasmine/tests/gl2d_plot_interact_test.js index a2b64a9e6d3..156cd063ead 100644 --- a/test/jasmine/tests/gl2d_plot_interact_test.js +++ b/test/jasmine/tests/gl2d_plot_interact_test.js @@ -254,9 +254,6 @@ describe('Test gl plot side effects', function() { }); it('@gl should not clear context when dimensions are not integers', function(done) { - spyOn(Plots, 'cleanPlot').and.callThrough(); - spyOn(Lib, 'log').and.callThrough(); - var w = 500.5; var h = 400.5; var w0 = Math.floor(w); @@ -276,13 +273,19 @@ describe('Test gl plot side effects', function() { expect(gl.drawingBufferHeight).toBe(h0, msg); } - Plotly.plot(gd, [{ + Plotly.newPlot(gd, [{ type: 'scattergl', mode: 'lines', y: [1, 2, 1] - }], { - width: w, - height: h + }]) + .then(function() { + spyOn(Plots, 'cleanPlot').and.callThrough(); + spyOn(Lib, 'log').and.callThrough(); + + return Plotly.relayout(gd, { + width: w, + height: h + }); }) .then(function() { assertDims('base state'); diff --git a/test/jasmine/tests/gl3d_plot_interact_test.js b/test/jasmine/tests/gl3d_plot_interact_test.js index 7cb5d979b40..484a10d77d1 100644 --- a/test/jasmine/tests/gl3d_plot_interact_test.js +++ b/test/jasmine/tests/gl3d_plot_interact_test.js @@ -1000,21 +1000,25 @@ describe('Test gl3d drag and wheel interactions', function() { } }; + var newPlot = function(fig) { + return Plotly.newPlot(gd, fig).then(function() { + relayoutCallback = jasmine.createSpy('relayoutCallback'); + gd.on('plotly_relayout', relayoutCallback); + + sceneLayout = gd._fullLayout.scene; + sceneLayout2 = gd._fullLayout.scene2; + sceneTarget = gd.querySelector('.svg-container .gl-container #scene canvas'); + sceneTarget2 = gd.querySelector('.svg-container .gl-container #scene2 canvas'); + }); + }; + function _assertAndReset(cnt) { expect(relayoutCallback).toHaveBeenCalledTimes(cnt); relayoutCallback.calls.reset(); } - Plotly.plot(gd, mock) + newPlot(mock) .then(function() { - relayoutCallback = jasmine.createSpy('relayoutCallback'); - gd.on('plotly_relayout', relayoutCallback); - - sceneLayout = gd._fullLayout.scene; - sceneLayout2 = gd._fullLayout.scene2; - sceneTarget = gd.querySelector('.svg-container .gl-container #scene canvas'); - sceneTarget2 = gd.querySelector('.svg-container .gl-container #scene2 canvas'); - expect(sceneLayout.camera.eye) .toEqual({x: 0.1, y: 0.1, z: 1}); expect(sceneLayout2.camera.eye) @@ -1067,7 +1071,11 @@ describe('Test gl3d drag and wheel interactions', function() { .then(function() { _assertAndReset(1); - return Plotly.plot(gd, [], {}, {scrollZoom: false}); + return newPlot({ + data: gd.data, + layout: gd.layout, + config: {scrollZoom: false} + }); }) .then(function() { _assertAndReset(0); @@ -1081,7 +1089,11 @@ describe('Test gl3d drag and wheel interactions', function() { }) .then(function() { _assertAndReset(0); - return Plotly.plot(gd, [], {}, {scrollZoom: 'gl3d'}); + return newPlot({ + data: gd.data, + layout: gd.layout, + config: {scrollZoom: 'gl3d'} + }); }) .then(function() { _assertAndReset(0); @@ -1113,21 +1125,25 @@ describe('Test gl3d drag and wheel interactions', function() { } }; + var newPlot = function(fig) { + return Plotly.newPlot(gd, fig).then(function() { + relayoutCallback = jasmine.createSpy('relayoutCallback'); + gd.on('plotly_relayout', relayoutCallback); + + sceneLayout = gd._fullLayout.scene; + sceneLayout2 = gd._fullLayout.scene2; + sceneTarget = gd.querySelector('.svg-container .gl-container #scene canvas'); + sceneTarget2 = gd.querySelector('.svg-container .gl-container #scene2 canvas'); + }); + }; + function _assertAndReset(cnt) { expect(relayoutCallback).toHaveBeenCalledTimes(cnt); relayoutCallback.calls.reset(); } - Plotly.plot(gd, mock) + newPlot(mock) .then(function() { - relayoutCallback = jasmine.createSpy('relayoutCallback'); - gd.on('plotly_relayout', relayoutCallback); - - sceneLayout = gd._fullLayout.scene; - sceneLayout2 = gd._fullLayout.scene2; - sceneTarget = gd.querySelector('.svg-container .gl-container #scene canvas'); - sceneTarget2 = gd.querySelector('.svg-container .gl-container #scene2 canvas'); - expect(sceneLayout.camera.eye) .toEqual({x: 0.1, y: 0.1, z: 1}); expect(sceneLayout2.camera.eye) @@ -1180,7 +1196,11 @@ describe('Test gl3d drag and wheel interactions', function() { .then(function() { _assertAndReset(1); - return Plotly.plot(gd, [], {}, {scrollZoom: false}); + return newPlot({ + data: gd.data, + layout: gd.layout, + config: {scrollZoom: false} + }); }) .then(function() { _assertAndReset(0); @@ -1194,7 +1214,11 @@ describe('Test gl3d drag and wheel interactions', function() { }) .then(function() { _assertAndReset(0); - return Plotly.plot(gd, [], {}, {scrollZoom: 'gl3d'}); + return newPlot({ + data: gd.data, + layout: gd.layout, + config: {scrollZoom: 'gl3d'} + }); }) .then(function() { return scroll(sceneTarget); @@ -1229,17 +1253,20 @@ describe('Test gl3d drag and wheel interactions', function() { var relayoutCnt = 0; var modeBar; - Plotly.plot(gd, mock) + var newPlot = function(fig) { + return Plotly.newPlot(gd, fig).then(function() { + gd.on('plotly_relayout', function(e) { + relayoutCnt++; + relayoutEvent = e; + }); + }); + }; + newPlot(mock) .then(function() { modeBar = gd._fullLayout._modeBar; }) .then(function() { - gd.on('plotly_relayout', function(e) { - relayoutCnt++; - relayoutEvent = e; - }); - sceneLayout = gd._fullLayout.scene; sceneLayout2 = gd._fullLayout.scene2; sceneTarget = gd.querySelector('.svg-container .gl-container #scene canvas'); diff --git a/test/jasmine/tests/legend_test.js b/test/jasmine/tests/legend_test.js index fd5e32ac1c8..3ae8bf32fae 100644 --- a/test/jasmine/tests/legend_test.js +++ b/test/jasmine/tests/legend_test.js @@ -1975,6 +1975,12 @@ describe('legend with custom doubleClickDelay', function() { var clickCnt = 0; var dblClickCnt = 0; + var newPlot = function(fig) { + return Plotly.newPlot(gd, fig).then(function() { + gd.on('plotly_legendclick', function() { clickCnt++; }); + gd.on('plotly_legenddoubleclick', function() { dblClickCnt++; }); + }); + }; function _assert(msg, _clickCnt, _dblClickCnt) { return function() { @@ -1985,15 +1991,15 @@ describe('legend with custom doubleClickDelay', function() { }; } - Plotly.newPlot(gd, [ - {y: [1, 2, 1]}, - {y: [2, 1, 2]} - ], {}, { - doubleClickDelay: tLong - }) - .then(function() { - gd.on('plotly_legendclick', function() { clickCnt++; }); - gd.on('plotly_legenddoubleclick', function() { dblClickCnt++; }); + newPlot({ + data: [ + {y: [1, 2, 1]}, + {y: [2, 1, 2]} + ], + layout: {}, + config: { + doubleClickDelay: tLong + } }) .then(click(0)).then(delay(tLong / 2)) .then(_assert('[long] after click + (t/2) delay', 1, 0)) @@ -2005,7 +2011,11 @@ describe('legend with custom doubleClickDelay', function() { .then(_assert('[long] after click + (1.1*t) delay + click', 2, 0)) .then(delay(tLong + 10)) .then(function() { - return Plotly.plot(gd, [], {}, {doubleClickDelay: tShort}); + return newPlot({ + data: gd.data, + layout: gd.layout, + config: {doubleClickDelay: tShort} + }); }) .then(click(0)).then(delay(tShort / 2)) .then(_assert('[short] after click + (t/2) delay', 1, 0)) diff --git a/test/jasmine/tests/localize_test.js b/test/jasmine/tests/localize_test.js index 9591dbb8f4a..256f0ae078f 100644 --- a/test/jasmine/tests/localize_test.js +++ b/test/jasmine/tests/localize_test.js @@ -387,7 +387,7 @@ describe('localization', function() { expect(getZoomTip()).toBe('Bigger'); // this is discouraged usage, but it works - return Plotly.plot(gd, [], {}, {locale: 'en'}); + return Plotly.newPlot(gd, gd.data, gd.layout, {locale: 'en'}); }) .then(function() { expect(firstXLabel()).toBe('Jan 2001'); diff --git a/test/jasmine/tests/mapbox_test.js b/test/jasmine/tests/mapbox_test.js index be1a9d5ac95..bb6aee219e7 100644 --- a/test/jasmine/tests/mapbox_test.js +++ b/test/jasmine/tests/mapbox_test.js @@ -1413,7 +1413,9 @@ describe('mapbox plots', function() { mockCopy2.config = {scrollZoom: false}; var relayoutCnt = 0; - gd.on('plotly_relayout', function() { relayoutCnt++; }); + var addOnGd = function() { + gd.on('plotly_relayout', function() { relayoutCnt++; }); + }; function _scroll() { relayoutCnt = 0; @@ -1428,6 +1430,8 @@ describe('mapbox plots', function() { expect(zoom).toBeCloseTo(1.234); var zoom0 = zoom; + addOnGd(); + _scroll().then(function() { expect(relayoutCnt).toBe(1, 'scroll relayout cnt'); @@ -1435,7 +1439,8 @@ describe('mapbox plots', function() { expect(zoomNew).toBeGreaterThan(zoom); zoom = zoomNew; }) - .then(function() { return Plotly.plot(gd, [], {}, {scrollZoom: false}); }) + .then(function() { return Plotly.newPlot(gd, gd.data, gd.layout, {scrollZoom: false}); }) + .then(addOnGd) .then(_scroll) .then(function() { expect(relayoutCnt).toBe(0, 'no additional relayout call'); @@ -1444,7 +1449,8 @@ describe('mapbox plots', function() { expect(zoomNew).toBe(zoom); zoom = zoomNew; }) - .then(function() { return Plotly.plot(gd, [], {}, {scrollZoom: true}); }) + .then(function() { return Plotly.newPlot(gd, gd.data, gd.layout, {scrollZoom: true}); }) + .then(addOnGd) .then(_scroll) .then(function() { expect(relayoutCnt).toBe(1, 'scroll relayout cnt'); @@ -1453,6 +1459,7 @@ describe('mapbox plots', function() { expect(zoomNew).toBeGreaterThan(zoom); }) .then(function() { return Plotly.newPlot(gd, mockCopy2); }) + .then(addOnGd) .then(_scroll) .then(function() { // see https://github.com/plotly/plotly.js/issues/3738 diff --git a/test/jasmine/tests/parcoords_test.js b/test/jasmine/tests/parcoords_test.js index bf35d2b914e..d898b6cf8cf 100644 --- a/test/jasmine/tests/parcoords_test.js +++ b/test/jasmine/tests/parcoords_test.js @@ -538,7 +538,7 @@ describe('parcoords edge cases', function() { mockCopy.data[0].dimensions[i] = newDimension; } - Plotly.plot(gd, mockCopy).then(function() { + Plotly.newPlot(gd, mockCopy).then(function() { expect(gd.data.length).toEqual(1); expect(gd.data[0].dimensions.length).toEqual(60); expect(document.querySelectorAll('.axis').length).toEqual(60); @@ -565,7 +565,7 @@ describe('parcoords edge cases', function() { mockCopy.data[0].dimensions[i] = newDimension; } - Plotly.plot(gd, mockCopy).then(function() { + Plotly.newPlot(gd, mockCopy).then(function() { expect(gd.data.length).toEqual(1); expect(gd.data[0].dimensions.length).toEqual(60); expect(document.querySelectorAll('.axis').length).toEqual(60); diff --git a/test/jasmine/tests/plot_promise_test.js b/test/jasmine/tests/plot_promise_test.js index b032f4e6ac8..437cc96e94e 100644 --- a/test/jasmine/tests/plot_promise_test.js +++ b/test/jasmine/tests/plot_promise_test.js @@ -70,7 +70,7 @@ describe('Plotly.___ methods', function() { var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; var initialDiv = createGraphDiv(); - Plotly.plot(initialDiv, data, {}); + Plotly.newPlot(initialDiv, data, {}); promise = Plotly.redraw(initialDiv); @@ -119,7 +119,7 @@ describe('Plotly.___ methods', function() { var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; var initialDiv = createGraphDiv(); - Plotly.plot(initialDiv, data, {}); + Plotly.newPlot(initialDiv, data, {}); promise = Plotly.extendTraces(initialDiv, { y: [[2]] }, [0], 3); @@ -145,7 +145,7 @@ describe('Plotly.___ methods', function() { var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; var initialDiv = createGraphDiv(); - Plotly.plot(initialDiv, data, {}); + Plotly.newPlot(initialDiv, data, {}); promise = Plotly.prependTraces(initialDiv, { y: [[2]] }, [0], 3); @@ -171,7 +171,7 @@ describe('Plotly.___ methods', function() { var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; var initialDiv = createGraphDiv(); - Plotly.plot(initialDiv, data, {}); + Plotly.newPlot(initialDiv, data, {}); promise = Plotly.addTraces(initialDiv, [{ x: [1, 2, 3], y: [1, 2, 3] }], [1]); @@ -197,7 +197,7 @@ describe('Plotly.___ methods', function() { var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; var initialDiv = createGraphDiv(); - Plotly.plot(initialDiv, data, {}); + Plotly.newPlot(initialDiv, data, {}); promise = Plotly.deleteTraces(initialDiv, [0]); @@ -223,7 +223,7 @@ describe('Plotly.___ methods', function() { var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; var initialDiv = createGraphDiv(); - Plotly.plot(initialDiv, data, {}); + Plotly.newPlot(initialDiv, data, {}); promise = Plotly.deleteTraces(initialDiv, [0]); @@ -252,7 +252,7 @@ describe('Plotly.___ methods', function() { ]; var initialDiv = createGraphDiv(); - Plotly.plot(initialDiv, data, {}); + Plotly.newPlot(initialDiv, data, {}); promise = Plotly.moveTraces(initialDiv, 0, 1); @@ -278,7 +278,7 @@ describe('Plotly.___ methods', function() { var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; var initialDiv = createGraphDiv(); - Plotly.plot(initialDiv, data, {}); + Plotly.newPlot(initialDiv, data, {}); promise = Plotly.restyle(initialDiv, 'marker.color', 'rgb(255,0,0)'); @@ -304,7 +304,7 @@ describe('Plotly.___ methods', function() { var data = [{ x: [1, 2, 3], y: [4, 5, 6] }]; var initialDiv = createGraphDiv(); - Plotly.plot(initialDiv, data, {}); + Plotly.newPlot(initialDiv, data, {}); promise = Plotly.restyle(initialDiv, undefined, ''); @@ -328,7 +328,7 @@ describe('Plotly.___ methods', function() { var layout = {hovermode: 'closest'}; var initialDiv = createGraphDiv(); - Plotly.plot(initialDiv, data, layout); + Plotly.newPlot(initialDiv, data, layout); promise = Plotly.relayout(initialDiv, 'hovermode', false); @@ -355,7 +355,7 @@ describe('Plotly.___ methods', function() { var layout = {hovermode: 'closest'}; var initialDiv = createGraphDiv(); - Plotly.plot(initialDiv, data, layout); + Plotly.newPlot(initialDiv, data, layout); promise = Plotly.relayout(initialDiv, 'hovermode', false); @@ -382,7 +382,7 @@ describe('Plotly.___ methods', function() { var layout = {hovermode: 'closest'}; var initialDiv = createGraphDiv(); - Plotly.plot(initialDiv, data, layout); + Plotly.newPlot(initialDiv, data, layout); initialDiv.framework = { isPolar: true }; promise = Plotly.relayout(initialDiv, 'hovermode', false); @@ -409,7 +409,7 @@ describe('Plotly.___ methods', function() { var layout = {hovermode: 'closest'}; var initialDiv = createGraphDiv(); - Plotly.plot(initialDiv, data, layout); + Plotly.newPlot(initialDiv, data, layout); promise = Plotly.relayout(initialDiv, undefined, false); @@ -432,7 +432,7 @@ describe('Plotly.___ methods', function() { initialDiv = createGraphDiv(); - Plotly.plot(initialDiv, data, {}).then(done); + Plotly.newPlot(initialDiv, data, {}).then(done); }); afterEach(destroyGraphDiv); From 17939fe972110177c993bd654f900af5629fd0de Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 11 Jan 2021 12:33:59 -0500 Subject: [PATCH 2/4] increase jasmine timout interval in some gl tests to pass on CI --- test/jasmine/tests/gl3d_plot_interact_test.js | 2 +- test/jasmine/tests/parcoords_test.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/jasmine/tests/gl3d_plot_interact_test.js b/test/jasmine/tests/gl3d_plot_interact_test.js index 484a10d77d1..3099e7f9b2f 100644 --- a/test/jasmine/tests/gl3d_plot_interact_test.js +++ b/test/jasmine/tests/gl3d_plot_interact_test.js @@ -935,7 +935,7 @@ describe('Test gl3d drag and wheel interactions', function() { beforeEach(function() { gd = createGraphDiv(); - jasmine.DEFAULT_TIMEOUT_INTERVAL = 6000; + jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; }); afterEach(function() { diff --git a/test/jasmine/tests/parcoords_test.js b/test/jasmine/tests/parcoords_test.js index d898b6cf8cf..742d9de0624 100644 --- a/test/jasmine/tests/parcoords_test.js +++ b/test/jasmine/tests/parcoords_test.js @@ -365,6 +365,8 @@ describe('parcoords initialization tests', function() { describe('parcoords edge cases', function() { var gd; beforeEach(function() { + jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; + gd = createGraphDiv(); }); From bcb0ce9ea8f9dc4458988f3b1fa5887decea1e39 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 11 Jan 2021 13:30:57 -0500 Subject: [PATCH 3/4] add plotly_hover before calling hover in heatmap and contour tests --- test/jasmine/tests/contour_test.js | 4 ++-- test/jasmine/tests/heatmap_test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/jasmine/tests/contour_test.js b/test/jasmine/tests/contour_test.js index b45ef59088b..208c2f7cde0 100644 --- a/test/jasmine/tests/contour_test.js +++ b/test/jasmine/tests/contour_test.js @@ -639,13 +639,13 @@ describe('contour hover', function() { afterAll(destroyGraphDiv); it('should not display hover on missing data and hoverongaps is disabled', function() { - var pt = _hover(gd, 10, 100)[0]; - var hoverData; gd.on('plotly_hover', function(data) { hoverData = data; }); + var pt = _hover(gd, 10, 100)[0]; + expect(hoverData).toEqual(undefined); expect(pt).toEqual(undefined); }); diff --git a/test/jasmine/tests/heatmap_test.js b/test/jasmine/tests/heatmap_test.js index 46614b53dca..43a44304931 100644 --- a/test/jasmine/tests/heatmap_test.js +++ b/test/jasmine/tests/heatmap_test.js @@ -989,13 +989,13 @@ describe('heatmap hover', function() { afterAll(destroyGraphDiv); it('should not display hover on missing data and hoverongaps is disabled', function() { - var pt = _hover(gd, 10, 100)[0]; - var hoverData; gd.on('plotly_hover', function(data) { hoverData = data; }); + var pt = _hover(gd, 10, 100)[0]; + expect(hoverData).toEqual(undefined); expect(pt).toEqual(undefined); }); From 981cc40fe02469db4bfa2ffe3de8122401733aff Mon Sep 17 00:00:00 2001 From: archmoj Date: Tue, 12 Jan 2021 09:48:41 -0500 Subject: [PATCH 4/4] use react in geo test when calc data used to be set to undefined --- test/jasmine/tests/geo_test.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/jasmine/tests/geo_test.js b/test/jasmine/tests/geo_test.js index d83ace42a66..4090b17327d 100644 --- a/test/jasmine/tests/geo_test.js +++ b/test/jasmine/tests/geo_test.js @@ -1215,8 +1215,8 @@ describe('Test geo interactions', function() { done(); } - gd.calcdata = undefined; - Plotly.newPlot(gd, gd.data, gd.layout); + gd.layout.datarevision = String(i); + Plotly.react(gd, gd.data, gd.layout); i++; }, INTERVAL); }); @@ -1246,8 +1246,8 @@ describe('Test geo interactions', function() { done(); } - gd.calcdata = undefined; - Plotly.newPlot(gd, gd.data, gd.layout); + gd.layout.datarevision = String(i); + Plotly.react(gd, gd.data, gd.layout); i++; }, INTERVAL); }); @@ -1277,8 +1277,8 @@ describe('Test geo interactions', function() { done(); } - gd.calcdata = undefined; - Plotly.newPlot(gd, gd.data, gd.layout); + gd.layout.datarevision = String(i); + Plotly.react(gd, gd.data, gd.layout); i++; }, INTERVAL); }); @@ -1292,8 +1292,8 @@ describe('Test geo interactions', function() { var trace1 = gd.data[1]; trace1.locations.shift(); - gd.calcdata = undefined; - Plotly.newPlot(gd, gd.data, gd.layout) + gd.layout.datarevision = '0'; + Plotly.react(gd, gd.data, gd.layout) .then(function() { expect(countTraces('scattergeo')).toBe(1); expect(countTraces('choropleth')).toBe(1); @@ -1319,8 +1319,8 @@ describe('Test geo interactions', function() { trace1.locations = locationsQueue; trace1.z = zQueue; - gd.calcdata = undefined; - Plotly.newPlot(gd, gd.data, gd.layout) + gd.layout.datarevision = '0'; + Plotly.react(gd, gd.data, gd.layout) .then(function() { expect(countTraces('scattergeo')).toBe(1); expect(countTraces('choropleth')).toBe(1);