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

import { buildPostImportRow } from '@/test/postImportFactories'

import type { DialogueFormControls } from '@/lib/dialogues/useDialogue'

const sharedFieldsSpy = vi.hoisted (() => vi.fn (() => <div data-testid="shared-fields"/>))

vi.mock ('@/components/posts/PostCreationDataFields', () => ({
  default: sharedFieldsSpy,
}))

describe ('PostCreationDataFields usage', () => {
  it ('is used by PostImportRowForm', async () => {
    const { default: PostImportRowForm } = await import (
        '@/components/posts/import/PostImportRowForm')

    render (
        <PostImportRowForm
            row={buildPostImportRow ()}
            controls={{
              close: vi.fn (),
              confirm: vi.fn (),
              setActions: vi.fn (),
            } as DialogueFormControls}
            onSave={vi.fn ()}/>)

    expect (screen.getByTestId ('shared-fields')).toBeInTheDocument ()
  })
})
