Skip to content

Commit 87b26d5

Browse files
committed
test order-independence of trace/transform/component registration
1 parent 62a1392 commit 87b26d5

File tree

4 files changed

+130
-1
lines changed

4 files changed

+130
-1
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
var d3 = require('d3');
2+
3+
var createGraphDiv = require('../assets/create_graph_div');
4+
var destroyGraphDiv = require('../assets/destroy_graph_div');
5+
6+
/**
7+
* common test that components work as registered
8+
* expects bar, scatter3d, filter, and calendars to be registered
9+
* but the test is that they may have been registered in any order
10+
*/
11+
module.exports = function checkComponent(Plotly) {
12+
describe('core (svg 2d, scatter) and registered (bar) traces and transforms', function() {
13+
var gd;
14+
15+
var mock = {
16+
data: [
17+
{
18+
// x data is date so we coerce a calendar
19+
x: ['2001-01-01', '2002-01-01', '2003-01-01'],
20+
y: [1, 3, 5]
21+
},
22+
{
23+
x: ['2001-01-01', '2002-01-01', '2003-01-01'],
24+
y: [1, 3, 5],
25+
type: 'bar',
26+
transforms: [{
27+
type: 'filter',
28+
operation: '<',
29+
target: 'y',
30+
value: '4',
31+
// need an explicit calendar, as filter uses a default of null
32+
// the rest of them get the default calendar filled in
33+
valuecalendar: 'nepali'
34+
}]
35+
}
36+
]
37+
};
38+
39+
beforeEach(function(done) {
40+
gd = createGraphDiv();
41+
Plotly.plot(gd, mock.data, mock.layout).then(done);
42+
});
43+
44+
afterEach(destroyGraphDiv);
45+
46+
it('should graph scatter traces with calendar attributes', function() {
47+
var nodes = d3.selectAll('g.trace.scatter');
48+
49+
expect(nodes.size()).toEqual(1);
50+
51+
// compare to core_test
52+
expect(gd._fullLayout.calendar).toBe('gregorian');
53+
expect(gd._fullLayout.xaxis.calendar).toBe('gregorian');
54+
expect(gd._fullData[0].xcalendar).toBe('gregorian');
55+
});
56+
57+
it('should graph bar traces with calendar attributes', function() {
58+
var nodes = d3.selectAll('g.trace.bars');
59+
60+
expect(nodes.size()).toEqual(1);
61+
expect(gd._fullData[1].xcalendar).toBe('gregorian');
62+
expect(gd._fullData[1].transforms[0].valuecalendar).toBe('nepali');
63+
});
64+
});
65+
66+
describe('registered subplot (gl3d)', function() {
67+
var gd;
68+
69+
var mock = require('@mocks/gl3d_world-cals');
70+
// just pick out the scatter3d trace
71+
mock.data = [mock.data[1]];
72+
var xaxisCalendar = mock.layout.scene.xaxis.calendar;
73+
var zDataCalendar = mock.data[0].zcalendar;
74+
75+
beforeEach(function(done) {
76+
gd = createGraphDiv();
77+
Plotly.plot(gd, mock.data, mock.layout).then(done);
78+
});
79+
80+
afterEach(destroyGraphDiv);
81+
82+
it('should graph gl3d axes and 3d plot types with calendars', function() {
83+
expect(xaxisCalendar).toBeDefined();
84+
expect(zDataCalendar).toBeDefined();
85+
86+
expect(gd._fullLayout.scene.xaxis.calendar).toBe(xaxisCalendar);
87+
expect(gd._fullData[0].zcalendar).toBe(zDataCalendar);
88+
});
89+
});
90+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var Plotly = require('@lib/core');
2+
var Bar = require('@lib/bar');
3+
var Scatter3d = require('@lib/scatter3d');
4+
var Filter = require('@lib/filter');
5+
var Calendars = require('@lib/calendars');
6+
7+
var checkComponent = require('../assets/check_component');
8+
9+
describe('Bundle with a component loaded before traces and transforms', function() {
10+
'use strict';
11+
12+
Plotly.register([Calendars, Filter, Scatter3d, Bar]);
13+
14+
checkComponent(Plotly);
15+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var Plotly = require('@lib/core');
2+
var Bar = require('@lib/bar');
3+
var Scatter3d = require('@lib/scatter3d');
4+
var Filter = require('@lib/filter');
5+
var Calendars = require('@lib/calendars');
6+
7+
var checkComponent = require('../assets/check_component');
8+
9+
describe('Bundle with a component loaded after traces and transforms', function() {
10+
'use strict';
11+
12+
Plotly.register([Bar, Scatter3d, Filter, Calendars]);
13+
14+
checkComponent(Plotly);
15+
});

test/jasmine/bundle_tests/core_test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
88

99
describe('Bundle with core only', function() {
1010
'use strict';
11+
var gd;
1112

1213
var mock = require('@mocks/bar_line.json');
1314

1415
beforeEach(function(done) {
15-
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
16+
gd = createGraphDiv();
17+
Plotly.plot(gd, mock.data, mock.layout).then(done);
1618
});
1719

1820
afterEach(destroyGraphDiv);
@@ -28,4 +30,11 @@ describe('Bundle with core only', function() {
2830

2931
expect(nodes.size()).toEqual(0);
3032
});
33+
34+
it('should not have calendar attributes', function() {
35+
// calendars is a register-able component that we have not registered
36+
expect(gd._fullLayout.calendar).toBeUndefined();
37+
expect(gd._fullLayout.xaxis.calendar).toBeUndefined();
38+
expect(gd._fullData[0].xcalendar).toBeUndefined();
39+
});
3140
});

0 commit comments

Comments
 (0)