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

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

describe('WorkQueuePage T12 contract', () => {
  it('renders queue and exception summary with version metadata', () => {
    const wrapper = mount(WorkQueuePage, { global, props: { title: '작업 큐', state: 'WARN', evidence: { version: 'queue-v2' } }, slots: { exceptionSummary: '<div data-test="summary">summary</div>', queue: '<div data-test="queue">queue</div>' } })
    expect(wrapper.find('.ks-page__meta').text()).toContain('Version: queue-v2')
    expect(wrapper.find('[data-test="summary"]').exists()).toBe(true)
    expect(wrapper.find('[data-test="queue"]').exists()).toBe(true)
  })

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