import { screen } from '@testing-library/react'
import { describe, expect, it } from 'vitest'

import TopNavUser from '@/components/TopNavUser'
import { buildUser } from '@/test/factories'
import { renderWithProviders } from '@/test/render'

describe ('TopNavUser', () => {
  it ('renders nothing without a user', () => {
    const { container } = renderWithProviders (<TopNavUser user={null}/>)

    expect (container).toBeEmptyDOMElement ()
  })

  it ('links named users to settings', () => {
    renderWithProviders (<TopNavUser user={buildUser ({ name: '山田' })}/>)

    expect (screen.getByRole ('link', { name: '山田' })).toHaveAttribute (
        'href',
        '/users/settings',
    )
  })

  it ('uses the anonymous display name', () => {
    renderWithProviders (<TopNavUser user={buildUser ({ name: null })}/>)

    expect (screen.getByRole ('link', { name: '名もなきニジラー' })).toBeInTheDocument ()
  })
})
