From 5fce792a139d7515652596e3b842535a1f8e70d8 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Thu, 18 Jul 2024 12:15:38 -0500 Subject: [PATCH] Add tests for all propertyNames changes --- test/integration/fixtures/schemas/settings.json | 7 +++++++ .../schemas/settingsPropertiesComplete.json | 11 +++++++++++ test/integration/fixtures/schemas/styles.json | 7 +++++++ .../stylesElementsPropertiesComplete_button.json | 11 +++++++++++ .../stylesElementsPropertiesComplete_link.json | 11 +++++++++++ .../stylesPropertiesAndElementsComplete.json | 11 +++++++++++ .../schemas/stylesPropertiesComplete.json | 13 +++++++++++++ .../stylesVariationBlockPropertiesComplete.json | 15 +++++++++++++++ .../schemas/stylesVariationProperties.json | 11 +++++++++++ .../stylesVariationPropertiesComplete.json | 15 +++++++++++++++ test/integration/theme-schema.test.js | 13 +++++++++++++ 11 files changed, 125 insertions(+) create mode 100644 test/integration/fixtures/schemas/settings.json create mode 100644 test/integration/fixtures/schemas/settingsPropertiesComplete.json create mode 100644 test/integration/fixtures/schemas/styles.json create mode 100644 test/integration/fixtures/schemas/stylesElementsPropertiesComplete_button.json create mode 100644 test/integration/fixtures/schemas/stylesElementsPropertiesComplete_link.json create mode 100644 test/integration/fixtures/schemas/stylesPropertiesAndElementsComplete.json create mode 100644 test/integration/fixtures/schemas/stylesPropertiesComplete.json create mode 100644 test/integration/fixtures/schemas/stylesVariationBlockPropertiesComplete.json create mode 100644 test/integration/fixtures/schemas/stylesVariationProperties.json create mode 100644 test/integration/fixtures/schemas/stylesVariationPropertiesComplete.json diff --git a/test/integration/fixtures/schemas/settings.json b/test/integration/fixtures/schemas/settings.json new file mode 100644 index 0000000000000..0ed0548aa7b0a --- /dev/null +++ b/test/integration/fixtures/schemas/settings.json @@ -0,0 +1,7 @@ +{ + "$schema": "../../../../schemas/json/theme.json", + "version": 3, + "settings": { + "invalidAdditionalProperty": true + } +} diff --git a/test/integration/fixtures/schemas/settingsPropertiesComplete.json b/test/integration/fixtures/schemas/settingsPropertiesComplete.json new file mode 100644 index 0000000000000..e70019cc26697 --- /dev/null +++ b/test/integration/fixtures/schemas/settingsPropertiesComplete.json @@ -0,0 +1,11 @@ +{ + "$schema": "../../../../schemas/json/theme.json", + "version": 3, + "settings": { + "blocks": { + "core/button": { + "invalidAdditionalProperty": true + } + } + } +} diff --git a/test/integration/fixtures/schemas/styles.json b/test/integration/fixtures/schemas/styles.json new file mode 100644 index 0000000000000..50635d3de7e92 --- /dev/null +++ b/test/integration/fixtures/schemas/styles.json @@ -0,0 +1,7 @@ +{ + "$schema": "../../../../schemas/json/theme.json", + "version": 3, + "styles": { + "invalidAdditionalProperty": true + } +} diff --git a/test/integration/fixtures/schemas/stylesElementsPropertiesComplete_button.json b/test/integration/fixtures/schemas/stylesElementsPropertiesComplete_button.json new file mode 100644 index 0000000000000..8c596653abcb0 --- /dev/null +++ b/test/integration/fixtures/schemas/stylesElementsPropertiesComplete_button.json @@ -0,0 +1,11 @@ +{ + "$schema": "../../../../schemas/json/theme.json", + "version": 3, + "styles": { + "elements": { + "button": { + "invalidAdditionalProperty": true + } + } + } +} diff --git a/test/integration/fixtures/schemas/stylesElementsPropertiesComplete_link.json b/test/integration/fixtures/schemas/stylesElementsPropertiesComplete_link.json new file mode 100644 index 0000000000000..b8bbd11910d50 --- /dev/null +++ b/test/integration/fixtures/schemas/stylesElementsPropertiesComplete_link.json @@ -0,0 +1,11 @@ +{ + "$schema": "../../../../schemas/json/theme.json", + "version": 3, + "styles": { + "elements": { + "link": { + "invalidAdditionalProperty": true + } + } + } +} diff --git a/test/integration/fixtures/schemas/stylesPropertiesAndElementsComplete.json b/test/integration/fixtures/schemas/stylesPropertiesAndElementsComplete.json new file mode 100644 index 0000000000000..cf9e2c5689534 --- /dev/null +++ b/test/integration/fixtures/schemas/stylesPropertiesAndElementsComplete.json @@ -0,0 +1,11 @@ +{ + "$schema": "../../../../schemas/json/theme.json", + "version": 3, + "styles": { + "blocks": { + "core/button": { + "invalidAdditionalProperty": true + } + } + } +} diff --git a/test/integration/fixtures/schemas/stylesPropertiesComplete.json b/test/integration/fixtures/schemas/stylesPropertiesComplete.json new file mode 100644 index 0000000000000..0727fb2abdbe1 --- /dev/null +++ b/test/integration/fixtures/schemas/stylesPropertiesComplete.json @@ -0,0 +1,13 @@ +{ + "$schema": "../../../../schemas/json/theme.json", + "version": 3, + "styles": { + "elements": { + "button": { + ":hover": { + "invalidAdditionalProperty": true + } + } + } + } +} diff --git a/test/integration/fixtures/schemas/stylesVariationBlockPropertiesComplete.json b/test/integration/fixtures/schemas/stylesVariationBlockPropertiesComplete.json new file mode 100644 index 0000000000000..42b3e4b2174f5 --- /dev/null +++ b/test/integration/fixtures/schemas/stylesVariationBlockPropertiesComplete.json @@ -0,0 +1,15 @@ +{ + "$schema": "../../../../schemas/json/theme.json", + "version": 3, + "styles": { + "variations": { + "custom-variation": { + "blocks": { + "core/button": { + "invalidAdditionalProperty": true + } + } + } + } + } +} diff --git a/test/integration/fixtures/schemas/stylesVariationProperties.json b/test/integration/fixtures/schemas/stylesVariationProperties.json new file mode 100644 index 0000000000000..a8a28550dbeee --- /dev/null +++ b/test/integration/fixtures/schemas/stylesVariationProperties.json @@ -0,0 +1,11 @@ +{ + "$schema": "../../../../schemas/json/theme.json", + "version": 3, + "styles": { + "variations": { + "custom-variation": { + "invalidAdditionalProperty": true + } + } + } +} diff --git a/test/integration/fixtures/schemas/stylesVariationPropertiesComplete.json b/test/integration/fixtures/schemas/stylesVariationPropertiesComplete.json new file mode 100644 index 0000000000000..4fc448a22a016 --- /dev/null +++ b/test/integration/fixtures/schemas/stylesVariationPropertiesComplete.json @@ -0,0 +1,15 @@ +{ + "$schema": "../../../../schemas/json/theme.json", + "version": 3, + "styles": { + "blocks": { + "core/button": { + "variations": { + "custom-variation": { + "invalidAdditionalProperty": true + } + } + } + } + } +} diff --git a/test/integration/theme-schema.test.js b/test/integration/theme-schema.test.js index e43c893a81de8..01c95ddaefadc 100644 --- a/test/integration/theme-schema.test.js +++ b/test/integration/theme-schema.test.js @@ -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 @@ -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 ); + } ); } );