import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { MemoryRouter } from 'react-router-dom'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import UploadPage from './UploadPage'

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

describe('UploadPage', () => {
  beforeEach(() => {
    localStorage.clear()
  })

  it('uses client-side navigation for the settings link', async () => {
    render(
      <MemoryRouter>
        <UploadPage />
      </MemoryRouter>
    )

    await userEvent.click(screen.getByRole('button', { name: '☁️ Nextcloud (not set up)' }))

    const settingsLink = screen.getByRole('link', { name: 'Go to Settings' })
    expect(settingsLink).toHaveAttribute('href', '/settings')
  })
})
