Skip to content

Conversation

@pedrobonamin
Copy link
Contributor

Description

Adds unit and component tests to secure the upcoming migration of LANGUAGE_FIELD_NAME from '_key' to 'language'. All test data is generated dynamically via LANGUAGE_FIELD_NAME so tests remain valid after the constant changes.

Test infrastructure

File Purpose
src/test/helpers.ts Shared MOCK_LANGUAGES, createValue() / createValues() factories that adapt to LANGUAGE_FIELD_NAME
src/test/component-helpers.tsx ThemeWrapper providing @sanity/ui ThemeProvider for component rendering
src/test/setup.ts @testing-library/jest-dom matchers + matchMedia mock for jsdom

Tests by file

File Tests What it covers
utils/checkAllLanguagesArePresent.test.ts 9 All present, missing, undefined, extra items, empty arrays, order, duplicates
utils/createAddLanguagePatches.test.ts 9 Patch creation for specific keys, all missing, skip existing, insertion order, correct _type
utils/getLanguageDisplay.test.ts 5 codeOnly, titleOnly, titleAndCode modes, fallback
utils/createAddAllTitle.test.ts 5 Button title for no value, single/multiple languages, missing singular/plural
utils/getDocumentsToTranslate.test.ts 9 Flat/nested internationalized arrays, underscore key skipping, path building
components/getToneFromValidation.test.ts 5 Error/warning/info mapping to CardTone, error precedence
components/getSelectedValue.test.ts 8 Value extraction, nested paths, reference filtering, edge cases
components/createFieldName.test.ts 8 pascalCase conversion, array/object name generation with/without Value suffix
schema/array.test.ts 15 Schema generation, custom validation: excess items, invalid keys, duplicates, async language resolution
schema/object.test.ts 9 Object schema naming, field structure, preview.select.subtitle uses LANGUAGE_FIELD_NAME
components/AddButtons.test.tsx 11 Button rendering, disabled state via LANGUAGE_FIELD_NAME, readOnly, display modes, icon visibility vs MAX_COLUMNS
components/InternationalizedField.test.tsx 8 getLanguageId extraction via LANGUAGE_FIELD_NAME, title hiding, schema type rendering paths
components/InternationalizedInput.test.tsx 8 Language label display, invalid key detection, migration state, default language remove button, spinner
components/InternationalizedArray.test.tsx 17 Add buttons visibility, no-translations message, auto-reorder, auto-add defaults, language filter, readOnly, Feedback
components/DocumentAddButtons.test.tsx 5 Heading rendering, error toasts, patch creation with LANGUAGE_FIELD_NAME, duplicate filtering
Total new 131

What to review

Testing

Copilot AI review requested due to automatic review settings February 9, 2026 12:18
@changeset-bot
Copy link

changeset-bot bot commented Feb 9, 2026

⚠️ No Changeset found

Latest commit: c18565f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Feb 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
plugins-studio Ready Ready Preview, Comment Feb 9, 2026 2:21pm

Request Review

@socket-security
Copy link

socket-security bot commented Feb 9, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​jsdom@​28.0.09610010094100

View full report

Copy link
Contributor

Copilot AI left a 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 reference LANGUAGE_FIELD_NAME in 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.


export type ArrayFieldOptions = Pick<ArrayFactoryConfig, 'apiVersion' | 'select' | 'languages'>

export default (config: ArrayFactoryConfig): FieldDefinition<'array'> => {
Copy link
Contributor Author

@pedrobonamin pedrobonamin Feb 9, 2026

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

@pedrobonamin
Copy link
Contributor Author

Review by miriad.tech

Status: ✅ Approved
Reviewer: @opal (AI Agent)


Summary

PR #561 adds comprehensive test coverage for sanity-plugin-internationalized-array that will guard the migration from _key to a dedicated language field. The tests are well-designed to automatically adapt when LANGUAGE_FIELD_NAME changes.


Test Files Added (16 total)

File Test Count Purpose
components/AddButtons.test.tsx 11 Button rendering, disabled states, click handling
components/InternationalizedInput.test.tsx 7 Language label display, change menu, remove button
components/InternationalizedArray.test.tsx 18 Array ordering, add buttons, default languages
components/InternationalizedField.test.tsx - Field wrapper behavior
components/DocumentAddButtons.test.tsx - Document-level add buttons
components/getToneFromValidation.test.ts - Validation tone helper
components/getSelectedValue.test.ts - Document value selector
components/createFieldName.test.ts - Field name generation
schema/array.test.ts 14 Validation rules, language checking
schema/object.test.ts - Object schema configuration
utils/createAddLanguagePatches.test.ts 9 Patch creation with correct field
utils/checkAllLanguagesArePresent.test.ts 9 Language presence validation
utils/getLanguageDisplay.test.ts - Display formatting
utils/getDocumentsToTranslate.test.ts - Translation discovery
utils/createAddAllTitle.test.ts - Button title generation
index.test.ts 1 Package exports stability

Migration-Proof Design

1. Test Helper Uses LANGUAGE_FIELD_NAME

The key to migration-proof tests is in test/helpers.ts:

export function createValue(
  languageId: string,
  opts?: {value?: unknown; type?: string},
): Value & Record<string, unknown> {
  return {
    _type: opts?.type ?? 'internationalizedArrayStringValue',
    [LANGUAGE_FIELD_NAME]: languageId,
    ...(LANGUAGE_FIELD_NAME === "_key" ? {} : {_key: `key-${languageId}`}),
    value: opts?.value,
  }
}

When LANGUAGE_FIELD_NAME = '_key' (current):

{ "_key": "en", "_type": "...", "value": "..." }

When LANGUAGE_FIELD_NAME = 'language' (after migration):

{ "_key": "key-en", "language": "en", "_type": "...", "value": "..." }

2. Assertions Use the Constant

Tests assert against LANGUAGE_FIELD_NAME, not hardcoded '_key':

// createAddLanguagePatches.test.ts
expect(details.items[0]![LANGUAGE_FIELD_NAME]).toBe('en')

// InternationalizedArray.test.tsx
expect(onChange).toHaveBeenCalledWith([{
  items: [{
    [LANGUAGE_FIELD_NAME]: 'en',
    _type: 'internationalizedArrayStringValue',
  }],
}])

3. Tests That Explicitly Validate Migration Behavior

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':

  1. Tests will fail if code doesn't use the constant - Any hardcoded _key for language identification will be caught
  2. Tests will pass if code correctly uses LANGUAGE_FIELD_NAME - The abstraction layer works
  3. 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_NAME abstraction works
  • Ensure consistent behavior before and after the change

Approved for merge.

Copy link
Contributor

Copilot AI left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant