MeshiTrack/packages/web/tests/app/(dashboard)/medicines/cabinet/page.test.tsx

39 lines
1.4 KiB
TypeScript
Raw Normal View History

import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
2026-04-26 18:44:59 +09:00
import type React from 'react';
const { mockUseApi } = vi.hoisted(() => ({ mockUseApi: vi.fn() }));
vi.mock('@/lib/useApi', () => ({ useApi: mockUseApi }));
2026-04-26 18:44:59 +09:00
vi.mock('next/link', () => ({
default: (props: { href?: string; children: React.ReactNode }) => props.children,
}));
vi.mock('@/app/(dashboard)/medicines/CabinetTab', () => ({
CabinetTab: ({ householdId }: { householdId: string }) => (
<div data-testid="cabinet-tab">{householdId}</div>
),
}));
2026-05-19 11:06:03 +09:00
import CabinetPage from '../../../../../src/app/(dashboard)/medicines/cabinet/page';
describe('CabinetPage', () => {
it('shows skeleton when loading', () => {
mockUseApi.mockReturnValue({ householdId: null, isLoading: true });
render(<CabinetPage />);
expect(screen.getByText('Medicine Cabinet')).toBeInTheDocument();
expect(screen.queryByTestId('cabinet-tab')).not.toBeInTheDocument();
});
it('shows household prompt when no householdId', () => {
mockUseApi.mockReturnValue({ householdId: null, isLoading: false });
render(<CabinetPage />);
expect(screen.getByText(/create or join a household/)).toBeInTheDocument();
});
it('renders CabinetTab when householdId exists', () => {
mockUseApi.mockReturnValue({ householdId: 'hh1', isLoading: false });
render(<CabinetPage />);
expect(screen.getByTestId('cabinet-tab')).toHaveTextContent('hh1');
});
});