-
Notifications
You must be signed in to change notification settings - Fork 3
chore(i18n-array): adds test to prepare migration #561
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
base: main
Are you sure you want to change the base?
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
e704bb7 to
a32ebc9
Compare
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
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.
Pull request overview
Adds a comprehensive unit + component test suite (and supporting test utilities/config) for sanity-plugin-internationalized-array, aiming to keep tests resilient during the upcoming LANGUAGE_FIELD_NAME migration from '_key' to 'language'.
Changes:
- Added extensive new unit/component tests plus shared test helpers and Vitest jsdom setup.
- Refactored a few internals to accept
schemaTypeName(string) and to consistently referenceLANGUAGE_FIELD_NAMEin logic/tests. - Added/updated documentation comments and introduced test dependencies (
@testing-library/*,jsdom) and lockfile updates.
Reviewed changes
Copilot reviewed 37 out of 38 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Updates dependency graph for new testing deps and jsdom version resolution. |
| plugins/sanity-plugin-internationalized-array/package.json | Adds @testing-library/jest-dom, @testing-library/react, and jsdom for component testing. |
| plugins/sanity-plugin-internationalized-array/vitest.config.ts | Enables jsdom environment and registers test setup file. |
| plugins/sanity-plugin-internationalized-array/src/test/setup.ts | Adds jest-dom matchers and matchMedia mock for jsdom. |
| plugins/sanity-plugin-internationalized-array/src/test/helpers.ts | Adds shared MOCK_LANGUAGES and factories that respect LANGUAGE_FIELD_NAME. |
| plugins/sanity-plugin-internationalized-array/src/test/component-helpers.tsx | Adds a ThemeWrapper for @sanity/ui component tests. |
| plugins/sanity-plugin-internationalized-array/src/utils/getLanguageDisplay.ts | Adds doc comment describing supported display modes and fallback behavior. |
| plugins/sanity-plugin-internationalized-array/src/utils/getLanguageDisplay.test.ts | Adds unit tests for getLanguageDisplay. |
| plugins/sanity-plugin-internationalized-array/src/utils/getDocumentsToTranslate.ts | Adds doc comment clarifying traversal and matching rules. |
| plugins/sanity-plugin-internationalized-array/src/utils/getDocumentsToTranslate.test.ts | Adds unit tests covering flat/nested traversal and underscore-key skipping. |
| plugins/sanity-plugin-internationalized-array/src/utils/createValueSchemaTypeName.ts | Removes helper and inlines schema-type-name handling elsewhere. |
| plugins/sanity-plugin-internationalized-array/src/utils/createAddLanguagePatches.ts | Switches to schemaTypeName input and adds doc comment. |
| plugins/sanity-plugin-internationalized-array/src/utils/createAddLanguagePatches.test.ts | Adds unit tests for patch creation and ordering rules. |
| plugins/sanity-plugin-internationalized-array/src/utils/createAddAllTitle.ts | Adds doc comment. |
| plugins/sanity-plugin-internationalized-array/src/utils/createAddAllTitle.test.ts | Adds unit tests for add-all button title text. |
| plugins/sanity-plugin-internationalized-array/src/utils/checkAllLanguagesArePresent.ts | Refactors language presence check implementation. |
| plugins/sanity-plugin-internationalized-array/src/utils/checkAllLanguagesArePresent.test.ts | Adds unit tests for presence check behavior and edge cases. |
| plugins/sanity-plugin-internationalized-array/src/components/getToneFromValidation.ts | Adds doc comment. |
| plugins/sanity-plugin-internationalized-array/src/components/getToneFromValidation.test.ts | Adds unit tests for tone mapping and precedence. |
| plugins/sanity-plugin-internationalized-array/src/components/getSelectedValue.ts | Adds doc comment. |
| plugins/sanity-plugin-internationalized-array/src/components/getSelectedValue.test.ts | Adds unit tests for select extraction and reference filtering. |
| plugins/sanity-plugin-internationalized-array/src/components/createFieldName.ts | Adds doc comments for naming helpers. |
| plugins/sanity-plugin-internationalized-array/src/components/createFieldName.test.ts | Adds unit tests for field/type naming behavior. |
| plugins/sanity-plugin-internationalized-array/src/components/AddButtons.tsx | Changes click API to pass languageId and adds test IDs + doc comment. |
| plugins/sanity-plugin-internationalized-array/src/components/AddButtons.test.tsx | Adds component tests for rendering/disabled state/display modes/icon rules. |
| plugins/sanity-plugin-internationalized-array/src/components/InternationalizedInput.tsx | Adds doc comment explaining behavior. |
| plugins/sanity-plugin-internationalized-array/src/components/InternationalizedInput.test.tsx | Adds component tests for label/change button/migration/remove disabled/spinner. |
| plugins/sanity-plugin-internationalized-array/src/components/InternationalizedField.tsx | Adds doc comments and clarifies language extraction behavior. |
| plugins/sanity-plugin-internationalized-array/src/components/InternationalizedField.test.tsx | Adds component tests for title hiding and rendering path selection. |
| plugins/sanity-plugin-internationalized-array/src/components/InternationalizedArray.tsx | Refactors add-language handler + added-languages detection; adds tests and test IDs. |
| plugins/sanity-plugin-internationalized-array/src/components/InternationalizedArray.test.tsx | Adds large component test suite for add buttons, reorder, defaults, filtering, etc. |
| plugins/sanity-plugin-internationalized-array/src/components/DocumentAddButtons.tsx | Refactors click API to pass languageId and adds doc comment. |
| plugins/sanity-plugin-internationalized-array/src/components/DocumentAddButtons.test.tsx | Adds component tests for heading, toasts, patch generation, and filtering. |
| plugins/sanity-plugin-internationalized-array/src/schema/array.ts | Removes explicit return type annotation and adds validation tests via new suite. |
| plugins/sanity-plugin-internationalized-array/src/schema/array.test.ts | Adds unit tests for schema generation and custom validation behavior. |
| plugins/sanity-plugin-internationalized-array/src/schema/object.ts | Removes explicit return type annotation; aligns with schema tests. |
| plugins/sanity-plugin-internationalized-array/src/schema/object.test.ts | Adds unit tests for object schema generation + preview select behavior. |
| plugins/sanity-plugin-internationalized-array/src/fieldActions/index.ts | Updates to pass schemaTypeName into createAddLanguagePatches. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
plugins/sanity-plugin-internationalized-array/src/utils/checkAllLanguagesArePresent.ts
Outdated
Show resolved
Hide resolved
plugins/sanity-plugin-internationalized-array/src/components/DocumentAddButtons.tsx
Outdated
Show resolved
Hide resolved
|
|
||
| export type ArrayFieldOptions = Pick<ArrayFactoryConfig, 'apiVersion' | 'select' | 'languages'> | ||
|
|
||
| export default (config: ArrayFactoryConfig): FieldDefinition<'array'> => { |
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 type definition is not correct, the type returned by the defineField function is broader, same with the schema/object file
Review by miriad.techStatus: ✅ Approved SummaryPR #561 adds comprehensive test coverage for Test Files Added (16 total)
Migration-Proof Design1. Test Helper Uses
|
| Test | File | What It Guards |
|---|---|---|
| "disables buttons for languages already present in value via LANGUAGE_FIELD_NAME" | AddButtons.test.tsx | Language lookup uses correct field |
| "correctly identifies existing languages regardless of LANGUAGE_FIELD_NAME value" | AddButtons.test.tsx | Field abstraction works |
| "tracks language keys in use from parent value via LANGUAGE_FIELD_NAME" | InternationalizedInput.test.tsx | Parent value parsing |
| "extracts added languages using LANGUAGE_FIELD_NAME with _key fallback" | InternationalizedArray.test.tsx | Add button disabled state |
| "creates patches for specified addLanguageKeys" | createAddLanguagePatches.test.ts | New items use correct field |
What Happens When We Migrate
When LANGUAGE_FIELD_NAME changes from '_key' to 'language':
- Tests will fail if code doesn't use the constant - Any hardcoded
_keyfor language identification will be caught - Tests will pass if code correctly uses
LANGUAGE_FIELD_NAME- The abstraction layer works - Test data automatically adapts -
createValue()generates correct structure for either mode
Conclusion
PR #561 provides excellent test coverage that will:
- Catch regressions during the migration
- Validate the
LANGUAGE_FIELD_NAMEabstraction works - Ensure consistent behavior before and after the change
Approved for merge.
…ocumentAddButtons.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Pull request overview
Copilot reviewed 37 out of 38 changed files in this pull request and generated 2 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Adds unit and component tests to secure the upcoming migration of
LANGUAGE_FIELD_NAMEfrom '_key' to 'language'. All test data is generated dynamically viaLANGUAGE_FIELD_NAMEso tests remain valid after the constant changes.Test infrastructure
src/test/helpers.tsMOCK_LANGUAGES,createValue()/createValues()factories that adapt toLANGUAGE_FIELD_NAMEsrc/test/component-helpers.tsxThemeWrapperproviding@sanity/uiThemeProviderfor component renderingsrc/test/setup.ts@testing-library/jest-dommatchers +matchMediamock for jsdomTests by file
utils/checkAllLanguagesArePresent.test.tsutils/createAddLanguagePatches.test.ts_typeutils/getLanguageDisplay.test.tscodeOnly,titleOnly,titleAndCodemodes, fallbackutils/createAddAllTitle.test.tsutils/getDocumentsToTranslate.test.tscomponents/getToneFromValidation.test.tscomponents/getSelectedValue.test.tscomponents/createFieldName.test.tspascalCaseconversion, array/object name generation with/without Value suffixschema/array.test.tsschema/object.test.tspreview.select.subtitleusesLANGUAGE_FIELD_NAMEcomponents/AddButtons.test.tsxLANGUAGE_FIELD_NAME, readOnly, display modes, icon visibility vsMAX_COLUMNScomponents/InternationalizedField.test.tsxgetLanguageIdextraction viaLANGUAGE_FIELD_NAME, title hiding, schema type rendering pathscomponents/InternationalizedInput.test.tsxcomponents/InternationalizedArray.test.tsxcomponents/DocumentAddButtons.test.tsxLANGUAGE_FIELD_NAME, duplicate filteringWhat to review
Testing