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

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

describe('BatchOperationsPageV2 T08 contract', () => {
  it('forwards version metadata and renders runbook/timeline/records/reprocess slots', () => {
    const wrapper = mount(BatchOperationsPageV2, {
      global,
      props: { title: '배치 운영', state: 'WARN', evidence: { version: 'job-v2' } },
      slots: { runSummary: '<div data-test="summary">summary</div>', timeline: '<div data-test="timeline">timeline</div>', records: '<div data-test="records">records</div>', reprocess: '<div data-test="reprocess">reprocess</div>', runbook: '<div data-test="runbook">runbook</div>' }
    })
    expect(wrapper.find('.ks-page__meta').text()).toContain('Version: job-v2')
    expect(wrapper.find('[data-test="timeline"]').exists()).toBe(true)
    expect(wrapper.find('[data-test="records"]').exists()).toBe(true)
    expect(wrapper.find('[data-test="reprocess"]').exists()).toBe(true)
    expect(wrapper.find('[data-test="runbook"]').exists()).toBe(true)
  })

  it('suppresses reprocess content while processing and forwards retry after error', async () => {
    const wrapper = mount(BatchOperationsPageV2, { global, props: { title: '배치', state: 'PROCESSING' }, slots: { reprocess: '<div data-test="reprocess">재처리</div>' } })
    expect(wrapper.find('[data-test="reprocess"]').exists()).toBe(false)
    await wrapper.setProps({ state: 'ERROR' })
    await wrapper.findComponent({ name: 'QueryStateBoundary' }).vm.$emit('retry')
    expect(wrapper.emitted('retry')).toHaveLength(1)
  })
})
