test(media): expand Vitest and Playwright coverage for sanity-plugin-media - #1851
Conversation
🦋 Changeset detectedLatest commit: 553a308 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
✅ E2E Tests🟢 40 passed • view full report • view run Studio: https://plugins-e2e-test-studio-pts1hbgyb.sanity.dev Datasets: |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 280dcbd. Configure here.
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
…media Add unit/integration coverage for mediaField, applyMediaTags, AutoTagInput, plugin assembly, folder/upload/tag epics, and key browser UI flows. Expand e2e studio with mediaProduct schema and happy-path Playwright specs for browse, edit, pick, upload, tags, folders, auto-tag, and Edit Media. Co-authored-by: Pedro Bonamin <pedrobonamin@users.noreply.github.com>
CI failures came from content-hash asset collisions under parallel runs, strict-mode matches on nested accessible names, missing tags-panel toggle label, and fragile field-image / Edit Media locators. Co-authored-by: Pedro Bonamin <pedrobonamin@users.noreply.github.com>
Clear mediaField tag pre-filters when picking untagged seeds, assert selection via the form preview, and harden Edit Media dialog clicks under duplicate Strict Mode layers. All 8 Chromium media specs pass locally. Co-authored-by: Pedro Bonamin <pedrobonamin@users.noreply.github.com>
bf3382c to
ab40332
Compare
applyMediaTags resolves tags by name and may reuse another tag with the same slug. Query opt.media.tags[]->name.current and clear sticky filter chips before selecting assets in the field dialog.
Debounced redux-observable work kept dispatching after Browser tests unmounted, racing jsdom teardown in CI (window is not defined / instanceof errors). End the root epic when ReduxProvider unmounts and harden Browser/FormBuilderTool test cleanup.
Browser/FormBuilderTool tests now use Subject-based listen mocks; knip flagged the orphaned helper.
There was a problem hiding this comment.
Pull request overview
Expands automated coverage for sanity-plugin-media across Vitest (unit/integration) and Playwright (Studio happy paths), and includes small runtime fixes that improve accessibility and prevent redux-observable epics from dispatching after unmount.
Changes:
- Adds Vitest coverage for
mediaField,applyMediaTags, key UI components, and multiple epics (tags/folders/uploads/folder assignment). - Adds Playwright e2e specs + helper utilities and wires a
mediaProductschema into the e2e studio for asset-source andmediaFieldflows. - Runtime: adds accessible names for tag controls and stops Media epics on unmount via
takeUntil+media/epicEnd.
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/sanity-plugin-media/src/utils/mediaField.test.ts | New unit tests for mediaField option wiring + input override. |
| plugins/sanity-plugin-media/src/utils/applyMediaTags.test.ts | New unit tests for tag reuse/creation/dedup + per-asset serialization. |
| plugins/sanity-plugin-media/src/plugin.test.tsx | New tests validating plugin schema/tool/assetSource wiring. |
| plugins/sanity-plugin-media/src/modules/uploads/epics.test.ts | Extends uploads epic coverage (upload epic behavior). |
| plugins/sanity-plugin-media/src/modules/tags/epics.test.ts | Adds fetch/update epic coverage for tags. |
| plugins/sanity-plugin-media/src/modules/folders/epics.test.ts | Adds create/rename/fetch epic coverage for folders. |
| plugins/sanity-plugin-media/src/modules/assets/folderSetEpics.test.ts | New tests for folder assignment epics and refresh behavior. |
| plugins/sanity-plugin-media/src/formSchema/index.test.ts | Expands schema validation coverage (folder + localized asset schema). |
| plugins/sanity-plugin-media/src/components/TagViewHeader/index.tsx | Adds aria-label for Create Tag control. |
| plugins/sanity-plugin-media/src/components/ReduxProvider/index.tsx | Stops root epic on unmount via takeUntil + end action dispatch. |
| plugins/sanity-plugin-media/src/components/PickedBar/PickedBar.test.tsx | Adds interaction tests for selection, delete, folder actions, insert. |
| plugins/sanity-plugin-media/src/components/FormBuilderTool/FormBuilderTool.test.tsx | Adds coverage for file-mode picker header and stabilizes mocks. |
| plugins/sanity-plugin-media/src/components/DialogFolderCreate/DialogFolderCreate.test.tsx | New dialog tests for folder creation UX. |
| plugins/sanity-plugin-media/src/components/DialogAssetEdit/DialogAssetEdit.test.tsx | Adds coverage for creditLine enabled/excluded behavior. |
| plugins/sanity-plugin-media/src/components/Controls/index.tsx | Adds aria-label for Tags panel toggle. |
| plugins/sanity-plugin-media/src/components/Browser/Browser.test.tsx | Adds coverage for default Tags panel visibility + stabilizes mocks. |
| plugins/sanity-plugin-media/src/components/AutoTagInputWrapper/AutoTagInput.test.tsx | New tests for auto-tagging behavior + error toast. |
| plugins/sanity-plugin-media/src/tests/fixtures/renderWithProviders.tsx | Enhances test wrapper to support multi-select asset-source dispatch. |
| plugins/sanity-plugin-media/src/tests/fixtures/mockSanityClient.ts | Extends mock client (adds create) for new util tests. |
| plugins/sanity-plugin-media/src/tests/fixtures/listenMock.ts | Removes now-unneeded listen mock helper. |
| e2e/tests/media/media.spec.ts | Adds multiple Media e2e specs (tool, upload, tags, folders, mediaField, edit flow). |
| e2e/README.md | Updates e2e studio description to include mediaField coverage. |
| e2e/helpers/media/media.ts | Adds seeding/cleanup helpers, robust locators, and unique PNG generation to avoid asset hash collisions. |
| dev/e2e-studio/src/media.ts | Wires sanity-plugin-media plus a mediaProduct type using mediaField. |
| .changeset/media-test-coverage.md | Patch changeset for runtime fixes + test expansion. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Why
sanity-plugin-mediahad thin automated coverage relative to its surface area (Media tool, asset source picker, tags/folders,mediaFieldauto-tagging). We want unit/integration tests for the logic that can run in Vitest, and Playwright smoke coverage for the Studio-facing happy paths that need a real form and Content Lake.This PR also makes two small runtime fixes that tests exposed: missing accessible names on tag controls, and Media browser epics that kept running after the tool/dialog unmounted.
What changes
Runtime (
sanity-plugin-media— patch)Create tagon the tags header actionToggle tags panelon the tags panel buttonReduxProvider(takeUntil+media/epicEnd). Closing the Media tool/dialog (or tearing down Vitest) no longer leaves debounced fetches dispatching into an unmounted tree.Vitest
Adds/extends coverage for the main authoring and state loops:
mediaField,applyMediaTagsplugin.test.tsx)Playwright e2e
Wires Media into
dev/e2e-studioand adds helpers + specs undere2e/tests/media/:mediaFieldproduct), not a specific tag document id (name-based resolve can reuse an existing tag)Infra (from rebase)
agent-report.md) in the e2e reporter/workflow so CI failures are easier to triage.Out of scope
styled-componentsTest plan
pnpm --filter sanity-plugin-media exec vitest run(253 passed locally)playwright test tests/media/media.spec.ts --project=chromium(8 passed locally)pnpm lint/pnpm knip/pnpm build