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

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

describe('ReconciliationExceptionPage T09 contract', () => {
  it('preserves version and comparison/correction/audit slots', () => {
    const wrapper = mount(ReconciliationExceptionPage, {
      global,
      props: { title: '대사 예외', state: 'WARN', evidence: { version: 'recon-v2' } },
      slots: { breaks: '<div data-test="breaks">breaks</div>', beforeAfter: '<div data-test="before-after">before-after</div>', correction: '<div data-test="correction">correction</div>', audit: '<div data-test="audit">audit</div>' }
    })
    expect(wrapper.find('.ks-page__meta').text()).toContain('Version: recon-v2')
    expect(wrapper.find('[data-test="breaks"]').exists()).toBe(true)
    expect(wrapper.find('[data-test="before-after"]').exists()).toBe(true)
    expect(wrapper.find('[data-test="correction"]').exists()).toBe(true)
    expect(wrapper.find('[data-test="audit"]').exists()).toBe(true)
  })

  it('suppresses exception detail while forbidden and forwards retry after error', async () => {
    const wrapper = mount(ReconciliationExceptionPage, { global, props: { title: '대사', state: 'FORBIDDEN' }, slots: { breaks: '<div data-test="breaks">민감한 break</div>', audit: '<div data-test="audit">감사</div>' } })
    expect(wrapper.find('[data-test="breaks"]').exists()).toBe(false)
    expect(wrapper.find('[data-test="audit"]').exists()).toBe(false)
    await wrapper.setProps({ state: 'ERROR' })
    await wrapper.findComponent({ name: 'QueryStateBoundary' }).vm.$emit('retry')
    expect(wrapper.emitted('retry')).toHaveLength(1)
  })
})
