8000 Bring back roles with value object by archmoj · Pull Request #5432 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Bring back roles with value object #5432

8000
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 7 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
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
Next Next commit
Revert "adapt tests"
This reverts commit bd47920.
  • Loading branch information
archmoj committed Jan 22, 2021
commit d3d8db767efa27433f1c0de7ade29e6b30aca0ea
38 changes: 34 additions & 4 deletions test/jasmine/bundle_tests/plotschema_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('plot schema', function() {
var isPlainObject = Lib.isPlainObject;

var VALTYPES = Object.keys(valObjects);
var ROLES = ['info', 'style', 'data'];
var editType = plotSchema.defs.editType;

function assertTraceSchema(callback) {
Expand Down Expand Up @@ -72,6 +73,26 @@ describe('plot schema', function() {
);
});

it('all attributes should only have valid `role`', function() {
assertPlotSchema(
function(attr) {
if(isValObject(attr)) {
expect(ROLES.indexOf(attr.role) !== -1).toBe(true, attr);
}
}
);
});

it('all nested objects should have the *object* `role`', function() {
assertPlotSchema(
function(attr, attrName) {
if(!isValObject(attr) && isPlainObject(attr) && attrName !== 'items') {
expect(attr.role === 'object').toBe(true);
}
}
);
});

it('all attributes should have the required options', function() {
assertPlotSchema(
function(attr) {
Expand All @@ -94,7 +115,7 @@ describe('plot schema', function() {
var opts = valObject.requiredOpts
.concat(valObject.otherOpts)
.concat([
'valType', 'description',
'valType', 'description', 'role',
'editType', 'impliedEdits', 'anim',
'_compareAsJSON', '_noTemplating'
]);
Expand Down Expand Up @@ -164,8 +185,13 @@ describe('plot schema', function() {

// N.B. the specs below must be satisfied for plotly.py
expect(isPlainObject(itemsObj)).toBe(true);
expect(itemsObj.role).toBeUndefined();
expect(Object.keys(itemsObj).length).toEqual(1);
expect(isPlainObject(itemObj)).toBe(true);
expect(itemObj.role).toBe('object');

var role = np.get().role;
expect(role).toEqual('object');
});
});

Expand Down 8000 Expand Up @@ -197,7 +223,7 @@ describe('plot schema', function() {
);
});

it('deprecated attributes should have a `valType`', function() {
it('deprecated attributes should have a `valType` and `role`', function() {
var DEPRECATED = '_deprecated';

assertPlotSchema(
Expand All @@ -208,6 +234,8 @@ describe('plot schema', function() {

expect(VALTYPES.indexOf(dAttr.valType) !== -1)
.toBe(true, attrString + ': ' + dAttrName);
expect(ROLES.indexOf(dAttr.role) !== -1)
.toBe(true, attrString + ': ' + dAttrName);
});
}
}
Expand Down Expand Up @@ -289,13 +317,15 @@ describe('plot schema', function() {
expect(plotSchema.defs.metaKeys)
.toEqual([
'_isSubplotObj', '_isLinkedToArray', '_arrayAttrRegexps',
'_deprecated', 'description', 'editType', 'impliedEdits'
'_deprecated', 'description', 'role', 'editType', 'impliedEdits'
]);
});

it('should list the correct frame attributes', function() {
expect(plotSchema.frames).toBeDefined();
expect(plotSchema.frames.role).toEqual('object');
expect(plotSchema.frames.items.frames_entry).toBeDefined();
expect(plotSchema.frames.items.frames_entry.role).toEqual('object');
});

it('should list config attributes', function() {
Expand Down Expand Up @@ -439,7 +469,7 @@ describe('getTraceValObject', function() {
// it still returns the attribute itself - but maybe we should only do this
// for valType: any? (or data_array/arrayOk with just an index)
[
'valType', 'dflt', 'description', 'arrayOk',
'valType', 'dflt', 'role', 'description', 'arrayOk',
'editType', 'min', 'max', 'values'
].forEach(function(prop) {
expect(getTraceValObject({}, ['x', prop]))
Expand Down
6 changes: 4 additions & 2 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2877,7 +2877,8 @@ describe('plot_api edit_types', function() {

editTypes.update(flags, {
valType: 'boolean',
dflt: true
dflt: true,
role: 'style'
});

expect(flags).toEqual({calc: false, style: true});
Expand All @@ -2897,7 +2898,8 @@ describe('plot_api edit_types', function() {
editTypes.update(flags, {
editType: 'calc+style',
valType: 'number',
dflt: 1
dflt: 1,
role: 'style'
});

expect(flags).toEqual({calc: true, legend: true, style: true});
Expand Down
0