Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

5.9 KB
Raw Blame
import { describe, it, expect, vi } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/react';
import { MemoryRouter } from 'react-router';
import VideoGenGallery from './VideoGenGallery';
import { finishTargetForRecord } from '../../lib/videoFinish';

vi.mock('../../services/socket', () => ({ default: { on: vi.fn(), off: vi.fn() } }));

const DRAFT_MODEL = { id: 'draft_model', name: 'Draft (4-step)', finishModelId: 'delivery_model' };
const DELIVERY_MODEL = { id: 'delivery_model', name: 'Delivery (20-step)' };

const videoRecord = (over = {}) => ({
  id: 'rec-1',
  filename: 'rec-1.mp4',
  thumbnail: 'rec-1.jpg',
  prompt: 'a quiet street at dusk',
  modelId: 'draft_model',
  seed: 424242,
  mode: 'text',
  renderInputsVersion: 1,
  conditioning: [],
  createdAt: '2026-01-01T00:00:00.000Z',
  ...over,
});

const renderGallery = ({ records, models, hidden = [], showHidden = false, onFinish = vi.fn(), onRemix } = {}) => {
  render(
    <MemoryRouter>
      <VideoGenGallery
        galleryVisible={records}
        galleryHidden={hidden}
        favoritesOnly={false}
        showHidden={showHidden}
        onToggleFavorites={vi.fn()}
        onToggleShowHidden={vi.fn()}
        onPreview={vi.fn()}
        onRemix={onRemix}
        onContinue={vi.fn()}
        onUpscale={vi.fn()}
        onDelete={vi.fn()}
        onToggleHidden={vi.fn()}
        getCardProps={() => ({ showCollectionMenu: false, showMoodBoardMenu: false })}
        finishTargetFor={(raw) => finishTargetForRecord(raw, models)}
        onFinish={onFinish}
      />
    </MemoryRouter>,
  );
  return { onFinish };
};

describe('VideoGenGallery — Finish action (#3696)', () => {
  it('offers Finish for a reproducible text-to-video draft with an available delivery model', () => {
    renderGallery({ records: [videoRecord()], models: [DRAFT_MODEL, DELIVERY_MODEL] });
    expect(screen.getByRole('button', { name: /Finish/i })).toBeInTheDocument();
  });

  it('names the delivery model in the affordance so the user knows what they are switching to', () => {
    renderGallery({ records: [videoRecord()], models: [DRAFT_MODEL, DELIVERY_MODEL] });
    expect(screen.getByRole('button', { name: /Finish/i })).toHaveAttribute(
      'title',
      expect.stringContaining('Delivery (20-step)'),
    );
  });

  it('hands the raw record plus the resolved target to the handler — and starts nothing itself', () => {
    const { onFinish } = renderGallery({ records: [videoRecord()], models: [DRAFT_MODEL, DELIVERY_MODEL] });
    fireEvent.click(screen.getByRole('button', { name: /Finish/i }));
    expect(onFinish).toHaveBeenCalledTimes(1);
    const [raw, target] = onFinish.mock.calls[0];
    expect(raw.id).toBe('rec-1');
    expect(target.id).toBe('delivery_model');
  });

  it('omits Finish for an image-conditioned draft', () => {
    renderGallery({
      records: [videoRecord({ mode: 'image', conditioning: ['image'] })],
      models: [DRAFT_MODEL, DELIVERY_MODEL],
    });
    expect(screen.queryByRole('button', { name: /Finish/i })).toBeNull();
  });

  it('omits Finish for a legacy record with no durable re-render inputs', () => {
    const { renderInputsVersion, conditioning, ...legacy } = videoRecord();
    renderGallery({ records: [legacy], models: [DRAFT_MODEL, DELIVERY_MODEL] });
    expect(screen.queryByRole('button', { name: /Finish/i })).toBeNull();
  });

  it('omits Finish when the delivery model is not installed here', () => {
    renderGallery({ records: [videoRecord()], models: [DRAFT_MODEL] });
    expect(screen.queryByRole('button', { name: /Finish/i })).toBeNull();
  });

  it('offers Finish in the expanded hidden section too — a chain\'s first chunk is a real draft', () => {
    const { onFinish } = renderGallery({
      records: [],
      hidden: [videoRecord({ id: 'rec-hidden', hidden: true })],
      showHidden: true,
      models: [DRAFT_MODEL, DELIVERY_MODEL],
    });
    fireEvent.click(screen.getByRole('button', { name: /Finish/i }));
    expect(onFinish.mock.calls[0][0].id).toBe('rec-hidden');
  });

  it('renders the gallery unchanged when no finish wiring is supplied at all', () => {
    render(
      <MemoryRouter>
        <VideoGenGallery
          galleryVisible={[videoRecord()]}
          galleryHidden={[]}
          favoritesOnly={false}
          showHidden={false}
          onToggleFavorites={vi.fn()}
          onToggleShowHidden={vi.fn()}
          onPreview={vi.fn()}
          onContinue={vi.fn()}
          onUpscale={vi.fn()}
          onDelete={vi.fn()}
          onToggleHidden={vi.fn()}
          getCardProps={() => ({ showCollectionMenu: false, showMoodBoardMenu: false })}
        />
      </MemoryRouter>,
    );
    expect(screen.queryByRole('button', { name: /Finish/i })).toBeNull();
    expect(screen.getByRole('button', { name: /Continue/i })).toBeInTheDocument();
  });
});

describe('VideoGenGallery — Remix action', () => {
  it('offers Remix and hands the raw record to the handler', () => {
    const onRemix = vi.fn();
    renderGallery({ records: [videoRecord()], models: [DRAFT_MODEL, DELIVERY_MODEL], onRemix });
    fireEvent.click(screen.getByRole('button', { name: /Remix/i }));
    expect(onRemix).toHaveBeenCalledTimes(1);
    expect(onRemix.mock.calls[0][0].id).toBe('rec-1');
    expect(onRemix.mock.calls[0][0].prompt).toBe('a quiet street at dusk');
  });

  it('offers Remix in the expanded hidden section too', () => {
    const onRemix = vi.fn();
    renderGallery({
      records: [],
      hidden: [videoRecord({ id: 'rec-hidden', hidden: true })],
      showHidden: true,
      models: [DRAFT_MODEL, DELIVERY_MODEL],
      onRemix,
    });
    fireEvent.click(screen.getByRole('button', { name: /Remix/i }));
    expect(onRemix.mock.calls[0][0].id).toBe('rec-hidden');
  });

  it('omits Remix when no handler is supplied', () => {
    renderGallery({ records: [videoRecord()], models: [DRAFT_MODEL, DELIVERY_MODEL] });
    expect(screen.queryByRole('button', { name: /Remix/i })).toBeNull();
  });
});