@alumbwe/anvil 1.0.41 → 1.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/bin/anvil.js +18 -0
  2. package/package.json +13 -6
  3. package/src/agents/bundled-agents.generated.ts +1 -1
  4. package/src/entry.ts +5 -0
  5. package/src/index.tsx +27 -4
  6. package/src/login/plain-login.ts +60 -0
  7. package/src/login/supabase-auth.ts +346 -0
  8. package/src/pre-init/client-env.ts +17 -0
  9. package/src/utils/anvil-client.ts +4 -0
  10. package/src/utils/auth.ts +16 -4
  11. package/src/utils/client-env-defaults.ts +28 -0
  12. package/src/utils/config-dir.ts +1 -1
  13. package/vendor/@anvil/common/src/constants/deepseek-direct.ts +30 -1
  14. package/vendor/@anvil/common/src/util/project-ignore.ts +4 -3
  15. package/vendor/@anvil/sdk/dist/index.cjs +46 -10
  16. package/vendor/@anvil/sdk/dist/index.mjs +46 -10
  17. package/src/commands/__tests__/anvil-command-aliases.test.ts +0 -56
  18. package/src/commands/__tests__/bash-command.test.ts +0 -445
  19. package/src/commands/__tests__/command-args.test.ts +0 -349
  20. package/src/commands/__tests__/copy-conversation-clipboard.test.ts +0 -108
  21. package/src/commands/__tests__/copy-conversation.test.ts +0 -226
  22. package/src/commands/__tests__/diagnostics-command.test.ts +0 -35
  23. package/src/commands/__tests__/image.test.ts +0 -99
  24. package/src/commands/__tests__/init.test.ts +0 -456
  25. package/src/commands/__tests__/new-command-rotates-chat.test.ts +0 -91
  26. package/src/commands/__tests__/process-diagnostics.test.ts +0 -54
  27. package/src/commands/__tests__/prompt-builders.test.ts +0 -28
  28. package/src/commands/__tests__/router-input.test.ts +0 -298
  29. package/src/components/__tests__/ad-banner.test.tsx +0 -83
  30. package/src/components/__tests__/anvil-landing-heading-row.test.tsx +0 -91
  31. package/src/components/__tests__/anvil-model-selector.test.tsx +0 -519
  32. package/src/components/__tests__/anvil-offer-invariants.test.ts +0 -54
  33. package/src/components/__tests__/anvil-takeover-prompt.test.tsx +0 -212
  34. package/src/components/__tests__/chat-input-bar.test.tsx +0 -130
  35. package/src/components/__tests__/grid-layout.integration.test.tsx +0 -304
  36. package/src/components/__tests__/grid-layout.test.tsx +0 -1051
  37. package/src/components/__tests__/message-block.completion.test.tsx +0 -104
  38. package/src/components/__tests__/message-block.streaming.test.tsx +0 -78
  39. package/src/components/__tests__/message-with-agents.test.tsx +0 -579
  40. package/src/components/__tests__/multiline-input.test.tsx +0 -1132
  41. package/src/components/__tests__/queue-panel.test.tsx +0 -398
  42. package/src/components/__tests__/selectable-list.test.ts +0 -232
  43. package/src/components/__tests__/status-bar.test.tsx +0 -44
  44. package/src/components/__tests__/status-indicator.test.tsx +0 -204
  45. package/src/components/__tests__/terminal-thinking-orb.test.tsx +0 -111
  46. package/src/components/__tests__/user-error-banner.test.tsx +0 -102
  47. package/src/components/ask-user/__tests__/multiple-choice-form.test.ts +0 -432
  48. package/src/components/ask-user/__tests__/validation.test.ts +0 -213
  49. package/src/components/tools/__tests__/apply-patch.test.tsx +0 -84
  50. package/src/components/tools/__tests__/code-search.test.tsx +0 -45
  51. package/src/components/tools/__tests__/gravity-index.test.ts +0 -76
  52. package/src/components/tools/__tests__/render-ui.test.tsx +0 -92
  53. package/src/components/tools/__tests__/run-terminal-command.test.ts +0 -233
  54. package/src/contexts/__tests__/chat-runtime-context.test.tsx +0 -149
  55. package/src/data/slash-commands.test.ts +0 -24
  56. package/src/hooks/__tests__/holds-live-anvil-slot.test.ts +0 -49
  57. package/src/hooks/__tests__/session-fetch-signal.test.ts +0 -63
  58. package/src/hooks/__tests__/use-activity-query.test.ts +0 -1000
  59. package/src/hooks/__tests__/use-ask-user-bridge.test.ts +0 -176
  60. package/src/hooks/__tests__/use-auth-query.test.ts +0 -21
  61. package/src/hooks/__tests__/use-chat-input-remount.test.tsx +0 -66
  62. package/src/hooks/__tests__/use-clipboard.test.tsx +0 -73
  63. package/src/hooks/__tests__/use-connection-status.test.ts +0 -112
  64. package/src/hooks/__tests__/use-directory-browser.test.ts +0 -203
  65. package/src/hooks/__tests__/use-gravity-ad.test.ts +0 -73
  66. package/src/hooks/__tests__/use-grid-layout.test.ts +0 -349
  67. package/src/hooks/__tests__/use-input-history.test.ts +0 -699
  68. package/src/hooks/__tests__/use-message-queue-editing.test.tsx +0 -209
  69. package/src/hooks/__tests__/use-message-queue.test.tsx +0 -71
  70. package/src/hooks/__tests__/use-path-tab-completion.test.ts +0 -315
  71. package/src/hooks/__tests__/use-queue-controls.test.ts +0 -68
  72. package/src/hooks/__tests__/use-queue-ui.test.tsx +0 -83
  73. package/src/hooks/__tests__/use-searchable-list.test.ts +0 -359
  74. package/src/hooks/__tests__/use-send-message-timer.test.ts +0 -146
  75. package/src/hooks/__tests__/use-suggestion-engine-mention.test.ts +0 -361
  76. package/src/hooks/__tests__/use-suggestion-engine.test.ts +0 -485
  77. package/src/hooks/__tests__/use-terminal-focus.test.ts +0 -66
  78. package/src/hooks/__tests__/use-terminal-layout.test.ts +0 -675
  79. package/src/hooks/__tests__/use-timeout.test.ts +0 -330
  80. package/src/hooks/__tests__/use-usage-query.test.ts +0 -502
  81. package/src/hooks/__tests__/use-user-details-query.test.ts +0 -195
  82. package/src/hooks/helpers/__tests__/send-message.test.ts +0 -1918
  83. package/src/init/__tests__/init-direnv.test.ts +0 -526
  84. package/src/state/__tests__/chat-store-focus.test.ts +0 -22
  85. package/src/state/__tests__/feedback-store.test.ts +0 -257
  86. package/src/utils/__tests__/active-run.test.ts +0 -140
  87. package/src/utils/__tests__/activity-tracker.test.ts +0 -440
  88. package/src/utils/__tests__/agent-display.test.ts +0 -139
  89. package/src/utils/__tests__/analytics-client.test.ts +0 -262
  90. package/src/utils/__tests__/anonymous-id.test.ts +0 -74
  91. package/src/utils/__tests__/anvil-api.test.ts +0 -578
  92. package/src/utils/__tests__/anvil-instance-owner.test.ts +0 -69
  93. package/src/utils/__tests__/anvil-model-navigation.test.ts +0 -102
  94. package/src/utils/__tests__/anvil-premium-reset.test.ts +0 -79
  95. package/src/utils/__tests__/anvil-referral-cache.test.ts +0 -116
  96. package/src/utils/__tests__/anvil-session-api.test.ts +0 -215
  97. package/src/utils/__tests__/anvil-session-display.test.ts +0 -23
  98. package/src/utils/__tests__/anvil-streak-line.test.ts +0 -217
  99. package/src/utils/__tests__/arrays.test.ts +0 -264
  100. package/src/utils/__tests__/bash-context-processor.test.ts +0 -38
  101. package/src/utils/__tests__/block-processor.test.ts +0 -810
  102. package/src/utils/__tests__/chat-history.test.ts +0 -203
  103. package/src/utils/__tests__/chat-input-key-intercept.test.ts +0 -40
  104. package/src/utils/__tests__/chat-meta.test.ts +0 -130
  105. package/src/utils/__tests__/clipboard-linux.test.ts +0 -359
  106. package/src/utils/__tests__/clipboard.test.ts +0 -910
  107. package/src/utils/__tests__/code-search-summary.test.ts +0 -84
  108. package/src/utils/__tests__/collapse-helpers.test.ts +0 -1109
  109. package/src/utils/__tests__/error-handling.test.ts +0 -658
  110. package/src/utils/__tests__/exit-cleanly.test.ts +0 -110
  111. package/src/utils/__tests__/feedback-helpers.test.ts +0 -444
  112. package/src/utils/__tests__/feedback-submission.test.ts +0 -26
  113. package/src/utils/__tests__/fetch-usage.test.ts +0 -355
  114. package/src/utils/__tests__/fingerprint.test.ts +0 -144
  115. package/src/utils/__tests__/fixtures/terminal-command-broker-child.ts +0 -7
  116. package/src/utils/__tests__/fixtures/terminal-command-broker-entry.ts +0 -3
  117. package/src/utils/__tests__/fixtures/terminal-command-broker-owner.ts +0 -33
  118. package/src/utils/__tests__/format-elapsed-time.test.ts +0 -103
  119. package/src/utils/__tests__/format-timeout.test.ts +0 -87
  120. package/src/utils/__tests__/image-dimensions.test.ts +0 -249
  121. package/src/utils/__tests__/image-processor.test.ts +0 -209
  122. package/src/utils/__tests__/implementor-helpers.test.ts +0 -1458
  123. package/src/utils/__tests__/keyboard-actions.test.ts +0 -660
  124. package/src/utils/__tests__/layout-helpers.test.ts +0 -36
  125. package/src/utils/__tests__/lazy-response-ads.test.ts +0 -167
  126. package/src/utils/__tests__/log-shipper.test.ts +0 -53
  127. package/src/utils/__tests__/markdown-renderer.test.tsx +0 -421
  128. package/src/utils/__tests__/message-block-helpers.test.ts +0 -1263
  129. package/src/utils/__tests__/message-updater.test.ts +0 -645
  130. package/src/utils/__tests__/osc-timeout-scenarios.test.ts +0 -172
  131. package/src/utils/__tests__/pending-attachments.test.ts +0 -277
  132. package/src/utils/__tests__/polling-backoff.test.ts +0 -51
  133. package/src/utils/__tests__/queue-panel-actions.test.ts +0 -148
  134. package/src/utils/__tests__/run-state-storage.test.ts +0 -919
  135. package/src/utils/__tests__/safe-json.test.ts +0 -77
  136. package/src/utils/__tests__/sdk-event-handlers.test.ts +0 -685
  137. package/src/utils/__tests__/send-message-helpers.test.ts +0 -1898
  138. package/src/utils/__tests__/send-message-timer.test.ts +0 -64
  139. package/src/utils/__tests__/settings.test.ts +0 -99
  140. package/src/utils/__tests__/strings.test.ts +0 -192
  141. package/src/utils/__tests__/terminal-color-detection.test.ts +0 -425
  142. package/src/utils/__tests__/terminal-command-broker.test.ts +0 -528
  143. package/src/utils/__tests__/terminal-enter-detection.test.ts +0 -77
  144. package/src/utils/__tests__/terminal-io.test.ts +0 -137
  145. package/src/utils/__tests__/terminal-protocol-controller.test.ts +0 -119
  146. package/src/utils/__tests__/text-layout.test.ts +0 -82
  147. package/src/utils/__tests__/theme-platform-detection.test.ts +0 -125
  148. package/src/utils/__tests__/think-tag-parser.test.ts +0 -159
  149. package/src/utils/__tests__/trace-writer.test.ts +0 -223
  150. package/src/utils/__tests__/trim-chat-logs.test.ts +0 -78
  151. package/src/utils/__tests__/usage-banner-state.test.ts +0 -298
  152. package/src/utils/__tests__/validation-error-formatting.test.ts +0 -126
  153. package/src/utils/__tests__/windows-terminal-health.test.ts +0 -101
  154. package/src/utils/__tests__/write-file-atomic.test.ts +0 -127
  155. package/vendor/@anvil/common/src/__tests__/agent-validation.test.ts +0 -846
  156. package/vendor/@anvil/common/src/__tests__/anvil-model-availability.test.ts +0 -101
  157. package/vendor/@anvil/common/src/__tests__/anvil-models.test.ts +0 -1408
  158. package/vendor/@anvil/common/src/__tests__/anvil-public-data-use-copy.test.ts +0 -258
  159. package/vendor/@anvil/common/src/__tests__/anvil-referral-tiers.test.ts +0 -48
  160. package/vendor/@anvil/common/src/__tests__/anvil-spend-ceilings.test.ts +0 -282
  161. package/vendor/@anvil/common/src/__tests__/anvil-trust.test.ts +0 -526
  162. package/vendor/@anvil/common/src/__tests__/deepseek-direct.test.ts +0 -68
  163. package/vendor/@anvil/common/src/__tests__/disposable-email.test.ts +0 -132
  164. package/vendor/@anvil/common/src/__tests__/dynamic-agent-template-schema.test.ts +0 -422
  165. package/vendor/@anvil/common/src/__tests__/env-ci.test.ts +0 -167
  166. package/vendor/@anvil/common/src/__tests__/env-process.test.ts +0 -145
  167. package/vendor/@anvil/common/src/__tests__/foreign-client-shipped-agents.test.ts +0 -234
  168. package/vendor/@anvil/common/src/__tests__/foreign-client-signals.test.ts +0 -379
  169. package/vendor/@anvil/common/src/__tests__/free-agents.test.ts +0 -807
  170. package/vendor/@anvil/common/src/__tests__/gravity-capi.test.ts +0 -154
  171. package/vendor/@anvil/common/src/__tests__/handlesteps-parsing.test.ts +0 -246
  172. package/vendor/@anvil/common/src/__tests__/kimi-k3-god-only.test.ts +0 -77
  173. package/vendor/@anvil/common/src/__tests__/model-config.test.ts +0 -89
  174. package/vendor/@anvil/common/src/__tests__/project-file-tree.test.ts +0 -298
  175. package/vendor/@anvil/common/src/__tests__/provisioned-model-tiers.test.ts +0 -116
  176. package/vendor/@anvil/common/src/__tests__/reasoning-effort.test.ts +0 -167
  177. package/vendor/@anvil/common/src/__tests__/reddit-capi.test.ts +0 -132
  178. package/vendor/@anvil/common/src/__tests__/response-ad-positions.test.ts +0 -72
  179. package/vendor/@anvil/common/src/__tests__/user-state.test.ts +0 -30
  180. package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding-gate.test.ts +0 -63
  181. package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding.test.ts +0 -246
  182. package/vendor/@anvil/common/src/constants/__tests__/cf-worker-signals.test.ts +0 -106
  183. package/vendor/@anvil/common/src/testing/TESTING_PATTERNS.md +0 -351
  184. package/vendor/@anvil/common/src/testing/anvil-offer-invariants.ts +0 -169
  185. package/vendor/@anvil/common/src/testing/errors.ts +0 -33
  186. package/vendor/@anvil/common/src/testing/fixtures/agent-runtime.ts +0 -334
  187. package/vendor/@anvil/common/src/testing/impl/agent-runtime.ts +0 -6
  188. package/vendor/@anvil/common/src/testing/index.ts +0 -84
  189. package/vendor/@anvil/common/src/testing/mock-modules.ts +0 -53
  190. package/vendor/@anvil/common/src/testing/mock-types.ts +0 -123
  191. package/vendor/@anvil/common/src/testing/mocks/analytics.ts +0 -261
  192. package/vendor/@anvil/common/src/testing/mocks/child-process.ts +0 -93
  193. package/vendor/@anvil/common/src/testing/mocks/crypto.ts +0 -218
  194. package/vendor/@anvil/common/src/testing/mocks/database.ts +0 -337
  195. package/vendor/@anvil/common/src/testing/mocks/fetch.ts +0 -219
  196. package/vendor/@anvil/common/src/testing/mocks/filesystem.ts +0 -166
  197. package/vendor/@anvil/common/src/testing/mocks/index.ts +0 -101
  198. package/vendor/@anvil/common/src/testing/mocks/logger.ts +0 -135
  199. package/vendor/@anvil/common/src/testing/mocks/stream.ts +0 -313
  200. package/vendor/@anvil/common/src/testing/mocks/timers.ts +0 -132
  201. package/vendor/@anvil/common/src/testing/mocks/tree-sitter.ts +0 -127
  202. package/vendor/@anvil/common/src/testing/setup.ts +0 -282
  203. package/vendor/@anvil/common/src/tools/__tests__/compile-tool-definitions.test.ts +0 -34
  204. package/vendor/@anvil/common/src/tools/params/__tests__/coerce-to-array.test.ts +0 -213
  205. package/vendor/@anvil/common/src/tools/params/__tests__/read-docs.test.ts +0 -47
  206. package/vendor/@anvil/common/src/tools/params/__tests__/render-ui.test.ts +0 -65
  207. package/vendor/@anvil/common/src/tools/params/tool/__tests__/run-terminal-command-timeout.test.ts +0 -49
  208. package/vendor/@anvil/common/src/types/__tests__/dynamic-agent-template.test.ts +0 -20
  209. package/vendor/@anvil/common/src/util/__tests__/ad-user-agent.test.ts +0 -26
  210. package/vendor/@anvil/common/src/util/__tests__/analytics-dispatcher.test.ts +0 -122
  211. package/vendor/@anvil/common/src/util/__tests__/analytics-log.test.ts +0 -102
  212. package/vendor/@anvil/common/src/util/__tests__/analytics-sampling.test.ts +0 -143
  213. package/vendor/@anvil/common/src/util/__tests__/anvil-streak.test.ts +0 -202
  214. package/vendor/@anvil/common/src/util/__tests__/anvil-usage-summary.test.ts +0 -193
  215. package/vendor/@anvil/common/src/util/__tests__/axiom-only-log.test.ts +0 -140
  216. package/vendor/@anvil/common/src/util/__tests__/client-user-agent.test.ts +0 -148
  217. package/vendor/@anvil/common/src/util/__tests__/engagement-tracker.test.ts +0 -115
  218. package/vendor/@anvil/common/src/util/__tests__/env-file-path.test.ts +0 -57
  219. package/vendor/@anvil/common/src/util/__tests__/error-abort.test.ts +0 -774
  220. package/vendor/@anvil/common/src/util/__tests__/error-api-details.test.ts +0 -206
  221. package/vendor/@anvil/common/src/util/__tests__/file-read-limits.test.ts +0 -173
  222. package/vendor/@anvil/common/src/util/__tests__/format-code-search.test.ts +0 -60
  223. package/vendor/@anvil/common/src/util/__tests__/log-mirror.test.ts +0 -31
  224. package/vendor/@anvil/common/src/util/__tests__/messages.test.ts +0 -1252
  225. package/vendor/@anvil/common/src/util/__tests__/partial-json-delta.test.ts +0 -505
  226. package/vendor/@anvil/common/src/util/__tests__/path.test.ts +0 -22
  227. package/vendor/@anvil/common/src/util/__tests__/project-ignore.test.ts +0 -90
  228. package/vendor/@anvil/common/src/util/__tests__/promise.test.ts +0 -325
  229. package/vendor/@anvil/common/src/util/__tests__/rate-limit.test.ts +0 -28
  230. package/vendor/@anvil/common/src/util/__tests__/reddit-anvil-retention.test.ts +0 -130
  231. package/vendor/@anvil/common/src/util/__tests__/saxy.test.ts +0 -1008
  232. package/vendor/@anvil/common/src/util/__tests__/split-data.test.ts +0 -289
  233. package/vendor/@anvil/common/src/util/__tests__/string.test.ts +0 -239
  234. package/vendor/@anvil/common/src/util/__tests__/thread-title.test.ts +0 -70
  235. package/vendor/@anvil/common/src/util/__tests__/tool-result-media-order.test.ts +0 -108
  236. package/vendor/@anvil/common/src/util/__tests__/ttft-histogram.test.ts +0 -180
  237. package/vendor/@anvil/common/src/util/__tests__/with-timeout.test.ts +0 -24
  238. package/vendor/@anvil/common/src/util/__tests__/zoned-time.test.ts +0 -88
  239. package/vendor/@anvil/common/src/util/skills.test.ts +0 -44
  240. package/vendor/@anvil/sdk/dist/index.cjs.map +0 -440
  241. package/vendor/@anvil/sdk/dist/index.mjs.map +0 -440
@@ -1,432 +0,0 @@
1
- /**
2
- * Integration tests for MultipleChoiceForm component logic
3
- *
4
- * NOTE: Due to React 19 + Bun + OpenTUI compatibility issues, we test the component's
5
- * core logic in isolation rather than rendering the full component.
6
- * See cli/knowledge.md for details on the testing constraints.
7
- */
8
-
9
- import { describe, it, expect } from 'bun:test'
10
-
11
- import { getOptionLabel, CUSTOM_OPTION_INDEX } from '../constants'
12
-
13
- import type { AccordionAnswer } from '../components/accordion-question'
14
- import type { AskUserOption } from '../constants'
15
-
16
- /** Question type - mirrors AskUserQuestion from chat-store */
17
- interface TestQuestion {
18
- question: string
19
- options: AskUserOption[]
20
- multiSelect?: boolean
21
- }
22
-
23
- /**
24
- * Format answer for submission (mirrors component logic)
25
- */
26
- function formatAnswer(
27
- question: TestQuestion,
28
- answer: AccordionAnswer | undefined,
29
- ): { question: string; answer: string } {
30
- if (!answer) {
31
- return { question: question.question, answer: 'Skipped' }
32
- }
33
-
34
- const selectedOptions = question.multiSelect
35
- ? Array.from(answer.selectedIndices ?? [])
36
- .map((idx) => getOptionLabel(question.options[idx]))
37
- .filter(Boolean)
38
- : answer.selectedIndex !== undefined
39
- ? [getOptionLabel(question.options[answer.selectedIndex])]
40
- : []
41
-
42
- const customText =
43
- answer.isCustom && (answer.customText?.trim().length ?? 0) > 0
44
- ? (answer.customText ?? '').trim()
45
- : ''
46
-
47
- const parts = customText ? [...selectedOptions, customText] : selectedOptions
48
- if (parts.length === 0) {
49
- return { question: question.question, answer: 'Skipped' }
50
- }
51
-
52
- return {
53
- question: question.question,
54
- answer: question.multiSelect ? parts.join(', ') : parts[0],
55
- }
56
- }
57
-
58
- describe('getOptionLabel', () => {
59
- it('extracts label from string option', () => {
60
- expect(getOptionLabel('Option A')).toBe('Option A')
61
- })
62
-
63
- it('extracts label from object option', () => {
64
- expect(
65
- getOptionLabel({ label: 'Option B', description: 'Description' }),
66
- ).toBe('Option B')
67
- })
68
-
69
- it('extracts label from object option without description', () => {
70
- expect(getOptionLabel({ label: 'Option C' })).toBe('Option C')
71
- })
72
-
73
- it('returns empty string for null-ish label', () => {
74
- expect(getOptionLabel({ label: '' })).toBe('')
75
- })
76
- })
77
-
78
- describe('formatAnswer', () => {
79
- const singleSelectQuestion: TestQuestion = {
80
- question: 'What is your favorite color?',
81
- options: ['Red', 'Blue', 'Green'],
82
- multiSelect: false,
83
- }
84
-
85
- const multiSelectQuestion: TestQuestion = {
86
- question: 'Select your hobbies',
87
- options: ['Reading', 'Gaming', 'Sports'],
88
- multiSelect: true,
89
- }
90
-
91
- const objectOptionsQuestion: TestQuestion = {
92
- question: 'Choose a plan',
93
- options: [
94
- { label: 'Basic', description: '$10/month' },
95
- { label: 'Pro', description: '$20/month' },
96
- ],
97
- multiSelect: false,
98
- }
99
-
100
- describe('single-select questions', () => {
101
- it('returns Skipped when no answer provided', () => {
102
- const result = formatAnswer(singleSelectQuestion, undefined)
103
- expect(result).toEqual({
104
- question: 'What is your favorite color?',
105
- answer: 'Skipped',
106
- })
107
- })
108
-
109
- it('returns Skipped when answer is empty object', () => {
110
- const result = formatAnswer(singleSelectQuestion, {})
111
- expect(result).toEqual({
112
- question: 'What is your favorite color?',
113
- answer: 'Skipped',
114
- })
115
- })
116
-
117
- it('returns selected option label', () => {
118
- const answer: AccordionAnswer = { selectedIndex: 1 }
119
- const result = formatAnswer(singleSelectQuestion, answer)
120
- expect(result).toEqual({
121
- question: 'What is your favorite color?',
122
- answer: 'Blue',
123
- })
124
- })
125
-
126
- it('returns first option when index is 0', () => {
127
- const answer: AccordionAnswer = { selectedIndex: 0 }
128
- const result = formatAnswer(singleSelectQuestion, answer)
129
- expect(result).toEqual({
130
- question: 'What is your favorite color?',
131
- answer: 'Red',
132
- })
133
- })
134
-
135
- it('returns custom text when isCustom is true', () => {
136
- const answer: AccordionAnswer = {
137
- isCustom: true,
138
- customText: 'Purple',
139
- }
140
- const result = formatAnswer(singleSelectQuestion, answer)
141
- expect(result).toEqual({
142
- question: 'What is your favorite color?',
143
- answer: 'Purple',
144
- })
145
- })
146
-
147
- it('trims whitespace from custom text', () => {
148
- const answer: AccordionAnswer = {
149
- isCustom: true,
150
- customText: ' Purple ',
151
- }
152
- const result = formatAnswer(singleSelectQuestion, answer)
153
- expect(result).toEqual({
154
- question: 'What is your favorite color?',
155
- answer: 'Purple',
156
- })
157
- })
158
-
159
- it('returns Skipped when isCustom is true but text is empty', () => {
160
- const answer: AccordionAnswer = {
161
- isCustom: true,
162
- customText: '',
163
- }
164
- const result = formatAnswer(singleSelectQuestion, answer)
165
- expect(result).toEqual({
166
- question: 'What is your favorite color?',
167
- answer: 'Skipped',
168
- })
169
- })
170
-
171
- it('returns Skipped when isCustom is true but text is only whitespace', () => {
172
- const answer: AccordionAnswer = {
173
- isCustom: true,
174
- customText: ' ',
175
- }
176
- const result = formatAnswer(singleSelectQuestion, answer)
177
- expect(result).toEqual({
178
- question: 'What is your favorite color?',
179
- answer: 'Skipped',
180
- })
181
- })
182
- })
183
-
184
- describe('multi-select questions', () => {
185
- it('returns Skipped when no selections', () => {
186
- const answer: AccordionAnswer = { selectedIndices: new Set() }
187
- const result = formatAnswer(multiSelectQuestion, answer)
188
- expect(result).toEqual({
189
- question: 'Select your hobbies',
190
- answer: 'Skipped',
191
- })
192
- })
193
-
194
- it('returns single selection', () => {
195
- const answer: AccordionAnswer = { selectedIndices: new Set([0]) }
196
- const result = formatAnswer(multiSelectQuestion, answer)
197
- expect(result).toEqual({
198
- question: 'Select your hobbies',
199
- answer: 'Reading',
200
- })
201
- })
202
-
203
- it('returns multiple selections joined by comma', () => {
204
- const answer: AccordionAnswer = { selectedIndices: new Set([0, 2]) }
205
- const result = formatAnswer(multiSelectQuestion, answer)
206
- expect(result).toEqual({
207
- question: 'Select your hobbies',
208
- answer: 'Reading, Sports',
209
- })
210
- })
211
-
212
- it('returns all selections when all selected', () => {
213
- const answer: AccordionAnswer = { selectedIndices: new Set([0, 1, 2]) }
214
- const result = formatAnswer(multiSelectQuestion, answer)
215
- expect(result).toEqual({
216
- question: 'Select your hobbies',
217
- answer: 'Reading, Gaming, Sports',
218
- })
219
- })
220
-
221
- it('includes custom text with selections', () => {
222
- const answer: AccordionAnswer = {
223
- selectedIndices: new Set([0]),
224
- isCustom: true,
225
- customText: 'Cooking',
226
- }
227
- const result = formatAnswer(multiSelectQuestion, answer)
228
- expect(result).toEqual({
229
- question: 'Select your hobbies',
230
- answer: 'Reading, Cooking',
231
- })
232
- })
233
-
234
- it('returns only custom text when no other selections', () => {
235
- const answer: AccordionAnswer = {
236
- selectedIndices: new Set(),
237
- isCustom: true,
238
- customText: 'Cooking',
239
- }
240
- const result = formatAnswer(multiSelectQuestion, answer)
241
- expect(result).toEqual({
242
- question: 'Select your hobbies',
243
- answer: 'Cooking',
244
- })
245
- })
246
- })
247
-
248
- describe('object options', () => {
249
- it('extracts label from object options', () => {
250
- const answer: AccordionAnswer = { selectedIndex: 0 }
251
- const result = formatAnswer(objectOptionsQuestion, answer)
252
- expect(result).toEqual({
253
- question: 'Choose a plan',
254
- answer: 'Basic',
255
- })
256
- })
257
-
258
- it('works with second object option', () => {
259
- const answer: AccordionAnswer = { selectedIndex: 1 }
260
- const result = formatAnswer(objectOptionsQuestion, answer)
261
- expect(result).toEqual({
262
- question: 'Choose a plan',
263
- answer: 'Pro',
264
- })
265
- })
266
- })
267
- })
268
-
269
- describe('CUSTOM_OPTION_INDEX constant', () => {
270
- it('is -1 for identifying custom option', () => {
271
- expect(CUSTOM_OPTION_INDEX).toBe(-1)
272
- })
273
-
274
- it('is distinct from valid option indices', () => {
275
- expect(CUSTOM_OPTION_INDEX).toBeLessThan(0)
276
- })
277
- })
278
-
279
- describe('answer state management patterns', () => {
280
- describe('single-select behavior', () => {
281
- it('selecting an option clears isCustom flag', () => {
282
- const previousAnswer: AccordionAnswer = {
283
- isCustom: true,
284
- customText: 'Custom text',
285
- }
286
-
287
- const optionIndex: number = 1
288
- const isCustomOption = optionIndex === CUSTOM_OPTION_INDEX
289
-
290
- const newAnswer: AccordionAnswer = isCustomOption
291
- ? {
292
- selectedIndex: undefined,
293
- selectedIndices: undefined,
294
- isCustom: true,
295
- customText: previousAnswer.customText || '',
296
- }
297
- : {
298
- selectedIndex: optionIndex,
299
- selectedIndices: undefined,
300
- isCustom: false,
301
- }
302
-
303
- expect(newAnswer.selectedIndex).toBe(1)
304
- expect(newAnswer.isCustom).toBe(false)
305
- })
306
-
307
- it('selecting CUSTOM clears selectedIndex and enables isCustom', () => {
308
- const previousAnswer: AccordionAnswer = {
309
- selectedIndex: 1,
310
- }
311
-
312
- const optionIndex = CUSTOM_OPTION_INDEX
313
- const isCustomOption = optionIndex === CUSTOM_OPTION_INDEX
314
-
315
- const newAnswer: AccordionAnswer = isCustomOption
316
- ? {
317
- selectedIndex: undefined,
318
- selectedIndices: undefined,
319
- isCustom: true,
320
- customText: previousAnswer.customText || '',
321
- }
322
- : {
323
- selectedIndex: optionIndex,
324
- selectedIndices: undefined,
325
- isCustom: false,
326
- }
327
-
328
- expect(newAnswer.selectedIndex).toBeUndefined()
329
- expect(newAnswer.isCustom).toBe(true)
330
- })
331
- })
332
-
333
- describe('multi-select behavior', () => {
334
- it('toggling adds option to selectedIndices', () => {
335
- const currentAnswer: AccordionAnswer = {
336
- selectedIndices: new Set([0]),
337
- }
338
-
339
- const optionIndex = 2
340
- const newIndices = new Set(currentAnswer.selectedIndices)
341
- if (newIndices.has(optionIndex)) {
342
- newIndices.delete(optionIndex)
343
- } else {
344
- newIndices.add(optionIndex)
345
- }
346
-
347
- expect(newIndices.has(0)).toBe(true)
348
- expect(newIndices.has(2)).toBe(true)
349
- expect(newIndices.size).toBe(2)
350
- })
351
-
352
- it('toggling removes option if already selected', () => {
353
- const currentAnswer: AccordionAnswer = {
354
- selectedIndices: new Set([0, 1, 2]),
355
- }
356
-
357
- const optionIndex = 1
358
- const newIndices = new Set(currentAnswer.selectedIndices)
359
- if (newIndices.has(optionIndex)) {
360
- newIndices.delete(optionIndex)
361
- } else {
362
- newIndices.add(optionIndex)
363
- }
364
-
365
- expect(newIndices.has(0)).toBe(true)
366
- expect(newIndices.has(1)).toBe(false)
367
- expect(newIndices.has(2)).toBe(true)
368
- expect(newIndices.size).toBe(2)
369
- })
370
-
371
- it('toggling CUSTOM toggles isCustom flag', () => {
372
- const currentAnswer: AccordionAnswer = {
373
- selectedIndices: new Set([0]),
374
- isCustom: false,
375
- }
376
-
377
- const optionIndex = CUSTOM_OPTION_INDEX
378
- const toggledCustomOn =
379
- optionIndex === CUSTOM_OPTION_INDEX && !currentAnswer.isCustom
380
-
381
- expect(toggledCustomOn).toBe(true)
382
- })
383
- })
384
- })
385
-
386
- describe('navigation edge cases', () => {
387
- it('clamps question index to valid range', () => {
388
- const questionsLength = 3
389
- const focusedQuestionIndex = 5
390
-
391
- const currentQuestionIndex = Math.min(
392
- Math.max(focusedQuestionIndex, 0),
393
- questionsLength - 1,
394
- )
395
-
396
- expect(currentQuestionIndex).toBe(2)
397
- })
398
-
399
- it('clamps negative question index to 0', () => {
400
- const questionsLength = 3
401
- const focusedQuestionIndex = -1
402
-
403
- const currentQuestionIndex = Math.min(
404
- Math.max(focusedQuestionIndex, 0),
405
- questionsLength - 1,
406
- )
407
-
408
- expect(currentQuestionIndex).toBe(0)
409
- })
410
-
411
- it('clamps option index to valid range', () => {
412
- const optionCount = 4
413
- const focusedOptionIndex = 10
414
-
415
- const lastOptionIndex = Math.max(optionCount - 1, 0)
416
- const currentOptionIndex = Math.min(
417
- Math.max(focusedOptionIndex, 0),
418
- lastOptionIndex,
419
- )
420
-
421
- expect(currentOptionIndex).toBe(3)
422
- })
423
-
424
- it('handles empty questions array', () => {
425
- const questionsLength = 0
426
- const expandedIndex = questionsLength > 0 ? 0 : null
427
- const focusedOptionIndex = questionsLength > 0 ? 0 : null
428
-
429
- expect(expandedIndex).toBeNull()
430
- expect(focusedOptionIndex).toBeNull()
431
- })
432
- })
@@ -1,213 +0,0 @@
1
- /**
2
- * Unit tests for validation.ts
3
- * Testing validation logic for text input
4
- */
5
-
6
- import { describe, it, expect } from 'bun:test'
7
-
8
- import {
9
- validateOtherText,
10
- isTextEmpty,
11
- sanitizeTextInput,
12
- } from '../utils/validation'
13
-
14
- import type { QuestionValidation } from '../utils/validation'
15
-
16
- describe('validateOtherText', () => {
17
- describe('default max length validation', () => {
18
- it('accepts text within default limit (500 chars)', () => {
19
- const text = 'a'.repeat(500)
20
- const result = validateOtherText(text)
21
- expect(result.isValid).toBe(true)
22
- expect(result.error).toBeUndefined()
23
- })
24
-
25
- it('rejects text exceeding default limit', () => {
26
- const text = 'a'.repeat(501)
27
- const result = validateOtherText(text)
28
- expect(result.isValid).toBe(false)
29
- expect(result.error).toBe('Max 500 characters')
30
- })
31
-
32
- it('accepts empty text', () => {
33
- const result = validateOtherText('')
34
- expect(result.isValid).toBe(true)
35
- })
36
- })
37
-
38
- describe('custom max length validation', () => {
39
- const validation: QuestionValidation = {
40
- maxLength: 10,
41
- }
42
-
43
- it('accepts text within custom limit', () => {
44
- const result = validateOtherText('hello', validation)
45
- expect(result.isValid).toBe(true)
46
- })
47
-
48
- it('rejects text exceeding custom limit', () => {
49
- const result = validateOtherText('hello world!', validation)
50
- expect(result.isValid).toBe(false)
51
- expect(result.error).toBe('Max 10 characters')
52
- })
53
- })
54
-
55
- describe('min length validation', () => {
56
- const validation: QuestionValidation = {
57
- minLength: 5,
58
- }
59
-
60
- it('accepts text meeting minimum', () => {
61
- const result = validateOtherText('hello', validation)
62
- expect(result.isValid).toBe(true)
63
- })
64
-
65
- it('rejects text below minimum', () => {
66
- const result = validateOtherText('hi', validation)
67
- expect(result.isValid).toBe(false)
68
- expect(result.error).toBe('Min 5 characters')
69
- })
70
- })
71
-
72
- describe('pattern (regex) validation', () => {
73
- it('validates email pattern', () => {
74
- const validation: QuestionValidation = {
75
- pattern: '^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$',
76
- patternError: 'Please enter a valid email',
77
- }
78
-
79
- const validResult = validateOtherText('test@example.com', validation)
80
- expect(validResult.isValid).toBe(true)
81
-
82
- const invalidResult = validateOtherText('not-an-email', validation)
83
- expect(invalidResult.isValid).toBe(false)
84
- expect(invalidResult.error).toBe('Please enter a valid email')
85
- })
86
-
87
- it('validates number pattern', () => {
88
- const validation: QuestionValidation = {
89
- pattern: '^\\d+$',
90
- patternError: 'Numbers only',
91
- }
92
-
93
- expect(validateOtherText('12345', validation).isValid).toBe(true)
94
- expect(validateOtherText('abc123', validation).isValid).toBe(false)
95
- })
96
-
97
- it('uses default error message when patternError not provided', () => {
98
- const validation: QuestionValidation = {
99
- pattern: '^\\d+$',
100
- }
101
-
102
- const result = validateOtherText('abc', validation)
103
- expect(result.isValid).toBe(false)
104
- expect(result.error).toBe('Invalid format')
105
- })
106
-
107
- it('accepts empty text when pattern provided', () => {
108
- const validation: QuestionValidation = {
109
- pattern: '^\\d+$',
110
- }
111
-
112
- const result = validateOtherText('', validation)
113
- expect(result.isValid).toBe(true) // Empty bypasses pattern check
114
- })
115
- })
116
-
117
- describe('combined validations', () => {
118
- it('checks all validations in order', () => {
119
- const validation: QuestionValidation = {
120
- minLength: 5,
121
- maxLength: 10,
122
- pattern: '^[a-zA-Z]+$',
123
- patternError: 'Letters only',
124
- }
125
-
126
- // Too short
127
- expect(validateOtherText('hi', validation).isValid).toBe(false)
128
-
129
- // Too long
130
- expect(validateOtherText('hello world', validation).isValid).toBe(false)
131
-
132
- // Invalid pattern
133
- const patternResult = validateOtherText('hello1', validation)
134
- expect(patternResult.isValid).toBe(false)
135
- expect(patternResult.error).toBe('Letters only')
136
-
137
- // Valid
138
- expect(validateOtherText('hello', validation).isValid).toBe(true)
139
- })
140
- })
141
-
142
- describe('no validation rules', () => {
143
- it('accepts any text when no validation provided', () => {
144
- expect(validateOtherText('anything').isValid).toBe(true)
145
- expect(validateOtherText('').isValid).toBe(true)
146
- expect(validateOtherText('a'.repeat(1000)).isValid).toBe(false) // Still checks default max
147
- })
148
- })
149
- })
150
-
151
- describe('isTextEmpty', () => {
152
- it('returns true for undefined', () => {
153
- expect(isTextEmpty(undefined)).toBe(true)
154
- })
155
-
156
- it('returns true for empty string', () => {
157
- expect(isTextEmpty('')).toBe(true)
158
- })
159
-
160
- it('returns true for whitespace only', () => {
161
- expect(isTextEmpty(' ')).toBe(true)
162
- expect(isTextEmpty('\t\n ')).toBe(true)
163
- })
164
-
165
- it('returns false for text with content', () => {
166
- expect(isTextEmpty('hello')).toBe(false)
167
- expect(isTextEmpty(' hello ')).toBe(false)
168
- })
169
- })
170
-
171
- describe('sanitizeTextInput', () => {
172
- it('removes control characters', () => {
173
- const input = 'hello\x00world\x1F'
174
- const result = sanitizeTextInput(input)
175
- expect(result).toBe('hello world')
176
- })
177
-
178
- it('collapses multiple spaces', () => {
179
- const input = 'hello world'
180
- const result = sanitizeTextInput(input)
181
- expect(result).toBe('hello world')
182
- })
183
-
184
- it('trims leading and trailing whitespace', () => {
185
- const input = ' hello world '
186
- const result = sanitizeTextInput(input)
187
- expect(result).toBe('hello world')
188
- })
189
-
190
- it('handles tabs and newlines', () => {
191
- const input = 'hello\t\nworld'
192
- const result = sanitizeTextInput(input)
193
- expect(result).toBe('hello world')
194
- })
195
-
196
- it('combines all sanitization', () => {
197
- const input = ' hello\x00\x01 \t\n world\x7F '
198
- const result = sanitizeTextInput(input)
199
- expect(result).toBe('hello world')
200
- })
201
-
202
- it('returns empty string for whitespace-only input', () => {
203
- const input = ' \t\n '
204
- const result = sanitizeTextInput(input)
205
- expect(result).toBe('')
206
- })
207
-
208
- it('preserves valid special characters', () => {
209
- const input = 'hello@example.com'
210
- const result = sanitizeTextInput(input)
211
- expect(result).toBe('hello@example.com')
212
- })
213
- })