-
Notifications
You must be signed in to change notification settings - Fork 9
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
Conditional theme settings and split theme-settings unit tests into separate suites #899
Conversation
57cd221
to
a5f115f
Compare
a5f115f
to
05b0d74
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻 test refactors make sense to me though I can't comment on the schemas/theme/setting.json
changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, nice work! A few questions/suggestions, but you're much more of a maintainer for this repo than I am so I think it's your call.
expect(diagnostics).toStrictEqual([]); | ||
}); | ||
|
||
it.each(SETTINGS_TYPES_NOT_SUPPORTING_VISIBLE_IF)('should not allow visible_if on %s setting type', async (settingType) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how feasible this is so it's just a question — but rather than
for each forbidden setting type, test that the diagnostic correctly forbids it
maybe it should be
gather the diagnostic result for every setting type, and check that the result list contains exactly the list of forbidden types
I feel like that's maybe testing a more useful property. (I know you already have the handwritten schemas with allowed conditional settings, but if there's a list of all settings types at hand somewhere this could bolster the handwritten stuff with a broader property-based test.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting way to look at it! I had considered an approach similar to what you have in mind, but the issue came down to consciously handwriting invalid settings in with our valid ones. My concern was that it would make that fixture a bit too difficult to scan and compromises its value as a self documenting example of valid settings.
The approach I opted for instead is to include all valid setting types that support conditional settings within the theme-block-conditional-settings.json
fixture and then only targeting the ones we explicitly do not wish to support (as listed in Clauderic's decision figjam).
tests/theme_block.spec.ts
Outdated
const SETTINGS_TYPES_NOT_SUPPORTING_VISIBLE_IF = [ | ||
'article', | ||
'blog', | ||
'collection', | ||
'collection_list', | ||
'metaobject', | ||
'metaobject_list', | ||
'page', | ||
'product', | ||
'product_list', | ||
]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth lifting to a shared file within the tests dir since it's repeated multiple times?
tests/theme-settings/general.spec.ts
Outdated
const inputSettingTypes = [ | ||
'article', | ||
'blog', | ||
'checkbox', | ||
'collection_list', | ||
'collection', | ||
'color_background', | ||
'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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe worth lifting this to the same shared file. and i guess this would be the list of all settings types that could potentially be validated against the set of settings types not supporting visible_if
?
{ | ||
message: 'Incorrect type. Expected "array".', | ||
severity: 1, | ||
range: expect.objectContaining({ | ||
start: expect.objectContaining({ | ||
character: expect.any(Number), | ||
line: expect.any(Number), | ||
}), | ||
end: expect.objectContaining({ | ||
character: expect.any(Number), | ||
line: expect.any(Number), | ||
}), | ||
}), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So quite a lot of the tests that were added look like this:
const result = doSomething();
expect(result).toStrictEqual(
/* some object with an exact shape including some specific message */
);
These are basically just snapshot tests, and to ease writing and maintenance I'd ask if we can't just use the snapshot API. It's not super well known, but snapshots can use expect.any(Number)
matchers just like you're doing here (that link is towards the Jest docs since they're more detailed, but Vitest supports the same functionality).
The benefit is that if a diagnostic message changes, we can just update the snapshots automatically and then only need to validate the git diff. It also makes it a lot quicker to add new test cases while sticking to the existing pattern. Up to you, though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im scared of making too many drastic changes to the existing unit tests that I refactored so I will be avoiding this one simply to limit the churn Ive done here 😅
Whats in this
https://vault.shopify.io/gsd/projects/44140-Conditional-Settings-for-Themes
Few changes here:
Closes https://github.com/Shopify/shopify/issues/572105