device-entity-resolution-model.test.mjs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import {
  4. canEditDeviceEntities,
  5. canReviewDeviceEntities,
  6. candidateStatusLabel,
  7. confidenceLabel,
  8. canonicalOptions,
  9. matchedSignalSummary,
  10. suggestionSourceLabel
  11. } from '../src/views/dataGovernance/development/deviceEntityResolutionModel.js'
  12. test('separates candidate editing from accountable review and rollback', () => {
  13. assert.equal(canEditDeviceEntities(['device-entities:edit']), true)
  14. assert.equal(canEditDeviceEntities(['governance:read']), false)
  15. assert.equal(canReviewDeviceEntities(['device-entities:review']), true)
  16. assert.equal(canReviewDeviceEntities(['device-entities:edit']), false)
  17. })
  18. test('presents governed lifecycle labels and confidence', () => {
  19. assert.equal(candidateStatusLabel('pending'), '待审核')
  20. assert.equal(candidateStatusLabel('merged'), '已合并')
  21. assert.equal(candidateStatusLabel('rolled_back'), '已回滚')
  22. assert.equal(suggestionSourceLabel('rule'), '确定性规则')
  23. assert.equal(suggestionSourceLabel('ai'), 'AI 建议')
  24. assert.equal(confidenceLabel(0.986), '98.6%')
  25. assert.equal(confidenceLabel(null), '—')
  26. })
  27. test('summarizes matched signals from literal explanation data', () => {
  28. const summary = matchedSignalSummary([
  29. { signal: 'name', matched: true, weight: 0.5 },
  30. { signal: 'location', matched: true, weight: 0.15 },
  31. { signal: 'model', matched: false, weight: 0.15 }
  32. ])
  33. assert.deepEqual(summary, {
  34. matched: 2,
  35. total: 3,
  36. weight: 0.65
  37. })
  38. })
  39. test('offers only the two candidate assets as canonical choices', () => {
  40. const options = canonicalOptions({
  41. left_asset_uid: 'asset-left',
  42. right_asset_uid: 'asset-right'
  43. })
  44. assert.deepEqual(options, [
  45. { text: '左侧资产 · asset-left', value: 'asset-left' },
  46. { text: '右侧资产 · asset-right', value: 'asset-right' }
  47. ])
  48. })