import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import FastEntryGridPage from '../v2/FastEntryGridPage.vue'
import { nativeUiAdapter } from '../../adapter/native'
import { uiAdapterKey } from '../../adapter/contracts'

const global = { provide: { [uiAdapterKey as unknown as string]: nativeUiAdapter } }

describe('FastEntryGridPage T11 contract', () => {
  it('renders grid and validation summary slots with version metadata', () => {
    const wrapper = mount(FastEntryGridPage, { global, props: { title: '대량 입력', state: 'DIRTY', evidence: { version: 'grid-v2' } }, slots: { grid: '<div data-test="grid">grid</div>', validationSummary: '<div data-test="validation">validation</div>' } })
    expect(wrapper.find('.ks-page__meta').text()).toContain('Version: grid-v2')
    expect(wrapper.find('[data-test="grid"]').exists()).toBe(true)
    expect(wrapper.find('[data-test="validation"]').exists()).toBe(true)
  })

  it('suppresses grid while processing and forwards retry after error', async () => {
    const wrapper = mount(FastEntryGridPage, { global, props: { title: '대량 입력', state: 'PROCESSING' }, slots: { grid: '<div data-test="grid">grid</div>' } })
    expect(wrapper.find('[data-test="grid"]').exists()).toBe(false)
    await wrapper.setProps({ state: 'ERROR' })
    await wrapper.findComponent({ name: 'QueryStateBoundary' }).vm.$emit('retry')
    expect(wrapper.emitted('retry')).toHaveLength(1)
  })
})
