argumentFieldIds.test.mjs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import {
  4. ARGUMENT_FIELD_ID_PREFIX,
  5. argumentFieldChoicesId,
  6. argumentFieldId,
  7. argumentFieldListboxId,
  8. argumentFieldListboxOptionId,
  9. argumentFieldOptionId,
  10. argumentFieldValidationElementId,
  11. argumentFieldValueId,
  12. argumentFieldWrapperId
  13. } from './argumentFieldIds.js'
  14. test('argumentFieldId namespaces argument names with a field role', () => {
  15. assert.equal(argumentFieldId('content'), 'arg-field-content')
  16. assert.equal(argumentFieldId('banner'), 'arg-field-banner')
  17. assert.equal(argumentFieldId('confirm'), 'arg-field-confirm')
  18. })
  19. test('role-prefixed ids avoid collisions between related argument elements', () => {
  20. assert.notEqual(argumentFieldId('content'), argumentFieldChoicesId('content'))
  21. assert.notEqual(argumentFieldId('content-choices'), argumentFieldChoicesId('content'))
  22. assert.notEqual(argumentFieldId('segments-value'), argumentFieldValueId('segments'))
  23. assert.notEqual(argumentFieldId('segments-wrapper'), argumentFieldWrapperId('segments'))
  24. assert.notEqual(argumentFieldId('segments-0'), argumentFieldOptionId('segments', 0))
  25. assert.notEqual(argumentFieldId('host-listbox'), argumentFieldListboxId('host'))
  26. assert.notEqual(
  27. argumentFieldId('host-listbox-option-0'),
  28. argumentFieldListboxOptionId('host', 0)
  29. )
  30. })
  31. test('argumentFieldChoicesId uses a distinct choices role', () => {
  32. assert.equal(argumentFieldChoicesId('content'), 'arg-choices-content')
  33. })
  34. test('argumentFieldValidationElementId uses checklist value id', () => {
  35. assert.equal(
  36. argumentFieldValidationElementId({ name: 'segments', type: 'checklist' }),
  37. 'arg-value-segments'
  38. )
  39. })
  40. test('argumentFieldValidationElementId uses field id for other argument types', () => {
  41. assert.equal(
  42. argumentFieldValidationElementId({ name: 'content', type: 'raw_string_multiline' }),
  43. 'arg-field-content'
  44. )
  45. assert.equal(
  46. argumentFieldValidationElementId({ name: 'datetime', type: 'datetime' }),
  47. 'arg-field-datetime'
  48. )
  49. })
  50. test('namespaced ids avoid known app-shell element ids', () => {
  51. const appShellIds = [
  52. 'content',
  53. 'banner',
  54. 'layout',
  55. 'mainnav',
  56. 'app',
  57. 'big-error',
  58. 'available-version',
  59. 'link-login',
  60. 'username-text',
  61. 'theme-style',
  62. 'olivetin-custom-js',
  63. 'justification',
  64. 'username',
  65. 'password',
  66. 'connection-banner',
  67. 'execution-results-popup',
  68. 'logs-filter-suggestions',
  69. 'argument-popup'
  70. ]
  71. for (const shellId of appShellIds) {
  72. assert.notEqual(argumentFieldId(shellId), shellId)
  73. assert.ok(argumentFieldId(shellId).startsWith(ARGUMENT_FIELD_ID_PREFIX))
  74. assert.notEqual(argumentFieldChoicesId(shellId), shellId)
  75. assert.notEqual(argumentFieldValueId(shellId), shellId)
  76. }
  77. })