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

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

describe('VersionGovernancePage T10 contract', () => {
  it('renders version comparison, evidence, approval and rollback slots with version', () => {
    const wrapper = mount(VersionGovernancePage, { global, props: { title: '버전 거버넌스', state: 'WARN', evidence: { version: 'model-v4' } }, slots: { versionComparison: '<div data-test="comparison">comparison</div>', evidenceMatrix: '<div data-test="evidence">evidence</div>', approval: '<div data-test="approval">approval</div>', rollback: '<div data-test="rollback">rollback</div>' } })
    expect(wrapper.find('.ks-page__meta').text()).toContain('Version: model-v4')
    expect(wrapper.find('[data-test="comparison"]').exists()).toBe(true)
    expect(wrapper.find('[data-test="evidence"]').exists()).toBe(true)
    expect(wrapper.find('[data-test="approval"]').exists()).toBe(true)
    expect(wrapper.find('[data-test="rollback"]').exists()).toBe(true)
  })

  it('suppresses governance actions while readonly and forwards retry after error', async () => {
    const wrapper = mount(VersionGovernancePage, { global, props: { title: '거버넌스', state: 'READONLY' }, slots: { approval: '<div data-test="approval">승인</div>', rollback: '<div data-test="rollback">롤백</div>' } })
    expect(wrapper.find('[data-test="approval"]').exists()).toBe(false)
    expect(wrapper.find('[data-test="rollback"]').exists()).toBe(false)
    await wrapper.setProps({ state: 'ERROR' })
    await wrapper.findComponent({ name: 'QueryStateBoundary' }).vm.$emit('retry')
    expect(wrapper.emitted('retry')).toHaveLength(1)
  })
})
