choiceComboboxHelpers.test.mjs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import {
  4. displayLabelForModelValue,
  5. normalizedModelValue,
  6. syncStateFromModelValue
  7. } from './choiceComboboxHelpers.js'
  8. const choices = [
  9. { title: 'Production', value: 'prod' },
  10. { title: 'Staging', value: 'stage' }
  11. ]
  12. test('displayLabelForModelValue returns the choice label for valid values', () => {
  13. assert.equal(displayLabelForModelValue(choices, 'prod'), 'Production')
  14. })
  15. test('displayLabelForModelValue clears invalid enum values instead of echoing them', () => {
  16. assert.equal(displayLabelForModelValue(choices, 'missing'), '')
  17. })
  18. test('normalizedModelValue keeps valid values and clears invalid ones', () => {
  19. assert.equal(normalizedModelValue(choices, 'stage'), 'stage')
  20. assert.equal(normalizedModelValue(choices, 'missing'), '')
  21. assert.equal(normalizedModelValue(choices, ''), '')
  22. })
  23. test('syncStateFromModelValue clears invalid selections for closed-state sync', () => {
  24. assert.deepEqual(syncStateFromModelValue(choices, 'missing'), {
  25. query: '',
  26. modelValue: ''
  27. })
  28. })
  29. test('syncStateFromModelValue preserves valid selections for closed-state sync', () => {
  30. assert.deepEqual(syncStateFromModelValue(choices, 'stage'), {
  31. query: 'Staging',
  32. modelValue: 'stage'
  33. })
  34. })