import { describe, it, expect, beforeEach, vi } from 'vitest';
import { screen } from '@testing-library/react';
import { renderWithProviders } from '../test/utils';

vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
vi.mock('../lib/api', () => ({
  api: { get: vi.fn(), post: vi.fn(), patch: vi.fn(), put: vi.fn(), delete: vi.fn() },
  ApiError: class extends Error {},
}));

import { api } from '../lib/api';
import MyFinancialPage from './MyFinancialPage';

const get = api.get as ReturnType<typeof vi.fn>;

beforeEach(() => {
  get.mockReset();
  get.mockResolvedValue({ success: true, data: {
    total_paid: 0, total_pending: 0, monthly_chart: [],
  } });
});

describe('MyFinancialPage inside the settings shell', () => {
  it('renders the settings sub-nav around the page content', async () => {
    renderWithProviders(<MyFinancialPage />, { route: '/admin/my-financial' });
    // settings shell menu
    expect(await screen.findByText('خرید اشتراک')).toBeInTheDocument();
    expect(screen.getByText('خدمات')).toBeInTheDocument();
    // page's own content
    expect(screen.getByText('گزارش مالی')).toBeInTheDocument();
  });
});
