import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { render, screen } from '@testing-library/react';
import { AuthContext } from '../../contexts/AuthContext';
import { AccountContext } from '../../contexts/AccountContext';
import PublicTermsOfServicePage from './PublicTermsOfServicePage';

jest.mock('../../../axiosApi', () => ({
  axiosInstance: {
    post: jest.fn(),
    get: jest.fn(),
    defaults: { headers: { common: {} as Record<string, string | null> } },
  },
}));

jest.mock('../../components/PageWrapperLayout/PageWrapperLayout', () => ({
  __esModule: true,
  default: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));

describe('PublicTermsOfServicePage', () => {
  it('renders key headings without auth', () => {
    render(
      <MemoryRouter>
        <AuthContext.Provider
          value={{
            authenticated: false,
            loading: false,
            setAuthentication: jest.fn(),
            needsNewPassword: false,
            setNeedsNewPassword: jest.fn(),
          }}
        >
          <AccountContext.Provider value={{ account: undefined, setAccount: jest.fn() }}>
            <PublicTermsOfServicePage />
          </AccountContext.Provider>
        </AuthContext.Provider>
      </MemoryRouter>,
    );

    expect(screen.getByRole('heading', { name: /Terms of Service/i })).toBeInTheDocument();
    expect(screen.getByRole('heading', { name: /Acceptance of Terms/i })).toBeInTheDocument();
    expect(screen.getByRole('heading', { name: /Analytics and Cookies/i })).toBeInTheDocument();
    expect(screen.getByRole('heading', { name: /Governing Law/i })).toBeInTheDocument();
    expect(screen.getByRole('heading', { name: /Contact/i })).toBeInTheDocument();
    expect(screen.queryByRole('button', { name: /Acknowledge/i })).not.toBeInTheDocument();
  });
});
