Skip to content

test(media): expand Vitest and Playwright coverage for sanity-plugin-media - #1851

Merged
pedrobonamin merged 7 commits into
mainfrom
cursor/media-plugin-test-coverage-3db6
Aug 21, 2026
Merged

test(media): expand Vitest and Playwright coverage for sanity-plugin-media#1851
pedrobonamin merged 7 commits into
mainfrom
cursor/media-plugin-test-coverage-3db6

Conversation

@pedrobonamin

@pedrobonamin pedrobonamin commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Why

sanity-plugin-media had thin automated coverage relative to its surface area (Media tool, asset source picker, tags/folders, mediaField auto-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)

  • A11y labels for Media UI controls that e2e (and assistive tech) need to find reliably:
    • Create tag on the tags header action
    • Toggle tags panel on the tags panel button
  • Stop redux-observable epics on unmount in ReduxProvider (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:

Area What’s covered
Utils mediaField, applyMediaTags
Plugin assembly schema / tool wiring (plugin.test.tsx)
Components AutoTagInput, Browser, FormBuilderTool, PickedBar, DialogAssetEdit, DialogFolderCreate
Epics folders, tags, uploads, folder-set assets

Playwright e2e

Wires Media into dev/e2e-studio and adds helpers + specs under e2e/tests/media/:

Spec Intent
Opens Media tool + seeded asset Browse/search
Edits asset title and saves Library edit dialog
Selects image into a document field Asset source → form
Uploads via Media tool Upload path
Creates a tag from Tags panel Tag CRUD
Filters assets by folder Folder panel
Auto-tags via mediaField Asserts tag slug (product), not a specific tag document id (name-based resolve can reuse an existing tag); clears mediaTags facets so untagged seeds stay visible
Edit Media from a document field Field menu → metadata save

Test plan

  • pnpm --filter sanity-plugin-media exec vitest run (254 passed after merge with main)
  • Resolve merge conflicts with main (Sanity UI v4 imports + epic teardown)
  • playwright test tests/media/media.spec.ts --project=chromium (previously 8 passed)
  • CI green after conflict-resolution merge
Open in Web Open in Cursor 

@pedrobonamin pedrobonamin added the 🤖 bot label Aug 6, 2026 — with Cursor
@changeset-bot

changeset-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2ad130b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
sanity-plugin-media Patch

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

@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
plugins-studio Ready Ready Preview Aug 20, 2026 12:46pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
plugins-e2e-test-studio Ignored Ignored Aug 20, 2026 12:46pm

Request Review

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

✅ E2E Tests

🟢 40 passedview full reportview run

Studio: https://plugins-e2e-test-studio-bj80oud1l.sanity.dev

Datasets: pr-1851-chromium-32370495161, pr-1851-firefox-32370495161

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread e2e/tests/media/media.spec.ts
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 32.87% 5683 / 17286
🔵 Statements 32.64% 6003 / 18386
🔵 Functions 29% 1501 / 5175
🔵 Branches 23.93% 2910 / 12157
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
plugins/sanity-plugin-media/src/__tests__/fixtures/mockSanityClient.ts 77.41% 100% 56.25% 73.07% 29-33, 48-50
plugins/sanity-plugin-media/src/__tests__/fixtures/renderWithProviders.tsx 100% 100% 100% 100%
plugins/sanity-plugin-media/src/components/Controls/index.tsx 79.16% 70% 54.54% 73.68% 30, 34, 38, 42, 46
plugins/sanity-plugin-media/src/components/ReduxProvider/index.tsx 100% 87.5% 100% 100%
plugins/sanity-plugin-media/src/components/TagViewHeader/index.tsx 90% 66.66% 75% 87.5% 25
Generated in workflow #9371 for commit 2ad130b by the Vitest Coverage Report Action

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mediaProduct schema into the e2e studio for asset-source and mediaField flows.
  • 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.

Base automatically changed from cursor/agent-friendly-e2e-failure-report-060d to main August 10, 2026 07:38
cursoragent and others added 6 commits August 10, 2026 09:38
…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>
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.
@pedrobonamin
pedrobonamin force-pushed the cursor/media-plugin-test-coverage-3db6 branch from 553a308 to 635f8cb Compare August 10, 2026 07:38
stipsan
stipsan previously approved these changes Aug 12, 2026
Resolve conflicts with Sanity UI v4 import paths: keep epic teardown on
ReduxProvider unmount, Subject-based listen mocks, and update
AutoTagInput tests to @sanity/ui/toast + buildTheme.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 25 out of 25 changed files in this pull request and generated no new comments.

@pedrobonamin
pedrobonamin requested a review from stipsan August 21, 2026 06:17

@stipsan stipsan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet!

@pedrobonamin
pedrobonamin merged commit d0f77d2 into main Aug 21, 2026
25 checks passed
@pedrobonamin
pedrobonamin deleted the cursor/media-plugin-test-coverage-3db6 branch August 21, 2026 16:46
@squiggler-app squiggler-app Bot mentioned this pull request Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants