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

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

describe('ApprovalWorkbenchPage T05 contract', () => {
  it('renders queue/detail/decision slots and evidence version metadata', () => {
    const wrapper = mount(ApprovalWorkbenchPage, {
      global,
      props: { title: '승인 검토', state: 'WARN', warning: '증거 확인 필요', evidence: { asOf: '2026-08-12T00:00:00Z', version: 'approval-v1' } },
      slots: { queue: '<div data-test="queue">queue</div>', detail: '<div data-test="detail">detail</div>', decision: '<div data-test="decision">decision</div>' }
    })

    expect(wrapper.find('.ks-page__meta').text()).toContain('Version: approval-v1')
    expect(wrapper.find('[data-test="queue"]').exists()).toBe(true)
    expect(wrapper.find('[data-test="detail"]').exists()).toBe(true)
    expect(wrapper.find('[data-test="decision"]').exists()).toBe(true)
  })

  it('suppresses decision content in conflict state and forwards retry', async () => {
    const wrapper = mount(ApprovalWorkbenchPage, {
      global,
      props: { title: '충돌 검토', state: 'CONFLICT' },
      slots: { decision: '<div data-test="sensitive-decision">승인</div>' }
    })

    expect(wrapper.find('[data-test="sensitive-decision"]').exists()).toBe(false)
    await wrapper.setProps({ state: 'ERROR' })
    await wrapper.findComponent({ name: 'QueryStateBoundary' }).vm.$emit('retry')
    expect(wrapper.emitted('retry')).toHaveLength(1)
  })
})
