import { describe, expect, it } from 'vitest'
import { formatUiGridCellForExport, matchesUiGridStatus, resolveUiGridStatus } from '../gridStatus'

const map = {
  definitions: [{ value: 'READY', label: '대기', semantic: 'ready' as const }],
  unknownLabel: '상태 미등록',
}

describe('KBX-derived grid status boundary', () => {
  it('keeps raw canonical values while resolving display metadata', () => {
    expect(resolveUiGridStatus(map, 'READY')).toEqual({ rawValue: 'READY', label: '대기', semantic: 'ready', unknown: false })
  })

  it('makes unknown values visible as warnings', () => {
    expect(resolveUiGridStatus(map, 'NEW_VENDOR_STATE')).toEqual({
      rawValue: 'NEW_VENDOR_STATE', label: '상태 미등록 · NEW_VENDOR_STATE', semantic: 'warning', unknown: true,
    })
  })

  it('filters by the display label without changing the canonical value', () => {
    expect(matchesUiGridStatus(map, 'READY', '대기')).toBe(true)
    expect(matchesUiGridStatus(map, 'READY', 'READY')).toBe(false)
  })

  it('exports the display label only when a status map is supplied', () => {
    expect(formatUiGridCellForExport(map, 'READY')).toBe('대기')
    expect(formatUiGridCellForExport(undefined, 'READY')).toBe('READY')
  })
})
