Skip to content

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

Open
pedrobonamin wants to merge 6 commits into
cursor/agent-friendly-e2e-failure-report-060dfrom
cursor/media-plugin-test-coverage-3db6
Open

test(media): expand Vitest and Playwright coverage for sanity-plugin-media#1851
pedrobonamin wants to merge 6 commits into
cursor/agent-friendly-e2e-failure-report-060dfrom
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)
Edit Media from a document field Field menu → metadata save

Infra (from rebase)

  • Agent-friendly Playwright digest (agent-report.md) in the e2e reporter/workflow so CI failures are easier to triage.

Out of scope

  • Migrating Media off styled-components
  • Broad visual regression / full Media feature matrix beyond the happy paths above

Test 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
  • CI E2E (chromium + firefox) green
  • CI (lint, knip, build, test shards) green
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: 553a308

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 6, 2026 10:29am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
plugins-e2e-test-studio Ignored Ignored Aug 6, 2026 10:29am

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-pts1hbgyb.sanity.dev

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

@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% 5679 / 17276
🔵 Statements 32.66% 5998 / 18364
🔵 Functions 29.03% 1499 / 5162
🔵 Branches 23.92% 2907 / 12152
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 #8795 for commit 553a308 by the Vitest Coverage Report Action

cursoragent and others added 3 commits August 6, 2026 11:54
…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 marked this pull request as ready for review August 6, 2026 10:48
@pedrobonamin
pedrobonamin requested a review from a team as a code owner August 6, 2026 10:48
@pedrobonamin
pedrobonamin requested review from Copilot and stipsan and removed request for a team August 6, 2026 10:48

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.

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.

3 participants