// tests/mockup-binding-coverage.test.ts
import { describe, it, expect } from 'vitest'
import { classifyCoverageViolations } from '../scripts/audit-mockup-binding-fidelity.mjs'

const VAR = 'boundVariables'
function frame(extra) {
  return { id: 'f', type: 'FRAME', name: 'row', layoutMode: 'HORIZONTAL', itemSpacing: 16, paddingLeft: 8, ...extra }
}
describe('classifyCoverageViolations (未绑即报)', () => {
  it('flags on-scale itemSpacing/padding that are bound to NO variable', () => {
    const r = classifyCoverageViolations(frame({}), {}, VAR)
    const props = r.map(x => x.prop)
    expect(props).toContain('itemSpacing')   // 16 是 on-scale，但未绑 → 仍报
    expect(props).toContain('paddingLeft')
  })
  it('does NOT flag a prop bound to a variable', () => {
    const bound = frame({ [VAR]: { itemSpacing: { id: 'VariableID:1' } } })
    const r = classifyCoverageViolations(bound, {}, VAR)
    expect(r.map(x => x.prop)).not.toContain('itemSpacing')
  })
  it('respects [[raw-ok]] ignore marker on the node', () => {
    const r = classifyCoverageViolations(frame({ name: 'row [[raw-ok]]' }), {}, VAR)
    expect(r).toHaveLength(0)
  })
  it('skips entire subtree when parent name contains [[raw-ok]]', () => {
    const child = { id: 'c1', type: 'FRAME', name: 'inner-row', layoutMode: 'HORIZONTAL', itemSpacing: 12, paddingLeft: 8 }
    const parent = { id: 'p1', type: 'FRAME', name: 'wrapper [[raw-ok]]', children: [child] }
    const r = classifyCoverageViolations(parent, {}, VAR)
    expect(r).toHaveLength(0)
  })
})
