Skip to content

Commit b459a2b

Browse files
committed
allow input mocks to declare layout attrs in checkTextTemplate
1 parent 9ee4aa7 commit b459a2b

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

test/jasmine/assets/check_texttemplate.js

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var Plotly = require('@lib/index');
24
var Registry = require('@src/registry');
35

@@ -7,17 +9,25 @@ var createGraphDiv = require('../assets/create_graph_div');
79
var destroyGraphDiv = require('../assets/destroy_graph_div');
810
var supplyAllDefaults = require('../assets/supply_defaults');
911

10-
'use strict';
11-
1212
module.exports = function checkTextTemplate(mock, selector, tests, skipExtra) {
13-
var isGL = Registry.traceIs(mock[0].type, 'gl');
14-
var isPolar = Registry.traceIs(mock[0].type, 'polar');
15-
var isScatterLike = Registry.traceIs(mock[0].type, 'scatter-like');
16-
var isBarLike = Registry.traceIs(mock[0].type, 'bar-like');
13+
var data;
14+
var layout;
15+
if(Array.isArray(mock)) {
16+
data = mock;
17+
layout = {};
18+
} else {
19+
data = mock.data;
20+
layout = mock.layout || {};
21+
}
22+
23+
var isGL = Registry.traceIs(data[0].type, 'gl');
24+
var isPolar = Registry.traceIs(data[0].type, 'polar');
25+
var isScatterLike = Registry.traceIs(data[0].type, 'scatter-like');
26+
var isBarLike = Registry.traceIs(data[0].type, 'bar-like');
1727

1828
it('should not coerce textinfo when texttemplate is defined', function() {
1929
var gd = {};
20-
gd.data = Lib.extendDeep([], mock);
30+
gd.data = Lib.extendDeep([], data);
2131
gd.data[0].textinfo = 'text';
2232
gd.data[0].texttemplate = 'texttemplate';
2333
supplyAllDefaults(gd);
@@ -27,7 +37,7 @@ module.exports = function checkTextTemplate(mock, selector, tests, skipExtra) {
2737
if(isScatterLike) {
2838
it('should not coerce texttemplate when mode has no `text` flag', function() {
2939
var gd = {};
30-
gd.data = Lib.extendDeep([], mock);
40+
gd.data = Lib.extendDeep([], data);
3141
gd.data[0].mode = 'markers';
3242
gd.data[0].texttemplate = 'texttemplate';
3343
supplyAllDefaults(gd);
@@ -38,7 +48,7 @@ module.exports = function checkTextTemplate(mock, selector, tests, skipExtra) {
3848
if(isBarLike) {
3949
it('should not coerce texttemplate when textposition is `none`', function() {
4050
var gd = {};
41-
gd.data = Lib.extendDeep([], mock);
51+
gd.data = Lib.extendDeep([], data);
4252
gd.data[0].textposition = 'none';
4353
gd.data[0].texttemplate = 'texttemplate';
4454
supplyAllDefaults(gd);
@@ -56,19 +66,19 @@ module.exports = function checkTextTemplate(mock, selector, tests, skipExtra) {
5666
for(i = 0; i < N; i++) {
5767
customdata.push(Lib.randstr({}));
5868
}
59-
mock[0].customdata = customdata;
69+
data[0].customdata = customdata;
6070
tests.push(['%{customdata}', customdata]);
6171

6272
// Generate meta
63-
mock[0].meta = {'colname': 'A'};
73+
data[0].meta = {'colname': 'A'};
6474
var metaSolution = [];
6575
for(i = 0; i < N; i++) {
66-
metaSolution.push(mock[0].meta.colname);
76+
metaSolution.push(data[0].meta.colname);
6777
}
6878
tests.push(['%{meta.colname}', metaSolution]);
6979

7080
// Make sure that empty text shows up as an empty string
71-
var emptyTextMock = Lib.extendDeep([], mock);
81+
var emptyTextMock = Lib.extendDeep([], data);
7282
var emptyTextSolution = [];
7383
emptyTextMock[0].text = [];
7484
for(i = 0; i < N; i++) {
@@ -81,9 +91,9 @@ module.exports = function checkTextTemplate(mock, selector, tests, skipExtra) {
8191
tests.forEach(function(test) {
8292
it('@gl should support texttemplate', function(done) {
8393
var gd = createGraphDiv();
84-
var mockCopy = Lib.extendDeep([], test[2] || mock);
85-
mockCopy[0].texttemplate = test[0];
86-
Plotly.newPlot(gd, mockCopy)
94+
var dataCopy = Lib.extendDeep([], test[2] || data);
95+
dataCopy[0].texttemplate = test[0];
96+
Plotly.newPlot(gd, dataCopy, Lib.extendDeep({}, layout))
8797
.then(function() {
8898
var glText;
8999
if(isPolar) {
@@ -113,9 +123,9 @@ module.exports = function checkTextTemplate(mock, selector, tests, skipExtra) {
113123
tests.forEach(function(test) {
114124
it('should support texttemplate', function(done) {
115125
var gd = createGraphDiv();
116-
var mockCopy = Lib.extendDeep([], test[2] || mock);
117-
mockCopy[0].texttemplate = test[0];
118-
Plotly.newPlot(gd, mockCopy)
126+
var dataCopy = Lib.extendDeep([], test[2] || data);
127+
dataCopy[0].texttemplate = test[0];
128+
Plotly.newPlot(gd, dataCopy, Lib.extendDeep({}, layout))
119129
.then(function() {
120130
var pts = Plotly.d3.selectAll(selector);
121131
expect(pts.size()).toBe(test[1].length);

0 commit comments

Comments
 (0)