Skip to content

Commit 892707f

Browse files
committed
handle async in plot_api tests
1 parent 3bccdb1 commit 892707f

File tree

1 file changed

+76
-48
lines changed

1 file changed

+76
-48
lines changed

test/jasmine/tests/plot_api_test.js

Lines changed: 76 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -560,14 +560,16 @@ describe('Test plot api', function() {
560560
done();
561561
});
562562

563-
Plotly.relayout(gd, {
563+
return Plotly.relayout(gd, {
564564
'title': 'Plotly chart',
565565
'xaxis.title': 'X',
566566
'xaxis.titlefont': {color: 'green'},
567567
'yaxis.title': 'Y',
568568
'polar.radialaxis.title': 'Radial'
569569
});
570-
});
570+
})
571+
.catch(failTest)
572+
.then(done);
571573
});
572574
});
573575

@@ -620,7 +622,7 @@ describe('Test plot api', function() {
620622
expect(subroutines.layoutReplot.calls.count()).toBeGreaterThan(0, msg);
621623
}
622624

623-
it('should trigger replot (but not recalc) when switching into select or lasso dragmode for scattergl traces', function() {
625+
it('should trigger replot (but not recalc) when switching into select or lasso dragmode for scattergl traces', function(done) {
624626
gd = mock({
625627
data: [{
626628
type: 'scattergl',
@@ -660,7 +662,9 @@ describe('Test plot api', function() {
660662
})
661663
.then(function() {
662664
expectReplot('select 2');
663-
});
665+
})
666+
.catch(failTest)
667+
.then(done);
664668
});
665669

666670
it('should trigger replot (but not recalc) when changing attributes that affect axis length/range', function() {
@@ -755,7 +759,7 @@ describe('Test plot api', function() {
755759
});
756760
});
757761

758-
it('should trigger calc on axis range updates when constraints are present', function() {
762+
it('should trigger calc on axis range updates when constraints are present', function(done) {
759763
gd = mock({
760764
data: [{
761765
y: [1, 2, 1]
@@ -769,7 +773,9 @@ describe('Test plot api', function() {
769773
Plotly.relayout(gd, 'xaxis.range[0]', 0)
770774
.then(function() {
771775
expect(gd.calcdata).toBeUndefined();
772-
});
776+
})
777+
.catch(failTest)
778+
.then(done);
773779
});
774780
});
775781

@@ -791,7 +797,7 @@ describe('Test plot api', function() {
791797
gd.emit = function() {};
792798
}
793799

794-
it('calls Scatter.arraysToCalcdata and Plots.style on scatter styling', function() {
800+
it('calls Scatter.arraysToCalcdata and Plots.style on scatter styling', function(done) {
795801
var gd = {
796802
data: [{x: [1, 2, 3], y: [1, 2, 3]}],
797803
layout: {}
@@ -805,10 +811,12 @@ describe('Test plot api', function() {
805811
expect(plotApi.plot).not.toHaveBeenCalled();
806812
// "docalc" deletes gd.calcdata - make sure this didn't happen
807813
expect(gd.calcdata).toBeDefined();
808-
});
814+
})
815+
.catch(failTest)
816+
.then(done);
809817
});
810818

811-
it('calls Bar.arraysToCalcdata and Plots.style on bar styling', function() {
819+
it('calls Bar.arraysToCalcdata and Plots.style on bar styling', function(done) {
812820
var gd = {
813821
data: [{x: [1, 2, 3], y: [1, 2, 3], type: 'bar'}],
814822
layout: {}
@@ -821,10 +829,12 @@ describe('Test plot api', function() {
821829
expect(Plots.style).toHaveBeenCalled();
822830
expect(plotApi.plot).not.toHaveBeenCalled();
823831
expect(gd.calcdata).toBeDefined();
824-
});
832+
})
833+
.catch(failTest)
834+
.then(done);
825835
});
826836

827-
it('should do full replot when arrayOk attributes are updated', function() {
837+
it('should do full replot when arrayOk attributes are updated', function(done) {
828838
var gd = {
829839
data: [{x: [1, 2, 3], y: [1, 2, 3]}],
830840
layout: {}
@@ -859,10 +869,12 @@ describe('Test plot api', function() {
859869
.then(function() {
860870
expect(gd.calcdata).toBeUndefined();
861871
expect(plotApi.plot).toHaveBeenCalled();
862-
});
872+
})
873+
.catch(failTest)
874+
.then(done);
863875
});
864876

865-
it('should do full replot when arrayOk base attributes are updated', function() {
877+
it('should do full replot when arrayOk base attributes are updated', function(done) {
866878
var gd = {
867879
data: [{x: [1, 2, 3], y: [1, 2, 3]}],
868880
layout: {}
@@ -897,10 +909,12 @@ describe('Test plot api', function() {
897909
.then(function() {
898910
expect(gd.calcdata).toBeUndefined();
899911
expect(plotApi.plot).toHaveBeenCalled();
900-
});
912+
})
913+
.catch(failTest)
914+
.then(done);
901915
});
902916

903-
it('should do full replot when attribute container are updated', function() {
917+
it('should do full replot when attribute container are updated', function(done) {
904918
var gd = {
905919
data: [{x: [1, 2, 3], y: [1, 2, 3]}],
906920
layout: {
@@ -918,10 +932,12 @@ describe('Test plot api', function() {
918932
.then(function() {
919933
expect(gd.calcdata).toBeUndefined();
920934
expect(plotApi.plot).toHaveBeenCalled();
921-
});
935+
})
936+
.catch(failTest)
937+
.then(done);
922938
});
923939

924-
it('calls plot on xgap and ygap styling', function() {
940+
it('calls plot on xgap and ygap styling', function(done) {
925941
var gd = {
926942
data: [{z: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], showscale: false, type: 'heatmap'}],
927943
layout: {}
@@ -936,28 +952,27 @@ describe('Test plot api', function() {
936952
})
937953
.then(function() {
938954
expect(plotApi.plot.calls.count()).toEqual(2);
939-
});
955+
})
956+
.catch(failTest)
957+
.then(done);
940958
});
941959

942-
it('should clear calcdata when restyling \'zmin\' and \'zmax\' on contour traces', function() {
943-
var contour = {
960+
[
961+
{
944962
data: [{
945963
type: 'contour',
946964
z: [[1, 2, 3], [1, 2, 1]]
947965
}]
948-
};
949-
950-
var histogram2dcontour = {
966+
},
967+
{
951968
data: [{
952969
type: 'histogram2dcontour',
953970
x: [1, 1, 2, 2, 2, 3],
954971
y: [0, 0, 0, 0, 1, 3]
955972
}]
956-
};
957-
958-
var mocks = [contour, histogram2dcontour];
959-
960-
mocks.forEach(function(gd) {
973+
}
974+
].forEach(function(gd) {
975+
it('should clear calcdata when restyling \'zmin\' and \'zmax\' on ' + gd.data.type + ' traces', function(done) {
961976
mockDefaultsAndCalc(gd);
962977
plotApi.plot.calls.reset();
963978
Plotly.restyle(gd, 'zmin', 0)
@@ -972,29 +987,28 @@ describe('Test plot api', function() {
972987
.then(function() {
973988
expect(gd.calcdata).toBeUndefined();
974989
expect(plotApi.plot).toHaveBeenCalled();
975-
});
990+
})
991+
.catch(failTest)
992+
.then(done);
976993
});
977994
});
978995

979-
it('should not clear calcdata when restyling \'zmin\' and \'zmax\' on heatmap traces', function() {
980-
var heatmap = {
996+
[
997+
{
981998
data: [{
982999
type: 'heatmap',
9831000
z: [[1, 2, 3], [1, 2, 1]]
9841001
}]
985-
};
986-
987-
var histogram2d = {
1002+
},
1003+
{
9881004
data: [{
9891005
type: 'histogram2d',
9901006
x: [1, 1, 2, 2, 2, 3],
9911007
y: [0, 0, 0, 0, 1, 3]
9921008
}]
993-
};
994-
995-
var mocks = [heatmap, histogram2d];
996-
997-
mocks.forEach(function(gd) {
1009+
}
1010+
].forEach(function(gd) {
1011+
it('should not clear calcdata when restyling \'zmin\' and \'zmax\' on ' + gd.data.type + ' traces', function(done) {
9981012
mockDefaultsAndCalc(gd);
9991013
plotApi.plot.calls.reset();
10001014
Plotly.restyle(gd, 'zmin', 0)
@@ -1009,11 +1023,17 @@ describe('Test plot api', function() {
10091023
.then(function() {
10101024
expect(gd.calcdata).toBeDefined();
10111025
expect(plotApi.plot).toHaveBeenCalled();
1012-
});
1026+
1027+
mockDefaultsAndCalc(gd);
1028+
plotApi.plot.calls.reset();
1029+
return Plotly.restyle(gd, 'zmin', 0);
1030+
})
1031+
.catch(failTest)
1032+
.then(done);
10131033
});
10141034
});
10151035

1016-
it('ignores undefined values', function() {
1036+
it('ignores undefined values', function(done) {
10171037
var gd = {
10181038
data: [{x: [1, 2, 3], y: [1, 2, 3], type: 'scatter'}],
10191039
layout: {}
@@ -1031,10 +1051,12 @@ describe('Test plot api', function() {
10311051
})
10321052
.then(function() {
10331053
expect(gd._fullData[0].marker.color).toBe('blue');
1034-
});
1054+
})
1055+
.catch(failTest)
1056+
.then(done);
10351057
});
10361058

1037-
it('ignores invalid trace indices', function() {
1059+
it('ignores invalid trace indices', function(done) {
10381060
var gd = {
10391061
data: [{x: [1, 2, 3], y: [1, 2, 3], type: 'scatter'}],
10401062
layout: {}
@@ -1043,10 +1065,12 @@ describe('Test plot api', function() {
10431065
mockDefaultsAndCalc(gd);
10441066

10451067
// Call restyle on an invalid trace indice
1046-
Plotly.restyle(gd, {'type': 'scatter', 'marker.color': 'red'}, [1]);
1068+
Plotly.restyle(gd, {'type': 'scatter', 'marker.color': 'red'}, [1])
1069+
.catch(failTest)
1070+
.then(done);
10471071
});
10481072

1049-
it('restores null values to defaults', function() {
1073+
it('restores null values to defaults', function(done) {
10501074
var gd = {
10511075
data: [{x: [1, 2, 3], y: [1, 2, 3], type: 'scatter'}],
10521076
layout: {}
@@ -1065,10 +1089,12 @@ describe('Test plot api', function() {
10651089
})
10661090
.then(function() {
10671091
expect(gd._fullData[0].marker.color).toBe(colorDflt);
1068-
});
1092+
})
1093+
.catch(failTest)
1094+
.then(done);
10691095
});
10701096

1071-
it('can target specific traces by leaving properties undefined', function() {
1097+
it('can target specific traces by leaving properties undefined', function(done) {
10721098
var gd = {
10731099
data: [
10741100
{x: [1, 2, 3], y: [1, 2, 3], type: 'scatter'},
@@ -1092,7 +1118,9 @@ describe('Test plot api', function() {
10921118
.then(function() {
10931119
expect(gd._fullData[0].marker.color).toBe(colorDflt[0]);
10941120
expect(gd._fullData[1].marker.color).toBe(colorDflt[1]);
1095-
});
1121+
})
1122+
.catch(failTest)
1123+
.then(done);
10961124
});
10971125
});
10981126

0 commit comments

Comments
 (0)