import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render, screen, waitFor } from '@testing-library/react'
import { MemoryRouter } from 'react-router-dom'
import { describe, expect, it, vi } from 'vitest'
import { AuthMethodsSection } from '../AuthMethodsSection'

vi.mock('@/shared/model/auth', () => ({
  $user: {
    defaultState: { id: '1', email: 'test@test.com' },
    subscribe: () => () => {},
    getState: () => ({ id: '1', email: 'test@test.com' }),
    watch: () => () => {},
    on: () => {},
    reset: () => {},
  },
  fetchAuthMethodsFx: vi.fn().mockResolvedValue([]),
  setPasswordFx: vi.fn(),
  unlinkOAuthFx: vi.fn(),
  requestEmailChangeFx: vi.fn(),
}))

vi.mock('@/shared/api/client', () => ({ apiClient: { post: vi.fn() } }))

vi.mock('effector-react', async () => {
  return {
    useUnit: () => ({ id: '1', email: 'test@test.com' }),
  }
})

function renderSection() {
  const qc = new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } })
  return render(
    <QueryClientProvider client={qc}>
      <MemoryRouter>
        <AuthMethodsSection />
      </MemoryRouter>
    </QueryClientProvider>,
  )
}

describe('AuthMethodsSection', () => {
  it('renders auth methods section', async () => {
    renderSection()
    await waitFor(() => {
      expect(screen.getByText('Методы входа')).toBeTruthy()
    })
  })
})
