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

1.8 KB
Raw Blame
import { describe, expect, it, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import { MemoryRouter, Route, Routes, useLocation } from 'react-router';

// Settings.jsx imports every tab component, and those pull in the API client.
// Stub the whole module so no tab's import-time wiring reaches the network. The
// Proxy answers any named import with a resolved-promise spy; `then` must stay
// undefined or Vitest's `await` on the factory result treats the namespace as a
// thenable and hangs waiting for a resolve that never comes.
vi.mock('../services/api', () => new Proxy({}, {
  get: (_target, key) => (key === 'then' || key === '__esModule' ? undefined : vi.fn().mockResolvedValue({})),
}));

const Settings = (await import('./Settings')).default;

function Landed() {
  const { pathname, search } = useLocation();
  return <div data-testid="landed">{`${pathname}${search}`}</div>;
}

// Former Settings tabs now live on the pages they configure. Their old
// /settings/<tab> URLs stay live as redirects so bookmarks, stale ⌘K history,
// and older docs keep working.
describe('Settings — retired tabs redirect to their new home', () => {
  it.each([
    ['/settings/image-gen', '/media/image?settings=1'],
    ['/settings/imessage', '/messages/imessage?settings=1'],
    ['/settings/signal', '/messages/signal'],
    ['/settings/catalog', '/catalog?settings=1'],
    ['/settings/spotify', '/brain/spotify'],
    ['/settings/youtube', '/brain/youtube'],
  ])('%s → %s', (from, to) => {
    render(
      <MemoryRouter initialEntries={[from]}>
        <Routes>
          <Route path="/settings/:tab" element={<Settings />} />
          <Route path="*" element={<Landed />} />
        </Routes>
      </MemoryRouter>,
    );
    expect(screen.getByTestId('landed').textContent).toBe(to);
  });
});