Skip to content

Commit

Permalink
Compare dynamic element metadata to archetype, see #121
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Aug 26, 2020
1 parent d6009d6 commit d858a22
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions js/phetioAPIValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* 8. Any schema entries in the overrides file must be different from its baseline counterpart
* 9. Types in the sim must exactly match types in the types file to ensure that type changes are intentional.
* 10. Dynamic elements should not appear in the API.
* 11. Dynamic element metadata should match the archetype in the API.
*
* Terminology:
* schema: specified through preloads. The full schema is the baseline plus the overrides, but those parts can be
Expand Down Expand Up @@ -265,6 +266,27 @@ class PhetioAPIValidation {
ruleInViolation: '4. After startup, only dynamic instances prescribed by the baseline file can be registered.'
} );
}
else {

const archetypeID = phetioObject.tandem.getConcretePhetioID();
const archetypeMetadata = this.loadedReferenceAPI.phetioElements[ archetypeID ];
const actualMetadata = phetioObject.getMetadata();

KEYS_TO_CHECK.forEach( key => {

// These attributes are different for archetype vs actual
if ( key !== 'phetioDynamicElement' && key !== 'phetioArchetypePhetioID' && key !== 'phetioIsArchetype' ) {

if ( archetypeMetadata[ key ] !== actualMetadata[ key ] ) {
this.assertAPIError( {
phetioID: phetioObject.tandem.phetioID,
ruleInViolation: '11. Dynamic element metadata should match the archetype in the API.',
message: 'mismatched metadata: ' + key
} );
}
}
} );
}
} );
}
}
Expand Down

0 comments on commit d858a22

Please sign in to comment.