// @vitest-environment jsdom import { cleanup, render, screen } from '@testing-library/react'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { PreviewSurface } from '../../src/components/plugins-home/cards/PreviewSurface'; import type { MediaPreviewSpec } from '../../src/components/plugins-home/preview'; const visibilityQueue: boolean[] = []; vi.mock('../../src/components/plugins-home/useInView', () => ({ useInView: () => ({ ref: { current: null }, inView: visibilityQueue.shift() ?? false, }), })); vi.mock('../../src/components/plugins-home/cards/MediaSurface', () => ({ MediaSurface: ({ inView, visible }: { inView: boolean; visible?: boolean }) => (
), })); vi.mock('../../src/components/plugins-home/cards/HtmlSurface', () => ({ HtmlSurface: ({ inView }: { inView: boolean }) => ( ), })); vi.mock('../../src/components/plugins-home/cards/DesignSystemSurface', () => ({ DesignSystemSurface: ({ inView }: { inView: boolean }) => ( ), })); vi.mock('../../src/components/plugins-home/cards/TextSurface', () => ({ TextSurface: () => , })); const IMAGE_PREVIEW: MediaPreviewSpec = { kind: 'media', mediaType: 'image', poster: 'https://example.invalid/poster.jpg', videoUrl: null, audioUrl: null, imageOnly: true, }; const PLAIN_VIDEO_PREVIEW: MediaPreviewSpec = { ...IMAGE_PREVIEW, mediaType: 'video', videoUrl: 'https://example.invalid/plain.mp4', imageOnly: false, }; const BAKED_CLIP_PREVIEW: MediaPreviewSpec = { ...PLAIN_VIDEO_PREVIEW, videoUrl: 'https://example.invalid/baked.mp4', loopHoldMs: 2500, }; function renderWithVisibility(preview: MediaPreviewSpec) { // PreviewSurface calls useInView in this order: near, media, keep, visible. Make the // values intentionally disagree so the gate passed to MediaSurface proves // which zone each media subtype uses. visibilityQueue.splice(0, visibilityQueue.length, false, true, false, true); render(