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 authored and scruffian committed Jul 19, 2024
1 parent b7082ef commit 5fce792
Show file tree
Hide file tree
Showing 11 changed files with 125 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
}
}
}
}
13 changes: 13 additions & 0 deletions test/integration/fixtures/schemas/stylesPropertiesComplete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "../../../../schemas/json/theme.json",
"version": 3,
"styles": {
"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 5fce792

Please sign in to comment.