Skip to content

Commit

Permalink
Add theme.json schema tests (#44252)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Lende <[email protected]>
  • Loading branch information
alecgeatches and Alex Lende authored Sep 21, 2022
1 parent f07982a commit ffa4819
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ Border styles.
| radius | undefined | |
| style | string | |
| width | string | |
| top | undefined | |
| right | undefined | |
| bottom | undefined | |
| left | undefined | |
| top | object | color, style, width |
| right | object | color, style, width |
| bottom | object | color, style, width |
| left | object | color, style, width |

---

Expand Down
143 changes: 88 additions & 55 deletions schemas/json/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"reference": "https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-json/"
},
"settingsPropertiesAppearanceTools": {
"type": "object",
"properties": {
"appearanceTools": {
"description": "Setting that enables the following UI tools:\n\n- border: color, radius, style, width\n- color: link\n- spacing: blockGap, margin, padding\n- typography: lineHeight",
Expand All @@ -26,6 +27,7 @@
}
},
"settingsPropertiesBorder": {
"type": "object",
"properties": {
"border": {
"description": "Settings related to borders.",
Expand Down Expand Up @@ -57,6 +59,7 @@
}
},
"settingsPropertiesColor": {
"type": "object",
"properties": {
"color": {
"description": "Settings related to colors.",
Expand Down Expand Up @@ -186,6 +189,7 @@
}
},
"settingsPropertiesLayout": {
"type": "object",
"properties": {
"layout": {
"description": "Settings related to layout.",
Expand All @@ -205,6 +209,7 @@
}
},
"settingsPropertiesSpacing": {
"type": "object",
"properties": {
"spacing": {
"description": "Settings related to spacing.",
Expand Down Expand Up @@ -310,6 +315,7 @@
}
},
"settingsPropertiesTypography": {
"type": "object",
"properties": {
"typography": {
"description": "Settings related to typography.",
Expand Down Expand Up @@ -379,18 +385,25 @@
},
"fluid": {
"description": "Specifics the minimum and maximum font size value of a fluid font size. Set to `false` to bypass fluid calculations and use the static `size` value.",
"type": [ "object", "boolean" ],
"properties": {
"min": {
"description": "A min font size for fluid font size calculations in px, rem or em.",
"type": "string"
"oneOf": [
{
"type": "object",
"properties": {
"min": {
"description": "A min font size for fluid font size calculations in px, rem or em.",
"type": "string"
},
"max": {
"description": "A max font size for fluid font size calculations in px, rem or em.",
"type": "string"
}
},
"additionalProperties": false
},
"max": {
"description": "A max font size for fluid font size calculations in px, rem or em.",
"type": "string"
{
"type": "boolean"
}
},
"additionalProperties": false
]
}
},
"additionalProperties": false
Expand Down Expand Up @@ -432,7 +445,6 @@
},
"fontWeight": {
"description": "List of available font weights, separated by a space.",
"type": "string",
"default": "400",
"oneOf": [
{
Expand Down Expand Up @@ -520,6 +532,7 @@
}
},
"settingsPropertiesCustom": {
"type": "object",
"properties": {
"custom": {
"description": "Generate custom CSS custom properties of the form `--wp--custom--{key}--{nested-key}: {value};`. `camelCased` keys are transformed to `kebab-case` as to follow the CSS property naming schema. Keys at different depth levels are separated by `--`, so keys should not include `--` in the name.",
Expand Down Expand Up @@ -562,6 +575,7 @@
"type": "object",
"properties": {
"core/archives": {
"type": "object",
"description": "Archive block. Display a monthly archive of your posts. This block has no block-level settings",
"additionalProperties": false
},
Expand All @@ -575,11 +589,13 @@
"$ref": "#/definitions/settingsPropertiesComplete"
},
"core/button": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/settingsPropertiesAppearanceTools"
},
{
"type": "object",
"properties": {
"border": {
"description": "Settings related to borders.\nGutenberg plugin required.",
Expand Down Expand Up @@ -862,6 +878,7 @@
}
},
"stylesProperties": {
"type": "object",
"properties": {
"border": {
"description": "Border styles.",
Expand Down Expand Up @@ -909,60 +926,76 @@
"type": "string"
},
"top": {
"color": {
"description": "Sets the `border-top-color` CSS property.",
"type": "string"
},
"style": {
"description": "Sets the `border-top-style` CSS property.",
"type": "string"
"type": "object",
"properties": {
"color": {
"description": "Sets the `border-top-color` CSS property.",
"type": "string"
},
"style": {
"description": "Sets the `border-top-style` CSS property.",
"type": "string"
},
"width": {
"description": "Sets the `border-top-width` CSS property.",
"type": "string"
}
},
"width": {
"description": "Sets the `border-top-width` CSS property.",
"type": "string"
}
"additionalProperties": false
},
"right": {
"color": {
"description": "Sets the `border-right-color` CSS property.",
"type": "string"
},
"style": {
"description": "Sets the `border-right-style` CSS property.",
"type": "string"
"type": "object",
"properties": {
"color": {
"description": "Sets the `border-right-color` CSS property.",
"type": "string"
},
"style": {
"description": "Sets the `border-right-style` CSS property.",
"type": "string"
},
"width": {
"description": "Sets the `border-right-width` CSS property.",
"type": "string"
}
},
"width": {
"description": "Sets the `border-right-width` CSS property.",
"type": "string"
}
"additionalProperties": false
},
"bottom": {
"color": {
"description": "Sets the `border-bottom-color` CSS property.",
"type": "string"
},
"style": {
"description": "Sets the `border-bottom-style` CSS property.",
"type": "string"
"type": "object",
"properties": {
"color": {
"description": "Sets the `border-bottom-color` CSS property.",
"type": "string"
},
"style": {
"description": "Sets the `border-bottom-style` CSS property.",
"type": "string"
},
"width": {
"description": "Sets the `border-bottom-width` CSS property.",
"type": "string"
}
},
"width": {
"description": "Sets the `border-bottom-width` CSS property.",
"type": "string"
}
"additionalProperties": false
},
"left": {
"color": {
"description": "Sets the `border-left-color` CSS property.",
"type": "string"
},
"style": {
"description": "Sets the `border-left-style` CSS property.",
"type": "string"
"type": "object",
"properties": {
"color": {
"description": "Sets the `border-left-color` CSS property.",
"type": "string"
},
"style": {
"description": "Sets the `border-left-style` CSS property.",
"type": "string"
},
"width": {
"description": "Sets the `border-left-width` CSS property.",
"type": "string"
}
},
"width": {
"description": "Sets the `border-left-width` CSS property.",
"type": "string"
}
"additionalProperties": false
}
},
"additionalProperties": false
Expand Down
27 changes: 27 additions & 0 deletions test/integration/theme-schema.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* External dependencies
*/
import Ajv from 'ajv-draft-04';

/**
* Internal dependencies
*/
import themeSchema from '../../schemas/json/theme.json';

describe( 'theme.json schema', () => {
const ajv = new Ajv( {
// Used for matching unknown blocks without repeating core blocks names
// with patternProperties in settings.blocks and settings.styles
allowMatchingProperties: true,
} );

it( 'strictly adheres to the draft-04 meta schema', () => {
// Use ajv.compile instead of ajv.validateSchema to validate the schema
// because validateSchema only checks syntax, whereas, compile checks
// if the schema is semantically correct with strict mode.
// See https://github.com/ajv-validator/ajv/issues/1434#issuecomment-822982571
const result = ajv.compile( themeSchema );

expect( result.errors ).toBe( null );
} );
} );

0 comments on commit ffa4819

Please sign in to comment.