import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import type React from 'react';

const { mockUseApi } = vi.hoisted(() => ({ mockUseApi: vi.fn() }));

vi.mock('@/lib/useApi', () => ({ useApi: mockUseApi }));
vi.mock('next/link', () => ({
  default: (props: { href?: string; children: React.ReactNode }) => props.children,
}));
vi.mock('@/app/(dashboard)/medicines/ActivityTab', () => ({
  ActivityTab: ({ householdId }: { householdId: string }) => (
    <div data-testid="activity-tab">{householdId}</div>
  ),
}));

import ActivityPage from '../../../../../src/app/(dashboard)/medicines/activity/page';

describe('ActivityPage', () => {
  it('shows skeleton when loading', () => {
    mockUseApi.mockReturnValue({ householdId: null, isLoading: true });
    render(<ActivityPage />);
    expect(screen.getByText('Cabinet Activity')).toBeInTheDocument();
    expect(screen.queryByTestId('activity-tab')).not.toBeInTheDocument();
  });

  it('shows household prompt when no householdId', () => {
    mockUseApi.mockReturnValue({ householdId: null, isLoading: false });
    render(<ActivityPage />);
    expect(screen.getByText(/create or join a household/)).toBeInTheDocument();
  });

  it('renders ActivityTab when householdId exists', () => {
    mockUseApi.mockReturnValue({ householdId: 'hh1', isLoading: false });
    render(<ActivityPage />);
    expect(screen.getByTestId('activity-tab')).toHaveTextContent('hh1');
  });
});
