diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 4c24b172103..2620d231d88 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -356,7 +356,7 @@ Plotly.plot = function(gd, data, layout, config) { // even if everything we did was synchronous, return a promise // so that the caller doesn't care which route we took return (donePlotting && donePlotting.then) ? - donePlotting : Promise.resolve(); + donePlotting : Promise.resolve(gd); }; // Get the container div: we store all variables for this plot as @@ -926,6 +926,7 @@ Plotly.redraw = function(gd) { gd.calcdata = undefined; return Plotly.plot(gd).then(function () { gd.emit('plotly_redraw'); + return gd; }); }; @@ -1361,12 +1362,14 @@ Plotly.extendTraces = function extendTraces (gd, update, indices, maxPoints) { return target.splice(0, target.length - maxPoints); }); - Plotly.redraw(gd); + var promise = Plotly.redraw(gd); var undoArgs = [gd, undo.update, indices, undo.maxPoints]; if (Plotly.Queue) { Plotly.Queue.add(gd, Plotly.prependTraces, undoArgs, extendTraces, arguments); } + + return promise; }; Plotly.prependTraces = function prependTraces (gd, update, indices, maxPoints) { @@ -1388,12 +1391,14 @@ Plotly.prependTraces = function prependTraces (gd, update, indices, maxPoints) return target.splice(maxPoints, target.length); }); - Plotly.redraw(gd); + var promise = Plotly.redraw(gd); var undoArgs = [gd, undo.update, indices, undo.maxPoints]; if (Plotly.Queue) { Plotly.Queue.add(gd, Plotly.extendTraces, undoArgs, prependTraces, arguments); } + + return promise; }; /** @@ -1436,9 +1441,9 @@ Plotly.addTraces = function addTraces (gd, traces, newIndices) { // if the user didn't define newIndices, they just want the traces appended // i.e., we can simply redraw and be done if (typeof newIndices === 'undefined') { - Plotly.redraw(gd); + var promise = Plotly.redraw(gd); if (Plotly.Queue) Plotly.Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs); - return; + return promise; } // make sure indices is property defined @@ -1462,8 +1467,9 @@ Plotly.addTraces = function addTraces (gd, traces, newIndices) { // this requires some extra work that moveTraces will do if (Plotly.Queue) Plotly.Queue.startSequence(gd); if (Plotly.Queue) Plotly.Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs); - Plotly.moveTraces(gd, currentIndices, newIndices); + var promise = Plotly.moveTraces(gd, currentIndices, newIndices); if (Plotly.Queue) Plotly.Queue.stopSequence(gd); + return promise; }; /** @@ -1502,9 +1508,11 @@ Plotly.deleteTraces = function deleteTraces (gd, indices) { traces.push(deletedTrace); } - Plotly.redraw(gd); + var promise = Plotly.redraw(gd); if (Plotly.Queue) Plotly.Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs); + + return promise; }; /** @@ -1599,9 +1607,11 @@ Plotly.moveTraces = function moveTraces (gd, currentIndices, newIndices) { gd.data = newData; - Plotly.redraw(gd); + var promise = Plotly.redraw(gd); if (Plotly.Queue) Plotly.Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs); + + return promise; }; // ----------------------------------------------------- @@ -1640,7 +1650,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { } else { console.log('restyle fail',astr,val,traces); - return; + return new Promise.reject(); } if(Object.keys(aobj).length) gd.changed = true; @@ -2115,8 +2125,8 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { if(!plotDone || !plotDone.then) plotDone = Promise.resolve(); return plotDone.then(function() { - gd.emit('plotly_restyle', - Plotly.Lib.extendDeep([], [redoit, traces])); + gd.emit('plotly_restyle', Plotly.Lib.extendDeep([], [redoit, traces])); + return gd; }); }; @@ -2161,7 +2171,9 @@ function swapXYData(trace) { Plotly.relayout = function relayout(gd, astr, val) { gd = getGraphDiv(gd); - if(gd.framework && gd.framework.isPolar) return; + if(gd.framework && gd.framework.isPolar) { + return new Promise.resolve(gd); + } var layout = gd.layout, fullLayout = gd._fullLayout, @@ -2178,7 +2190,7 @@ Plotly.relayout = function relayout(gd, astr, val) { else if(Plotly.Lib.isPlainObject(astr)) aobj = astr; else { console.log('relayout fail',astr,val); - return; + return new Promise.reject(); } if(Object.keys(aobj).length) gd.changed = true; @@ -2484,11 +2496,12 @@ Plotly.relayout = function relayout(gd, astr, val) { var plotDone = Plotly.Lib.syncOrAsync(seq, gd); - if(!plotDone || !plotDone.then) plotDone = Promise.resolve(); + if(!plotDone || !plotDone.then) plotDone = Promise.resolve(gd); return plotDone.then(function() { gd.emit('plotly_relayout', Plotly.Lib.extendDeep({}, redoit)); + return gd; }); }; diff --git a/test/jasmine/tests/plot_api_test.js b/test/jasmine/tests/plot_api_test.js index b9a5e5141a3..68ff9cd1e02 100644 --- a/test/jasmine/tests/plot_api_test.js +++ b/test/jasmine/tests/plot_api_test.js @@ -51,7 +51,7 @@ describe('Test graph_obj', function () { }); - describe('Plotly.deleteTraces should', function () { + describe('Plotly.deleteTraces', function () { var gd; beforeEach(function () { @@ -63,11 +63,10 @@ describe('Test graph_obj', function () { {'name': 'd'} ] }; - Plotly.Queue = null; spyOn(Plotly, 'redraw'); }); - it('throw an error when indices are omitted', function () { + it('should throw an error when indices are omitted', function () { expect(function () { Plotly.deleteTraces(gd); @@ -75,7 +74,7 @@ describe('Test graph_obj', function () { }); - it('throw an error when indices are out of bounds', function () { + it('should throw an error when indices are out of bounds', function () { expect(function () { Plotly.deleteTraces(gd, 10); @@ -83,7 +82,7 @@ describe('Test graph_obj', function () { }); - it('throw an error when indices are repeated', function () { + it('should throw an error when indices are repeated', function () { expect(function () { Plotly.deleteTraces(gd, [0, 0]); @@ -91,52 +90,46 @@ describe('Test graph_obj', function () { }); - it('work when indices are negative', function () { - var expected = { - data: [ - {'name': 'a'}, - {'name': 'b'}, - {'name': 'c'} - ] - }; + it('should work when indices are negative', function () { + var expectedData = [ + {'name': 'a'}, + {'name': 'b'}, + {'name': 'c'} + ]; Plotly.deleteTraces(gd, -1); - expect(gd).toEqual(expected); + expect(gd.data).toEqual(expectedData); expect(Plotly.redraw).toHaveBeenCalled(); }); - it('work when multiple traces are deleted', function () { - var expected = { - data: [ - {'name': 'b'}, - {'name': 'c'} - ] - }; + it('should work when multiple traces are deleted', function () { + var expectedData = [ + {'name': 'b'}, + {'name': 'c'} + ]; Plotly.deleteTraces(gd, [0, 3]); - expect(gd).toEqual(expected); + expect(gd.data).toEqual(expectedData); expect(Plotly.redraw).toHaveBeenCalled(); }); - it('work when indices are not sorted', function () { - var expected = { - data: [ - {'name': 'b'}, - {'name': 'c'} - ] - }; + it('should work when indices are not sorted', function () { + var expectedData = [ + {'name': 'b'}, + {'name': 'c'} + ]; Plotly.deleteTraces(gd, [3, 0]); - expect(gd).toEqual(expected); + expect(gd.data).toEqual(expectedData); expect(Plotly.redraw).toHaveBeenCalled(); }); }); - describe('Plotly.addTraces should', function () { + describe('Plotly.addTraces', function () { var gd; beforeEach(function () { @@ -150,7 +143,7 @@ describe('Test graph_obj', function () { spyOn(Plotly, 'moveTraces'); }); - it('throw an error when traces is not an object or an array of objects', function () { + it('should throw an error when traces is not an object or an array of objects', function () { var expected = JSON.parse(JSON.stringify(gd)); expect(function () { Plotly.addTraces(gd, 1, 2); @@ -169,7 +162,7 @@ describe('Test graph_obj', function () { }); - it('throw an error when traces and newIndices arrays are unequal', function () { + it('should throw an error when traces and newIndices arrays are unequal', function () { expect(function () { Plotly.addTraces(gd, [{}, {}], 2); @@ -177,7 +170,7 @@ describe('Test graph_obj', function () { }); - it('throw an error when newIndices are out of bounds', function () { + it('should throw an error when newIndices are out of bounds', function () { var expected = JSON.parse(JSON.stringify(gd)); expect(function () { @@ -188,65 +181,60 @@ describe('Test graph_obj', function () { expect(gd).toEqual(expected); }); - it('work when newIndices is undefined', function () { - var expected = { - data: [ - {'name': 'a'}, - {'name': 'b'}, - {'name': 'c'}, - {'name': 'd'} - ] - }; + it('should work when newIndices is undefined', function () { + var expectedData = [ + {'name': 'a'}, + {'name': 'b'}, + {'name': 'c'}, + {'name': 'd'} + ]; Plotly.addTraces(gd, [{'name': 'c'}, {'name': 'd'}]); - expect(gd).toEqual(expected); + expect(gd.data).toEqual(expectedData); expect(Plotly.redraw).toHaveBeenCalled(); expect(Plotly.moveTraces).not.toHaveBeenCalled(); }); - it('work when newIndices is defined', function () { - var expected = { - data: [ - {'name': 'a'}, - {'name': 'b'}, - {'name': 'c'}, - {'name': 'd'} - ] - }; + it('should work when newIndices is defined', function () { + var expectedData = [ + {'name': 'a'}, + {'name': 'b'}, + {'name': 'c'}, + {'name': 'd'} + ]; + Plotly.addTraces(gd, [{'name': 'c'}, {'name': 'd'}], [1, 3]); - expect(gd).toEqual(expected); + expect(gd.data).toEqual(expectedData); expect(Plotly.redraw).not.toHaveBeenCalled(); expect(Plotly.moveTraces).toHaveBeenCalledWith(gd, [-2, -1], [1, 3]); }); - it('work when newIndices has negative indices', function () { - var expected = { - data: [ - {'name': 'a'}, - {'name': 'b'}, - {'name': 'c'}, - {'name': 'd'} - ] - }; + it('should work when newIndices has negative indices', function () { + var expectedData = [ + {'name': 'a'}, + {'name': 'b'}, + {'name': 'c'}, + {'name': 'd'} + ]; + Plotly.addTraces(gd, [{'name': 'c'}, {'name': 'd'}], [-3, -1]); - expect(gd).toEqual(expected); + expect(gd.data).toEqual(expectedData); expect(Plotly.redraw).not.toHaveBeenCalled(); expect(Plotly.moveTraces).toHaveBeenCalledWith(gd, [-2, -1], [-3, -1]); }); - it('work when newIndices is an integer', function () { - var expected = { - data: [ - {'name': 'a'}, - {'name': 'b'}, - {'name': 'c'} - ] - }; + it('should work when newIndices is an integer', function () { + var expectedData = [ + {'name': 'a'}, + {'name': 'b'}, + {'name': 'c'} + ]; + Plotly.addTraces(gd, {'name': 'c'}, 0); - expect(gd).toEqual(expected); + expect(gd.data).toEqual(expectedData); expect(Plotly.redraw).not.toHaveBeenCalled(); expect(Plotly.moveTraces).toHaveBeenCalledWith(gd, [-1], [0]); @@ -323,68 +311,64 @@ describe('Test graph_obj', function () { }); it('accept integers in place of arrays', function () { - var expected = { - data: [ - {'name': 'b'}, - {'name': 'a'}, - {'name': 'c'}, - {'name': 'd'} - ] - }; + var expectedData = [ + {'name': 'b'}, + {'name': 'a'}, + {'name': 'c'}, + {'name': 'd'} + ]; + Plotly.moveTraces(gd, 0, 1); - expect(gd).toEqual(expected); + expect(gd.data).toEqual(expectedData); expect(Plotly.redraw).toHaveBeenCalled(); }); it('handle unsorted currentIndices', function () { - var expected = { - data: [ - {'name': 'd'}, - {'name': 'a'}, - {'name': 'c'}, - {'name': 'b'} - ] - }; + var expectedData = [ + {'name': 'd'}, + {'name': 'a'}, + {'name': 'c'}, + {'name': 'b'} + ]; + Plotly.moveTraces(gd, [3, 1], [0, 3]); - expect(gd).toEqual(expected); + expect(gd.data).toEqual(expectedData); expect(Plotly.redraw).toHaveBeenCalled(); }); it('work when newIndices are undefined.', function () { - var expected = { - data: [ - {'name': 'b'}, - {'name': 'c'}, - {'name': 'd'}, - {'name': 'a'} - ] - }; + var expectedData = [ + {'name': 'b'}, + {'name': 'c'}, + {'name': 'd'}, + {'name': 'a'} + ]; + Plotly.moveTraces(gd, [3, 0]); - expect(gd).toEqual(expected); + expect(gd.data).toEqual(expectedData); expect(Plotly.redraw).toHaveBeenCalled(); }); it('accept negative indices.', function () { - var expected = { - data: [ - {'name': 'a'}, - {'name': 'c'}, - {'name': 'b'}, - {'name': 'd'} - ] - }; + var expectedData = [ + {'name': 'a'}, + {'name': 'c'}, + {'name': 'b'}, + {'name': 'd'} + ]; + Plotly.moveTraces(gd, 1, -2); - expect(gd).toEqual(expected); + expect(gd.data).toEqual(expectedData); expect(Plotly.redraw).toHaveBeenCalled(); }); }); - describe('Plotly.ExtendTraces should', function() { + describe('Plotly.ExtendTraces', function() { var gd; beforeEach(function () { gd = { @@ -406,7 +390,7 @@ describe('Test graph_obj', function () { spyOn(Plotly.Queue, 'add'); }); - it('throw an error when gd.data isn\'t an array.', function () { + it('should throw an error when gd.data isn\'t an array.', function () { expect(function () { Plotly.extendTraces({}, {x: [[1]]}, [0]); @@ -418,7 +402,7 @@ describe('Test graph_obj', function () { }); - it('throw an error when update is not an object', function () { + it('should throw an error when update is not an object', function () { expect(function () { Plotly.extendTraces(gd, undefined, [0], 8); @@ -431,7 +415,7 @@ describe('Test graph_obj', function () { }); - it('throw an error when indices are omitted', function () { + it('should throw an error when indices are omitted', function () { expect(function () { Plotly.extendTraces(gd, {x: [[1]]}); @@ -439,7 +423,7 @@ describe('Test graph_obj', function () { }); - it('thow an error when a current index is out of bounds', function () { + it('should thow an error when a current index is out of bounds', function () { expect(function () { Plotly.extendTraces(gd, {x: [[1]]}, [-gd.data.length - 1]); @@ -447,7 +431,7 @@ describe('Test graph_obj', function () { }); - it('not thow an error when negative index wraps to positive', function () { + it('should not thow an error when negative index wraps to positive', function () { expect(function () { Plotly.extendTraces(gd, {x: [[1]]}, [-1]); @@ -455,7 +439,7 @@ describe('Test graph_obj', function () { }); - it('thow an error when number of Indices does not match Update arrays', function () { + it('should thow an error when number of Indices does not match Update arrays', function () { expect(function () { Plotly.extendTraces(gd, {x: [[1, 2], [2, 3]] }, [0]); @@ -467,7 +451,7 @@ describe('Test graph_obj', function () { }); - it('thow an error when maxPoints is an Object but does not match Update', function () { + it('should thow an error when maxPoints is an Object but does not match Update', function () { expect(function () { Plotly.extendTraces(gd, {x: [[1]]}, [0], {y: [1]}); @@ -481,7 +465,7 @@ describe('Test graph_obj', function () { }); - it('throw an error when update keys mismatch trace keys', function () { + it('should throw an error when update keys mismatch trace keys', function () { // lets update y on both traces, but only 1 trace has "y" gd.data[1].y = [1,2,3]; @@ -494,7 +478,7 @@ describe('Test graph_obj', function () { }); - it('extend traces with update keys', function () { + it('should extend traces with update keys', function () { Plotly.extendTraces(gd, { x: [[3, 4], [4, 5]], 'marker.size': [[0, -1], [5, 6]] @@ -508,7 +492,7 @@ describe('Test graph_obj', function () { expect(Plotly.redraw).toHaveBeenCalled(); }); - it('extend and window traces with update keys', function () { + it('should extend and window traces with update keys', function () { var maxPoints = 3; Plotly.extendTraces(gd, { @@ -521,7 +505,7 @@ describe('Test graph_obj', function () { ]); }); - it('extend and window traces with update keys', function () { + it('should extend and window traces with update keys', function () { var maxPoints = 3; Plotly.extendTraces(gd, { @@ -534,7 +518,7 @@ describe('Test graph_obj', function () { ]); }); - it('extend and window traces using full maxPoint object', function () { + it('should extend and window traces using full maxPoint object', function () { var maxPoints = {x: [2, 3], 'marker.size': [1, 2]}; Plotly.extendTraces(gd, { @@ -547,7 +531,7 @@ describe('Test graph_obj', function () { ]); }); - it('truncates arrays when maxPoints is zero', function () { + it('should truncate arrays when maxPoints is zero', function () { Plotly.extendTraces(gd, { x: [[3, 4], [4, 5]], 'marker.size': [[0, -1], [5, 6]] @@ -614,7 +598,5 @@ describe('Test graph_obj', function () { expect(gd.data).toEqual(cachedData); }); - }); - }); diff --git a/test/jasmine/tests/plot_promise_test.js b/test/jasmine/tests/plot_promise_test.js new file mode 100644 index 00000000000..a25dbaf0914 --- /dev/null +++ b/test/jasmine/tests/plot_promise_test.js @@ -0,0 +1,303 @@ +var Plotly = require('@src/plotly'); +var createGraphDiv = require('../assets/create_graph_div'); +var destroyGraphDiv = require('../assets/destroy_graph_div'); + +describe('Plotly.___ methods', function () { + 'use strict'; + + describe('Plotly.plot promise', function () { + var promise, + promiseGd; + + beforeEach(function (done) { + + var data = [{ x: [1,2,3], y: [4,5,6] }], + + promise = Plotly.plot(createGraphDiv(), data, {}); + + promise.then(function(gd){ + promiseGd = gd; + done(); + }); + }); + afterEach(destroyGraphDiv); + + it('should be returned with the graph div as an argument', function () { + expect(promiseGd).toBeDefined(); + expect(typeof promiseGd).toBe('object'); + expect(promiseGd.data).toBeDefined(); + expect(promiseGd.layout).toBeDefined(); + }); + }); + + describe('Plotly.redraw promise', function () { + var promise, + promiseGd; + + beforeEach(function (done) { + var data = [{ x: [1,2,3], y: [4,5,6] }], + initialDiv = createGraphDiv(); + + Plotly.plot(initialDiv, data, {}); + + promise = Plotly.redraw(initialDiv); + + promise.then(function(gd){ + promiseGd = gd; + done(); + }); + }); + afterEach(destroyGraphDiv); + + it('should be returned with the graph div as an argument', function () { + expect(promiseGd).toBeDefined(); + expect(typeof promiseGd).toBe('object'); + expect(promiseGd.data).toBeDefined(); + expect(promiseGd.layout).toBeDefined(); + }); + }); + + describe('Plotly.newPlot promise', function () { + var promise, + promiseGd; + + beforeEach(function (done) { + var data = [{ x: [1,2,3], y: [4,5,6] }], + + promise = Plotly.newPlot(createGraphDiv(), data, {}); + + promise.then(function(gd){ + promiseGd = gd; + done(); + }); + }); + afterEach(destroyGraphDiv); + + it('should be returned with the graph div as an argument', function () { + expect(promiseGd).toBeDefined(); + expect(typeof promiseGd).toBe('object'); + expect(promiseGd.data).toBeDefined(); + expect(promiseGd.layout).toBeDefined(); + }); + }); + + describe('Plotly.extendTraces promise', function () { + var promise, + promiseGd; + + beforeEach(function (done) { + var data = [{ x: [1,2,3], y: [4,5,6] }], + initialDiv = createGraphDiv(); + + Plotly.plot(initialDiv, data, {}); + + promise = Plotly.extendTraces(initialDiv, { y: [[2]] }, [0], 3); + + promise.then(function(gd){ + promiseGd = gd; + done(); + }); + }); + afterEach(destroyGraphDiv); + + it('should be returned with the graph div as an argument', function () { + expect(promiseGd).toBeDefined(); + expect(typeof promiseGd).toBe('object'); + expect(promiseGd.data).toBeDefined(); + expect(promiseGd.layout).toBeDefined(); + }); + }); + + describe('Plotly.prependTraces promise', function () { + var promise, + promiseGd; + + beforeEach(function (done) { + var data = [{ x: [1,2,3], y: [4,5,6] }], + initialDiv = createGraphDiv(); + + Plotly.plot(initialDiv, data, {}); + + promise = Plotly.prependTraces(initialDiv, { y: [[2]] }, [0], 3); + + promise.then(function(gd){ + promiseGd = gd; + done(); + }); + }); + afterEach(destroyGraphDiv); + + it('should be returned with the graph div as an argument', function () { + expect(promiseGd).toBeDefined(); + expect(typeof promiseGd).toBe('object'); + expect(promiseGd.data).toBeDefined(); + expect(promiseGd.layout).toBeDefined(); + }); + }); + + describe('Plotly.addTraces promise', function () { + var promise, + promiseGd; + + beforeEach(function (done) { + var data = [{ x: [1,2,3], y: [4,5,6] }], + initialDiv = createGraphDiv(); + + Plotly.plot(initialDiv, data, {}); + + promise = Plotly.addTraces(initialDiv, [{ x: [1,2,3], y: [1,2,3] }], [1]); + + promise.then(function(gd){ + promiseGd = gd; + done(); + }); + }); + afterEach(destroyGraphDiv); + + it('should be returned with the graph div as an argument', function () { + expect(promiseGd).toBeDefined(); + expect(typeof promiseGd).toBe('object'); + expect(promiseGd.data).toBeDefined(); + expect(promiseGd.layout).toBeDefined(); + }); + }); + + describe('Plotly.deleteTraces promise', function () { + var promise, + promiseGd; + + beforeEach(function (done) { + var data = [{ x: [1,2,3], y: [4,5,6] }], + initialDiv = createGraphDiv(); + + Plotly.plot(initialDiv, data, {}); + + promise = Plotly.deleteTraces(initialDiv, [0]); + + promise.then(function(gd){ + promiseGd = gd; + done(); + }); + }); + afterEach(destroyGraphDiv); + + it('should be returned with the graph div as an argument', function () { + expect(promiseGd).toBeDefined(); + expect(typeof promiseGd).toBe('object'); + expect(promiseGd.data).toBeDefined(); + expect(promiseGd.layout).toBeDefined(); + }); + }); + + describe('Plotly.deleteTraces promise', function () { + var promise, + promiseGd; + + beforeEach(function (done) { + var data = [{ x: [1,2,3], y: [4,5,6] }], + initialDiv = createGraphDiv(); + + Plotly.plot(initialDiv, data, {}); + + promise = Plotly.deleteTraces(initialDiv, [0]); + + promise.then(function(gd){ + promiseGd = gd; + done(); + }); + }); + afterEach(destroyGraphDiv); + + it('should be returned with the graph div as an argument', function () { + expect(promiseGd).toBeDefined(); + expect(typeof promiseGd).toBe('object'); + expect(promiseGd.data).toBeDefined(); + expect(promiseGd.layout).toBeDefined(); + }); + }); + + describe('Plotly.moveTraces promise', function () { + var promise, + promiseGd; + + beforeEach(function (done) { + var data = [ + { x: [1,2,3], y: [4,5,6] }, + { x: [1,2,3], y: [6,5,4] } + ], + initialDiv = createGraphDiv(); + + Plotly.plot(initialDiv, data, {}); + + promise = Plotly.moveTraces(initialDiv, 0, 1); + + promise.then(function(gd){ + promiseGd = gd; + done(); + }); + }); + afterEach(destroyGraphDiv); + + it('should be returned with the graph div as an argument', function () { + expect(promiseGd).toBeDefined(); + expect(typeof promiseGd).toBe('object'); + expect(promiseGd.data).toBeDefined(); + expect(promiseGd.layout).toBeDefined(); + }); + }); + + describe('Plotly.restyle promise', function () { + var promise, + promiseGd; + + beforeEach(function (done) { + var data = [{ x: [1,2,3], y: [4,5,6] }], + initialDiv = createGraphDiv(); + + Plotly.plot(initialDiv, data, {}); + + promise = Plotly.restyle(initialDiv, 'marker.color', 'rgb(255,0,0)'); + + promise.then(function(gd){ + promiseGd = gd; + done(); + }); + }); + afterEach(destroyGraphDiv); + + it('should be returned with the graph div as an argument', function () { + expect(promiseGd).toBeDefined(); + expect(typeof promiseGd).toBe('object'); + expect(promiseGd.data).toBeDefined(); + expect(promiseGd.layout).toBeDefined(); + }); + }); + + describe('Plotly.relayout promise', function () { + var promise, + promiseGd; + + beforeEach(function (done) { + var data = [{ x: [1,2,3], y: [4,5,6] }], + initialDiv = createGraphDiv(); + + Plotly.plot(initialDiv, data, {}); + + promise = Plotly.restyle(initialDiv, 'title', 'Promise test!'); + + promise.then(function(gd){ + promiseGd = gd; + done(); + }); + }); + afterEach(destroyGraphDiv); + + it('should be returned with the graph div as an argument', function () { + expect(promiseGd).toBeDefined(); + expect(typeof promiseGd).toBe('object'); + expect(promiseGd.data).toBeDefined(); + expect(promiseGd.layout).toBeDefined(); + }); + }); + +});