Skip to content

Commit

Permalink
Add tests for all propertyNames changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlende committed Jul 18, 2024
1 parent 2ac04ea commit fb81b62
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/integration/fixtures/schemas/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "../../../../schemas/json/theme.json",
"version": 3,
"settings": {
"invalidAdditionalProperty": true
}
}
11 changes: 11 additions & 0 deletions test/integration/fixtures/schemas/settingsPropertiesComplete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "../../../../schemas/json/theme.json",
"version": 3,
"settings": {
"blocks": {
"core/button": {
"invalidAdditionalProperty": true
}
}
}
}
7 changes: 7 additions & 0 deletions test/integration/fixtures/schemas/styles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "../../../../schemas/json/theme.json",
"version": 3,
"styles": {
"invalidAdditionalProperty": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "../../../../schemas/json/theme.json",
"version": 3,
"styles": {
"elements": {
"button": {
"invalidAdditionalProperty": true
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "../../../../schemas/json/theme.json",
"version": 3,
"styles": {
"elements": {
"link": {
"invalidAdditionalProperty": true
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "../../../../schemas/json/theme.json",
"version": 3,
"styles": {
"blocks": {
"core/button": {
"invalidAdditionalProperty": true
}
}
}
}
14 changes: 14 additions & 0 deletions test/integration/fixtures/schemas/stylesPropertiesComplete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "../../../../schemas/json/theme.json",
"version": 3,
"styles": {
"invalidAdditionalProperty": true,
"elements": {
"button": {
":hover": {
"invalidAdditionalProperty": true
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../../../../schemas/json/theme.json",
"version": 3,
"styles": {
"variations": {
"custom-variation": {
"blocks": {
"core/button": {
"invalidAdditionalProperty": true
}
}
}
}
}
}
11 changes: 11 additions & 0 deletions test/integration/fixtures/schemas/stylesVariationProperties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "../../../../schemas/json/theme.json",
"version": 3,
"styles": {
"variations": {
"custom-variation": {
"invalidAdditionalProperty": true
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../../../../schemas/json/theme.json",
"version": 3,
"styles": {
"blocks": {
"core/button": {
"variations": {
"custom-variation": {
"invalidAdditionalProperty": true
}
}
}
}
}
}
13 changes: 13 additions & 0 deletions test/integration/theme-schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ describe( 'theme.json schema', () => {
[ 'packages/*/src/**/theme.json', '{lib,phpunit,test}/**/theme.json' ],
{ onlyFiles: true }
);
const invalidFiles = glob.sync(
[ 'test/integration/fixtures/schemas/*.json' ],
{ onlyFiles: true }
);
const ajv = new Ajv( {
// Used for matching unknown blocks without repeating core blocks names
// with patternProperties in settings.blocks and settings.styles
Expand Down Expand Up @@ -45,4 +49,13 @@ describe( 'theme.json schema', () => {

expect( result ).toBe( true );
} );

test.each( invalidFiles )( 'invalidates schema for `%s`', ( filepath ) => {
// We want to validate the theme.json file using the local schema.
const { $schema, ...metadata } = require( filepath );

const result = ajv.validate( themeSchema, metadata );

expect( result ).toBe( false );
} );
} );

0 comments on commit fb81b62

Please sign in to comment.