Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow visible_if on more valid settings types #918

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 42 additions & 14 deletions schemas/theme/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,10 @@
"additionalProperties": false
},
"number": {
"allOf": [{ "$ref": "#/definitions/inputSettingsStandardAttributes" }],
"allOf": [
{ "$ref": "#/definitions/inputSettingsStandardAttributes" },
{ "$ref": "#/definitions/conditionalSetting" }
],
"properties": {
"type": {
"const": "number",
Expand All @@ -643,7 +646,8 @@
"default": { "type": "number" },
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": true
},
"additionalProperties": false
},
Expand Down Expand Up @@ -701,7 +705,10 @@
},

"radio": {
"allOf": [{ "$ref": "#/definitions/inputSettingsStandardAttributes" }],
"allOf": [
{ "$ref": "#/definitions/inputSettingsStandardAttributes" },
{ "$ref": "#/definitions/conditionalSetting" }
],
"properties": {
"type": {
"const": "radio",
Expand All @@ -715,7 +722,8 @@
"options": { "$ref": "#/definitions/options" },
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": true
},
"required": ["options"],
"additionalProperties": false
Expand Down Expand Up @@ -841,7 +849,10 @@
},

"style.layout_panel": {
"allOf": [{ "$ref": "#/definitions/inputSettingsStandardAttributes" }],
"allOf": [
{ "$ref": "#/definitions/inputSettingsStandardAttributes" },
{ "$ref": "#/definitions/conditionalSetting" }
],
"properties": {
"type": {
"const": "style.layout_panel",
Expand All @@ -866,13 +877,17 @@
},
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": true
},
"additionalProperties": false
},

"style.size_panel": {
"allOf": [{ "$ref": "#/definitions/inputSettingsStandardAttributes" }],
"allOf": [
{ "$ref": "#/definitions/inputSettingsStandardAttributes" },
{ "$ref": "#/definitions/conditionalSetting" }
],
"properties": {
"type": {
"const": "style.size_panel",
Expand All @@ -897,13 +912,17 @@
},
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": true
},
"additionalProperties": false
},

"style.spacing_panel": {
"allOf": [{ "$ref": "#/definitions/inputSettingsStandardAttributes" }],
"allOf": [
{ "$ref": "#/definitions/inputSettingsStandardAttributes" },
{ "$ref": "#/definitions/conditionalSetting" }
],
"properties": {
"type": {
"const": "style.spacing_panel",
Expand All @@ -928,13 +947,17 @@
},
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": true
},
"additionalProperties": false
},

"text": {
"allOf": [{ "$ref": "#/definitions/inputSettingsStandardAttributes" }],
"allOf": [
{ "$ref": "#/definitions/inputSettingsStandardAttributes" },
{ "$ref": "#/definitions/conditionalSetting" }
],
"properties": {
"type": {
"const": "text",
Expand All @@ -950,7 +973,8 @@
},
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": true
},
"additionalProperties": false
},
Expand Down Expand Up @@ -979,7 +1003,10 @@
},

"textarea": {
"allOf": [{ "$ref": "#/definitions/inputSettingsStandardAttributes" }],
"allOf": [
{ "$ref": "#/definitions/inputSettingsStandardAttributes" },
{ "$ref": "#/definitions/conditionalSetting" }
],
"properties": {
"type": {
"const": "textarea",
Expand All @@ -995,7 +1022,8 @@
},
"label": true,
"info": true,
"id": true
"id": true,
"visible_if": true
},
"additionalProperties": false
},
Expand Down
79 changes: 56 additions & 23 deletions tests/section.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import set from 'lodash.set';
import { assert, describe, expect, it } from 'vitest';
import { SETTINGS_TYPES_NOT_SUPPORTING_VISIBLE_IF } from './test-constants';
import { INPUT_SETTING_TYPES, SETTINGS_TYPES_NOT_SUPPORTING_VISIBLE_IF } from './test-constants';
import { complete, getService, hover, loadFixture, validateSchema } from './test-helpers';

const sectionSchema1 = loadFixture('section-schema-1.json');
Expand Down Expand Up @@ -29,7 +29,7 @@ describe('JSON Schema validation of Liquid theme section schema tags', () => {
sectionSchema5,
sectionSchema6,
sectionNestedBlocks,
sectionSchemaPresetBlocksAsHash
sectionSchemaPresetBlocksAsHash,
];
for (const sectionSchema of schemas) {
const diagnostics = await validate('sections/section.liquid', sectionSchema);
Expand Down Expand Up @@ -211,31 +211,64 @@ describe('JSON Schema validation of Liquid theme section schema tags', () => {
});

it('should validate section schema with conditional settings', async () => {
const sectionSchemaConditionalSettings = loadFixture('section-schema-conditional-settings.json');
const sectionSchemaConditionalSettings = loadFixture(
'section-schema-conditional-settings.json',
);
const diagnostics = await validate('sections/section.liquid', sectionSchemaConditionalSettings);
expect(diagnostics).toStrictEqual([]);
});

it.each(SETTINGS_TYPES_NOT_SUPPORTING_VISIBLE_IF)('should not allow visible_if on %s setting type', async (settingType) => {
const schema = {
settings: [
{
type: settingType,
id: 'test_setting',
label: 'Test Setting',
visible_if: '{{ section.settings.some_setting }}'
}
]
};

const diagnostics = await validate('sections/section.liquid', schema);
expect(diagnostics).toContainEqual(
expect.objectContaining({
message: 'Property visible_if is not allowed.',
severity: 1
})
);
});
const settingsTypesSupportingVisibleIf = INPUT_SETTING_TYPES.filter(
(settingType) =>
!SETTINGS_TYPES_NOT_SUPPORTING_VISIBLE_IF.concat('color_scheme_group').includes(settingType),
);

it.each(settingsTypesSupportingVisibleIf)(
'should allow visible_if on %s setting type',
async (settingType) => {
const schema = {
settings: [
{
type: settingType,
id: 'test_setting',
label: 'Test Setting',
visible_if: '{{ section.settings.some_setting }}',
},
],
};

const diagnostics = await validate('sections/section.liquid', schema);
expect(diagnostics).not.toContainEqual(
expect.objectContaining({
message: 'Property visible_if is not allowed.',
}),
);
},
);

it.each(SETTINGS_TYPES_NOT_SUPPORTING_VISIBLE_IF)(
'should not allow visible_if on %s setting type',
async (settingType) => {
const schema = {
settings: [
{
type: settingType,
id: 'test_setting',
label: 'Test Setting',
visible_if: '{{ section.settings.some_setting }}',
},
],
};

const diagnostics = await validate('sections/section.liquid', schema);
expect(diagnostics).toContainEqual(
expect.objectContaining({
message: 'Property visible_if is not allowed.',
severity: 1,
}),
);
},
);

it('should complete the type property with the generic docs', async () => {
const result = await complete(
Expand Down