Skip to content

test that validateTemplate accepts DOM element as input #3118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions test/jasmine/tests/template_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,7 @@ describe('template interactions', function() {

describe('validateTemplate', function() {

function checkValidate(mock, expected, countToCheck) {
var template = mock.layout.template;
var mockNoTemplate = Lib.extendDeep({}, mock);
delete mockNoTemplate.layout.template;

var out1 = Plotly.validateTemplate(mock);
var out2 = Plotly.validateTemplate(mockNoTemplate, template);
function compareOutputs(out1, out2, expected, countToCheck) {
expect(out2).toEqual(out1);
if(expected) {
expect(countToCheck ? out1.slice(0, countToCheck) : out1)
Expand All @@ -280,17 +274,41 @@ describe('validateTemplate', function() {
}
}

function checkValidate(mock, expected, countToCheck) {
var template = mock.layout.template;
var mockNoTemplate = Lib.extendDeep({}, mock);
delete mockNoTemplate.layout.template;

// Test with objects as argument
var out1 = Plotly.validateTemplate(mock);
var out2 = Plotly.validateTemplate(mockNoTemplate, template);
expect(out2).toEqual(out1);
compareOutputs(out1, out2, expected, countToCheck);

// Test with DOM elements as argument
var gd = createGraphDiv(), gdNotemplate = createGraphDiv();
return Plotly.newPlot(gd, mock)
.then(function() {return Plotly.newPlot(gdNotemplate, mockNoTemplate);})
.then(function() {
var out1 = Plotly.validateTemplate(gd);
var out2 = Plotly.validateTemplate(gdNotemplate, template);
compareOutputs(out1, out2, expected, countToCheck);
})
.catch(failTest)
.then(destroyGraphDiv);
}

var cleanMock = Lib.extendDeep({}, templateMock);
cleanMock.layout.annotations.pop();
cleanMock.data.pop();
cleanMock.data.splice(1, 1);
cleanMock.layout.template.data.bar.pop();

it('returns undefined when the template matches precisely', function() {
checkValidate(cleanMock);
it('returns undefined when the template matches precisely', function(done) {
checkValidate(cleanMock).then(done);
});

it('catches all classes of regular issue', function() {
it('catches all classes of regular issue', function(done) {
var messyMock = Lib.extendDeep({}, templateMock);
messyMock.data.push({type: 'box', x0: 1, y: [1, 2, 3]});
messyMock.layout.template.layout.geo = {projection: {type: 'orthographic'}};
Expand Down Expand Up @@ -347,10 +365,10 @@ describe('validateTemplate', function() {
path: 'layout.annotations[4]',
templateitemname: 'nope',
msg: 'There are no templates for item layout.annotations[4] with name nope'
}]);
}]).then(done);
});

it('catches missing template.data', function() {
it('catches missing template.data', function(done) {
var noDataMock = Lib.extendDeep({}, cleanMock);
delete noDataMock.layout.template.data;

Expand All @@ -360,17 +378,17 @@ describe('validateTemplate', function() {
}],
// check only the first error - we don't care about the specifics
// uncovered after we already know there's no template.data
1);
1).then(done);
});

it('catches missing template.layout', function() {
it('catches missing template.layout', function(done) {
var noLayoutMock = Lib.extendDeep({}, cleanMock);
delete noLayoutMock.layout.template.layout;

checkValidate(noLayoutMock, [{
code: 'layout',
msg: 'The template has no key layout.'
}], 1);
}], 1).then(done);
});

});