import { render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { AuthProvider } from '../auth-provider';

const mockInitialize = vi.fn();

vi.mock('@/lib/auth-store', () => ({
  useAuthStore: (selector: (state: { initialize: () => void }) => unknown) =>
    selector({ initialize: mockInitialize }),
}));

describe('AuthProvider', () => {
  beforeEach(() => {
    mockInitialize.mockClear();
  });

  it('renders children', () => {
    render(
      <AuthProvider>
        <div>Child content</div>
      </AuthProvider>,
    );
    expect(screen.getByText('Child content')).toBeInTheDocument();
  });

  it('calls initialize on mount', () => {
    render(
      <AuthProvider>
        <div>Test</div>
      </AuthProvider>,
    );
    expect(mockInitialize).toHaveBeenCalled();
  });

  it('renders multiple children', () => {
    render(
      <AuthProvider>
        <div>Child 1</div>
        <div>Child 2</div>
      </AuthProvider>,
    );
    expect(screen.getByText('Child 1')).toBeInTheDocument();
    expect(screen.getByText('Child 2')).toBeInTheDocument();
  });
});
