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

2.2 KB
Raw Blame
import { describe, it, expect, vi, afterEach } from 'vitest';
import { render, screen, fireEvent, cleanup } from '@testing-library/react';

vi.mock('../../services/api', () => ({
  getPrivacyOrgs: vi.fn(),
  deletePrivacyOrg: vi.fn(),
  getVaultRecords: vi.fn(),
  getOrgHoldings: vi.fn(),
  createPrivacyOrg: vi.fn(),
  updatePrivacyOrg: vi.fn(),
  setOrgHoldings: vi.fn(),
  getSocialAccounts: vi.fn(),
}));

import * as api from '../../services/api';
import PrivacyOrgsTab from './PrivacyOrgsTab';

afterEach(() => {
  cleanup();
  vi.clearAllMocks();
});

describe('PrivacyOrgsTab', () => {
  it('shows a failed organization read as a retryable error, not "No organizations yet"', async () => {
    api.getPrivacyOrgs.mockRejectedValueOnce(new Error('boom'));
    api.getPrivacyOrgs.mockResolvedValue([{ id: 'org-1', name: 'Acme Bank', category: 'bank', trust: 'trusted', status: 'active' }]);
    api.getVaultRecords.mockResolvedValue([]);
    api.getOrgHoldings.mockResolvedValue([]);
    render(<PrivacyOrgsTab subjectId="self" />);

    expect(await screen.findByText(/Could not load organizations/)).toBeInTheDocument();
    expect(screen.queryByText(/No organizations yet/)).not.toBeInTheDocument();

    fireEvent.click(screen.getByRole('button', { name: 'Retry' }));
    expect(await screen.findByText('Acme Bank')).toBeInTheDocument();
  });

  it('shows a holdings error instead of "No holdings recorded" when a badge read fails, and Retry restores it', async () => {
    api.getPrivacyOrgs.mockResolvedValue([{ id: 'org-1', name: 'Acme Bank', category: 'bank', trust: 'trusted', status: 'active' }]);
    api.getVaultRecords.mockResolvedValue([]);
    api.getOrgHoldings.mockRejectedValueOnce(new Error('holdings down'));
    api.getOrgHoldings.mockResolvedValue([{ vaultRecordId: 'v1', status: 'current' }]);
    render(<PrivacyOrgsTab subjectId="self" />);

    expect(await screen.findByText(/Could not load holdings/)).toBeInTheDocument();
    expect(screen.queryByText('No holdings recorded')).not.toBeInTheDocument();

    fireEvent.click(screen.getByRole('button', { name: 'Retry' }));
    expect(await screen.findByText(/1 current/i)).toBeInTheDocument();
    expect(screen.queryByText(/Could not load holdings/)).not.toBeInTheDocument();
  });
});