Skip to content

Commit

Permalink
Update setting docs (#687)
Browse files Browse the repository at this point in the history
* Update setting documentation

* Ignore LocalHistory files

* Add tests

* Update list settings limit to integers
  • Loading branch information
PhilippeCollin authored Jul 18, 2024
1 parent 31a9764 commit 3ea5dc5
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
node_modules/
.vscode/description.code-snippets

# VS Code extensions
# Local history
.history
59 changes: 57 additions & 2 deletions schemas/theme/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"inline_richtext",
"link_list",
"liquid",
"metaobject",
"metaobject_list",
"number",
"page",
"paragraph",
Expand Down Expand Up @@ -114,6 +116,14 @@
"if": { "required": ["type"], "properties": { "type": { "const": "liquid" } } },
"then": { "$ref": "#/definitions/liquid" }
},
{
"if": { "required": ["type"], "properties": { "type": { "const": "metaobject" } } },
"then": { "$ref": "#/definitions/metaobject" }
},
{
"if": { "required": ["type"], "properties": { "type": { "const": "metaobject_list" } } },
"then": { "$ref": "#/definitions/metaobject_list" }
},
{
"if": { "required": ["type"], "properties": { "type": { "const": "number" } } },
"then": { "$ref": "#/definitions/number" }
Expand Down Expand Up @@ -258,7 +268,7 @@
"markdownDescription": "A setting of type `collection_list` outputs a collection picker field that's automatically populated with the available collections for the store. You can use these fields to capture multiple collections, such as a group of collections to feature on the homepage.\n\n---\n\n[Shopify reference](https://shopify.dev/docs/themes/architecture/settings/input-settings#collection_list)"
},
"limit": {
"type": "number",
"type": "integer",
"description": "The maximum number that the merchant can select. The default limit, and the maximum limit you can set, is 50."
},
"default": true,
Expand Down Expand Up @@ -527,6 +537,51 @@
"additionalProperties": false
},

"metaobject": {
"allOf": [{ "$ref": "#/definitions/inputSettingsStandardAttributes" }],
"properties": {
"type": {
"const": "metaobject",
"description": "A setting of type metaobject outputs a metaobject picker field that's automatically populated with the compatible metaobject entries for the store. You can use these fields to capture a metaobject entry selection for a known metaobject type.",
"markdownDescription": "A setting of type `metaobject` outputs a metaobject picker field that's automatically populated with the compatible metaobject entries for the store. You can use these fields to capture a metaobject entry selection for a known metaobject type. \n\n---\n\n[Shopify reference](https://shopify.dev/docs/themes/architecture/settings/input-settings#metaobject)"
},
"metaobject_type": {
"type": "string",
"description": "The metaobject type allowed by the picker."
},
"default": true,
"label": true,
"info": true,
"id": true
},
"required": ["metaobject_type"],
"additionalProperties": false
},

"metaobject_list": {
"allOf": [{ "$ref": "#/definitions/inputSettingsStandardAttributes" }],
"properties": {
"type": {
"const": "metaobject_list",
"description": "A setting of type metaobject_list outputs a metaobject picker field that's automatically populated with the compatible metaobject entries for the store. You can use these fields to capture multiple metaobject entry selections for a known metaobject type.",
"markdownDescription": "A setting of type `metaobject_list` outputs a metaobject picker field that's automatically populated with the compatible metaobject entries for the store. You can use these fields to capture multiple metaobject entry selections for a known metaobject type.\n\n---\n\n[Shopify reference](https://shopify.dev/docs/themes/architecture/settings/input-settings#metaobject_list)"
},
"metaobject_type": {
"type": "string",
"description": "The metaobject type allowed by the picker."
},
"limit": {
"type": "integer",
"description": "The maximum number that the merchant can select. The default limit, and the maximum limit you can set, is 50."
},
"default": true,
"label": true,
"info": true,
"id": true
},
"required": ["metaobject_type"],
"additionalProperties": false
},
"number": {
"allOf": [{ "$ref": "#/definitions/inputSettingsStandardAttributes" }],
"properties": {
Expand Down Expand Up @@ -588,7 +643,7 @@
"markdownDescription": "A setting of type `product_list` outputs a product picker field that's automatically populated with the available products for the store. You can use these fields to capture multiple products, such as a group of products to feature on the homepage.\n\n---\n\n[Shopify reference](https://shopify.dev/docs/themes/architecture/settings/input-settings#product_list)"
},
"limit": {
"type": "number",
"type": "integer",
"description": "The maximum number that the merchant can select. The default limit, and the maximum limit you can set, is 50."
},
"default": true,
Expand Down
163 changes: 152 additions & 11 deletions tests/theme_settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,44 @@ const themeSettingsAllSettings = loadFixture('theme-settings-all-settings.json')
const themeSettingsDawn = loadFixture('theme-settings-dawn.json');

const inputSettingTypes = [
'checkbox',
'number',
'radio',
'range',
'select',
'text',
'textarea',
'article',
'blog',
'collection',
'checkbox',
'collection_list',
'color',
'collection',
'color_background',
'color_scheme',
'color_scheme_group',
'color_scheme',
'color',
'font_picker',
'html',
'image_picker',
'inline_richtext',
'link_list',
'liquid',
'metaobject',
'metaobject_list',
'number',
'page',
'product_list',
'product',
'radio',
'range',
'richtext',
'select',
'style.layout_panel',
'style.size_panel',
'style.spacing_panel',
'text_alignment',
'text',
'textarea',
'url',
'video_url',
'video',
] as const;

const resourceListSettingTypes = ['product_list', 'collection_list', 'metaobject_list'] as const;

const sidebarSettingTypes = ['header', 'paragraph'] as const;

const validate = validateSchema();
Expand Down Expand Up @@ -404,7 +408,7 @@ describe('Module: theme settings validation (config/settings_schema.json)', () =
"padding-block": "10px 20px",
"margin-top": "0px",
"margin-inline": "20px",
"margin-inline-end": "1px"
"margin-inline-end": "1px"
}
}
},
Expand Down Expand Up @@ -580,4 +584,141 @@ describe('Module: theme settings validation (config/settings_schema.json)', () =
]);
});
});

describe.each(resourceListSettingTypes)('Resource list setting: %s', (setting_type) => {
it(`${setting_type} does not require a limit`, async () => {
const metaobject_type = setting_type === 'metaobject_list' ? `, "metaobject_type": "author"` : '';
const settings = `[
{
"name": "some category",
"settings": [
{
"type": "${setting_type}",
"id": "${setting_type}",
"label": "${setting_type}"
${metaobject_type}
}
]
}
]`;

const diagnostics = await validate('config/settings_schema.json', settings);

expect(diagnostics).toHaveLength(0);
});

it(`${setting_type} allows having a numeric limit`, async () => {
const metaobject_type = setting_type === 'metaobject_list' ? `, "metaobject_type": "author"` : '';
const settings = `[
{
"name": "some category",
"settings": [
{
"type": "${setting_type}",
"id": "${setting_type}",
"label": "${setting_type}",
"limit": 10
${metaobject_type}
}
]
}
]`;

const diagnostics = await validate('config/settings_schema.json', settings);

expect(diagnostics).not.toContainEqual(
expect.objectContaining({
message: expect.stringContaining('limit'),
})
);
});
});

describe('Unit: metaobject settings', () => {
it('metaobject setting requires a metaobject_type', async () => {
const settings = `[
{
"name": "some category",
"settings": [
{
"type": "metaobject",
"id": "metaobject",
"label": "Metaobject"
}
]
}
]`;

const diagnostics = await validate('config/settings_schema.json', settings);

expect(diagnostics).toStrictEqual([
expect.objectContaining({
message: `Missing property "metaobject_type".`,
}),
]);
});

it('metaobject_list setting requires a metaobject_type', async () => {
const settings = `[
{
"name": "some category",
"settings": [
{
"type": "metaobject_list",
"id": "metaobject_list",
"label": "metaobject list"
}
]
}
]`;

const diagnostics = await validate('config/settings_schema.json', settings);

expect(diagnostics).toStrictEqual([
expect.objectContaining({
message: `Missing property "metaobject_type".`,
}),
]);
});

it('metaobject setting allows a valid metaobject_type', async () => {
const settings = `[
{
"name": "some category",
"settings": [
{
"type": "metaobject",
"id": "metaobject",
"label": "Metaobject",
"metaobject_type": "author"
}
]
}
]`;

const diagnostics = await validate('config/settings_schema.json', settings);

expect(diagnostics).toHaveLength(0);
});

it('metaobject_list setting allows a valid metaobject_type', async () => {
const settings = `[
{
"name": "some category",
"settings": [
{
"type": "metaobject_list",
"id": "metaobject_list",
"label": "Metaobject list",
"metaobject_type": "author"
}
]
}
]`;

const diagnostics = await validate('config/settings_schema.json', settings);

expect(diagnostics).toHaveLength(0);
});
});
});

0 comments on commit 3ea5dc5

Please sign in to comment.