device-quality-model.test.mjs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import {
  4. canBootstrapOrRevise,
  5. canPublish,
  6. canRun,
  7. evidenceSummary,
  8. formatPassRate,
  9. formatScore,
  10. policyStatusLabel,
  11. resultStatusLabel,
  12. ruleLabel,
  13. severityLabel
  14. } from '../src/views/dataGovernance/development/deviceQualityModel.js'
  15. test('separates policy editing, publishing and execution permissions', () => {
  16. assert.equal(canBootstrapOrRevise(['device-quality:edit']), true)
  17. assert.equal(canBootstrapOrRevise(['device-quality:execute']), false)
  18. assert.equal(canPublish(['device-quality:publish']), true)
  19. assert.equal(canPublish(['device-quality:edit']), false)
  20. assert.equal(canRun(['device-quality:execute']), true)
  21. assert.equal(canRun(['governance:read']), false)
  22. })
  23. test('presents governed policy and result labels', () => {
  24. assert.equal(policyStatusLabel('draft'), '草稿')
  25. assert.equal(policyStatusLabel('published'), '已发布')
  26. assert.equal(ruleLabel('maintenance_closed_loop'), '维修闭环完整性')
  27. assert.equal(severityLabel('critical'), '严重')
  28. assert.equal(resultStatusLabel('violated'), '存在违规')
  29. assert.equal(resultStatusLabel('not_applicable'), '不适用')
  30. })
  31. test('formats quality score and pass rate consistently', () => {
  32. assert.equal(formatScore(85), '85.0')
  33. assert.equal(formatScore(null), '—')
  34. assert.equal(formatPassRate(0.856), '85.6%')
  35. assert.equal(formatPassRate(undefined), '—')
  36. })
  37. test('summarizes bounded violation evidence without exposing raw attributes', () => {
  38. assert.deepEqual(evidenceSummary({
  39. asset_uid: 'asset-1',
  40. source_mapping_uid: 'mapping-1',
  41. missing_fields: ['location', 'organization'],
  42. password: 'must-not-be-shown'
  43. }), {
  44. assetUid: 'asset-1',
  45. sourceMappingUid: 'mapping-1',
  46. issueCount: 2
  47. })
  48. })