Skip to content

Commit 3ef1c9b

Browse files
committed
test errors from parent/child simultaneous edits
1 parent d29cbae commit 3ef1c9b

File tree

1 file changed

+76
-2
lines changed

1 file changed

+76
-2
lines changed

test/jasmine/tests/plot_api_test.js

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,42 @@ describe('Test plot api', function() {
180180
.then(done);
181181
});
182182

183+
it('errors if child and parent are edited together', function(done) {
184+
var edit1 = {rando: [{a: 1}, {b: 2}]};
185+
var edit2 = {'rando[1]': {c: 3}};
186+
var edit3 = {'rando[1].d': 4};
187+
188+
Plotly.plot(gd, [{ x: [1, 2, 3], y: [1, 2, 3] }])
189+
.then(function() {
190+
return Plotly.relayout(gd, edit1);
191+
})
192+
.then(function() {
193+
expect(gd.layout.rando).toEqual([{a: 1}, {b: 2}]);
194+
return Plotly.relayout(gd, edit2);
195+
})
196+
.then(function() {
197+
expect(gd.layout.rando).toEqual([{a: 1}, {c: 3}]);
198+
return Plotly.relayout(gd, edit3);
199+
})
200+
.then(function() {
201+
expect(gd.layout.rando).toEqual([{a: 1}, {c: 3, d: 4}]);
202+
203+
// OK, setup is done - test the failing combinations
204+
[[edit1, edit2], [edit1, edit3], [edit2, edit3]].forEach(function(v) {
205+
// combine properties in both orders - which results in the same object
206+
// but the properties are iterated in opposite orders
207+
expect(function() {
208+
return Plotly.relayout(gd, Lib.extendFlat({}, v[0], v[1]));
209+
}).toThrow();
210+
expect(function() {
211+
return Plotly.relayout(gd, Lib.extendFlat({}, v[1], v[0]));
212+
}).toThrow();
213+
});
214+
})
215+
.catch(fail)
216+
.then(done);
217+
});
218+
183219
it('can set empty text nodes', function(done) {
184220
var data = [{
185221
x: [1, 2, 3],
@@ -333,7 +369,7 @@ describe('Test plot api', function() {
333369
destroyGraphDiv();
334370
});
335371

336-
it('should redo auto z/contour when editing z array', function() {
372+
it('should redo auto z/contour when editing z array', function(done) {
337373
Plotly.plot(gd, [{type: 'contour', z: [[1, 2], [3, 4]]}]).then(function() {
338374
expect(gd.data[0].zauto).toBe(true, gd.data[0]);
339375
expect(gd.data[0].zmin).toBe(1);
@@ -348,7 +384,45 @@ describe('Test plot api', function() {
348384
expect(gd.data[0].zmax).toBe(10);
349385

350386
expect(gd.data[0].contours).toEqual({start: 3, end: 9, size: 1});
351-
});
387+
})
388+
.catch(fail)
389+
.then(done);
390+
});
391+
392+
it('errors if child and parent are edited together', function(done) {
393+
var edit1 = {rando: [[{a: 1}, {b: 2}]]};
394+
var edit2 = {'rando[1]': {c: 3}};
395+
var edit3 = {'rando[1].d': 4};
396+
397+
Plotly.plot(gd, [{x: [1, 2, 3], y: [1, 2, 3], type: 'scatter'}])
398+
.then(function() {
399+
return Plotly.restyle(gd, edit1);
400+
})
401+
.then(function() {
402+
expect(gd.data[0].rando).toEqual([{a: 1}, {b: 2}]);
403+
return Plotly.restyle(gd, edit2);
404+
})
405+
.then(function() {
406+
expect(gd.data[0].rando).toEqual([{a: 1}, {c: 3}]);
407+
return Plotly.restyle(gd, edit3);
408+
})
409+
.then(function() {
410+
expect(gd.data[0].rando).toEqual([{a: 1}, {c: 3, d: 4}]);
411+
412+
// OK, setup is done - test the failing combinations
413+
[[edit1, edit2], [edit1, edit3], [edit2, edit3]].forEach(function(v) {
414+
// combine properties in both orders - which results in the same object
415+
// but the properties are iterated in opposite orders
416+
expect(function() {
417+
return Plotly.restyle(gd, Lib.extendFlat({}, v[0], v[1]));
418+
}).toThrow();
419+
expect(function() {
420+
return Plotly.restyle(gd, Lib.extendFlat({}, v[1], v[0]));
421+
}).toThrow();
422+
});
423+
})
424+
.catch(fail)
425+
.then(done);
352426
});
353427
});
354428

0 commit comments

Comments
 (0)