@nyaruka/temba-components 0.129.8 → 0.129.9

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 (203) hide show
  1. package/CHANGELOG.md +27 -3
  2. package/demo/data/flows/sample-flow.json +186 -96
  3. package/dist/temba-components.js +414 -351
  4. package/dist/temba-components.js.map +1 -1
  5. package/out-tsc/src/events.js.map +1 -1
  6. package/out-tsc/src/excellent/helpers.js +2 -2
  7. package/out-tsc/src/excellent/helpers.js.map +1 -1
  8. package/out-tsc/src/flow/CanvasNode.js +25 -7
  9. package/out-tsc/src/flow/CanvasNode.js.map +1 -1
  10. package/out-tsc/src/flow/Editor.js +11 -1
  11. package/out-tsc/src/flow/Editor.js.map +1 -1
  12. package/out-tsc/src/flow/NodeEditor.js +133 -290
  13. package/out-tsc/src/flow/NodeEditor.js.map +1 -1
  14. package/out-tsc/src/flow/actions/add_input_labels.js +40 -0
  15. package/out-tsc/src/flow/actions/add_input_labels.js.map +1 -1
  16. package/out-tsc/src/flow/actions/call_llm.js +56 -3
  17. package/out-tsc/src/flow/actions/call_llm.js.map +1 -1
  18. package/out-tsc/src/flow/actions/call_webhook.js +1 -1
  19. package/out-tsc/src/flow/actions/call_webhook.js.map +1 -1
  20. package/out-tsc/src/flow/actions/open_ticket.js +65 -3
  21. package/out-tsc/src/flow/actions/open_ticket.js.map +1 -1
  22. package/out-tsc/src/flow/actions/set_run_result.js +75 -0
  23. package/out-tsc/src/flow/actions/set_run_result.js.map +1 -1
  24. package/out-tsc/src/flow/config.js +4 -0
  25. package/out-tsc/src/flow/config.js.map +1 -1
  26. package/out-tsc/src/flow/nodes/split_by_llm_categorize.js +227 -0
  27. package/out-tsc/src/flow/nodes/split_by_llm_categorize.js.map +1 -0
  28. package/out-tsc/src/flow/nodes/split_by_ticket.js +18 -0
  29. package/out-tsc/src/flow/nodes/split_by_ticket.js.map +1 -0
  30. package/out-tsc/src/flow/nodes/wait_for_response.js +27 -1
  31. package/out-tsc/src/flow/nodes/wait_for_response.js.map +1 -1
  32. package/out-tsc/src/flow/types.js +0 -65
  33. package/out-tsc/src/flow/types.js.map +1 -1
  34. package/out-tsc/src/form/ArrayEditor.js +18 -61
  35. package/out-tsc/src/form/ArrayEditor.js.map +1 -1
  36. package/out-tsc/src/form/FieldRenderer.js +305 -0
  37. package/out-tsc/src/form/FieldRenderer.js.map +1 -0
  38. package/out-tsc/src/form/FormField.js +3 -3
  39. package/out-tsc/src/form/FormField.js.map +1 -1
  40. package/out-tsc/src/form/TextInput.js +1 -1
  41. package/out-tsc/src/form/TextInput.js.map +1 -1
  42. package/out-tsc/src/form/select/Select.js +48 -20
  43. package/out-tsc/src/form/select/Select.js.map +1 -1
  44. package/out-tsc/src/live/ContactChat.js +39 -13
  45. package/out-tsc/src/live/ContactChat.js.map +1 -1
  46. package/out-tsc/src/markdown.js +13 -11
  47. package/out-tsc/src/markdown.js.map +1 -1
  48. package/out-tsc/test/ActionHelper.js +2 -0
  49. package/out-tsc/test/ActionHelper.js.map +1 -1
  50. package/out-tsc/test/NodeHelper.js +148 -0
  51. package/out-tsc/test/NodeHelper.js.map +1 -0
  52. package/out-tsc/test/actions/call_llm.test.js +103 -0
  53. package/out-tsc/test/actions/call_llm.test.js.map +1 -0
  54. package/out-tsc/test/nodes/split_by_llm_categorize.test.js +532 -0
  55. package/out-tsc/test/nodes/split_by_llm_categorize.test.js.map +1 -0
  56. package/out-tsc/test/nodes/split_by_random.test.js +150 -0
  57. package/out-tsc/test/nodes/split_by_random.test.js.map +1 -0
  58. package/out-tsc/test/nodes/wait_for_digits.test.js +150 -0
  59. package/out-tsc/test/nodes/wait_for_digits.test.js.map +1 -0
  60. package/out-tsc/test/nodes/wait_for_response.test.js +171 -0
  61. package/out-tsc/test/nodes/wait_for_response.test.js.map +1 -0
  62. package/out-tsc/test/temba-add-input-labels.test.js +70 -0
  63. package/out-tsc/test/temba-add-input-labels.test.js.map +1 -0
  64. package/out-tsc/test/temba-field-renderer.test.js +296 -0
  65. package/out-tsc/test/temba-field-renderer.test.js.map +1 -0
  66. package/out-tsc/test/temba-markdown.test.js +1 -1
  67. package/out-tsc/test/temba-markdown.test.js.map +1 -1
  68. package/out-tsc/test/temba-node-editor.test.js +400 -0
  69. package/out-tsc/test/temba-node-editor.test.js.map +1 -1
  70. package/out-tsc/test/temba-select.test.js +6 -3
  71. package/out-tsc/test/temba-select.test.js.map +1 -1
  72. package/out-tsc/test/temba-webchat.test.js +1 -1
  73. package/out-tsc/test/temba-webchat.test.js.map +1 -1
  74. package/package.json +1 -1
  75. package/screenshots/truth/actions/add_contact_groups/editor/descriptive-group-names.png +0 -0
  76. package/screenshots/truth/actions/add_contact_groups/editor/long-group-names.png +0 -0
  77. package/screenshots/truth/actions/add_contact_groups/editor/many-groups.png +0 -0
  78. package/screenshots/truth/actions/call_llm/editor/information-extraction.png +0 -0
  79. package/screenshots/truth/actions/call_llm/editor/sentiment-analysis.png +0 -0
  80. package/screenshots/truth/actions/call_llm/editor/summarization.png +0 -0
  81. package/screenshots/truth/actions/call_llm/editor/translation-task.png +0 -0
  82. package/screenshots/truth/actions/call_llm/render/information-extraction.png +0 -0
  83. package/screenshots/truth/actions/call_llm/render/sentiment-analysis.png +0 -0
  84. package/screenshots/truth/actions/call_llm/render/summarization.png +0 -0
  85. package/screenshots/truth/actions/call_llm/render/translation-task.png +0 -0
  86. package/screenshots/truth/actions/remove_contact_groups/editor/long-descriptive-group-names.png +0 -0
  87. package/screenshots/truth/actions/remove_contact_groups/editor/many-groups.png +0 -0
  88. package/screenshots/truth/actions/remove_contact_groups/editor/remove-from-all-groups.png +0 -0
  89. package/screenshots/truth/actions/send_email/editor/complex-business-email.png +0 -0
  90. package/screenshots/truth/actions/send_email/editor/multiple-recipients.png +0 -0
  91. package/screenshots/truth/actions/send_msg/editor/long-quick-replies.png +0 -0
  92. package/screenshots/truth/actions/send_msg/editor/multiline-text-with-replies.png +0 -0
  93. package/screenshots/truth/actions/send_msg/editor/simple-text.png +0 -0
  94. package/screenshots/truth/actions/send_msg/editor/text-with-linebreaks.png +0 -0
  95. package/screenshots/truth/actions/send_msg/editor/text-with-many-quick-replies.png +0 -0
  96. package/screenshots/truth/actions/send_msg/editor/text-with-quick-replies.png +0 -0
  97. package/screenshots/truth/actions/send_msg/editor/text-without-quick-replies.png +0 -0
  98. package/screenshots/truth/editor/router.png +0 -0
  99. package/screenshots/truth/editor/send_msg.png +0 -0
  100. package/screenshots/truth/editor/set_contact_language.png +0 -0
  101. package/screenshots/truth/editor/set_contact_name.png +0 -0
  102. package/screenshots/truth/editor/set_run_result.png +0 -0
  103. package/screenshots/truth/editor/wait.png +0 -0
  104. package/screenshots/truth/field-renderer/checkbox-checked.png +0 -0
  105. package/screenshots/truth/field-renderer/checkbox-unchecked.png +0 -0
  106. package/screenshots/truth/field-renderer/checkbox-with-errors.png +0 -0
  107. package/screenshots/truth/field-renderer/context-comparison.png +0 -0
  108. package/screenshots/truth/field-renderer/key-value-with-label.png +0 -0
  109. package/screenshots/truth/field-renderer/message-editor-with-label.png +0 -0
  110. package/screenshots/truth/field-renderer/select-multi.png +0 -0
  111. package/screenshots/truth/field-renderer/select-no-label.png +0 -0
  112. package/screenshots/truth/field-renderer/select-with-label.png +0 -0
  113. package/screenshots/truth/field-renderer/text-evaluated.png +0 -0
  114. package/screenshots/truth/field-renderer/text-no-label.png +0 -0
  115. package/screenshots/truth/field-renderer/text-with-errors.png +0 -0
  116. package/screenshots/truth/field-renderer/text-with-label.png +0 -0
  117. package/screenshots/truth/field-renderer/textarea-evaluated.png +0 -0
  118. package/screenshots/truth/field-renderer/textarea-with-label.png +0 -0
  119. package/screenshots/truth/nodes/split_by_llm_categorize/editor/basic-categorization.png +0 -0
  120. package/screenshots/truth/nodes/split_by_llm_categorize/editor/custom-input-and-result-name.png +0 -0
  121. package/screenshots/truth/nodes/split_by_llm_categorize/editor/feedback-categorization.png +0 -0
  122. package/screenshots/truth/nodes/split_by_llm_categorize/editor/many-categories.png +0 -0
  123. package/screenshots/truth/nodes/split_by_llm_categorize/editor/minimal-categories.png +0 -0
  124. package/screenshots/truth/nodes/split_by_llm_categorize/render/basic-categorization.png +0 -0
  125. package/screenshots/truth/nodes/split_by_llm_categorize/render/custom-input-and-result-name.png +0 -0
  126. package/screenshots/truth/nodes/split_by_llm_categorize/render/feedback-categorization.png +0 -0
  127. package/screenshots/truth/nodes/split_by_llm_categorize/render/many-categories.png +0 -0
  128. package/screenshots/truth/nodes/split_by_llm_categorize/render/minimal-categories.png +0 -0
  129. package/screenshots/truth/nodes/split_by_random/editor/ab-test-multiple-variants.png +0 -0
  130. package/screenshots/truth/nodes/split_by_random/editor/sampling-split.png +0 -0
  131. package/screenshots/truth/nodes/split_by_random/editor/three-way-split.png +0 -0
  132. package/screenshots/truth/nodes/split_by_random/editor/two-bucket-split.png +0 -0
  133. package/screenshots/truth/nodes/split_by_random/render/ab-test-multiple-variants.png +0 -0
  134. package/screenshots/truth/nodes/split_by_random/render/sampling-split.png +0 -0
  135. package/screenshots/truth/nodes/split_by_random/render/three-way-split.png +0 -0
  136. package/screenshots/truth/nodes/split_by_random/render/two-bucket-split.png +0 -0
  137. package/screenshots/truth/nodes/wait_for_digits/editor/basic-digits-wait.png +0 -0
  138. package/screenshots/truth/nodes/wait_for_digits/editor/phone-number-collection.png +0 -0
  139. package/screenshots/truth/nodes/wait_for_digits/editor/single-digit-with-timeout.png +0 -0
  140. package/screenshots/truth/nodes/wait_for_digits/editor/verification-code.png +0 -0
  141. package/screenshots/truth/nodes/wait_for_digits/render/basic-digits-wait.png +0 -0
  142. package/screenshots/truth/nodes/wait_for_digits/render/phone-number-collection.png +0 -0
  143. package/screenshots/truth/nodes/wait_for_digits/render/single-digit-with-timeout.png +0 -0
  144. package/screenshots/truth/nodes/wait_for_digits/render/verification-code.png +0 -0
  145. package/screenshots/truth/nodes/wait_for_response/editor/basic-wait.png +0 -0
  146. package/screenshots/truth/nodes/wait_for_response/editor/custom-result-name.png +0 -0
  147. package/screenshots/truth/nodes/wait_for_response/editor/no-timeout.png +0 -0
  148. package/screenshots/truth/nodes/wait_for_response/editor/short-timeout.png +0 -0
  149. package/screenshots/truth/nodes/wait_for_response/render/basic-wait.png +0 -0
  150. package/screenshots/truth/nodes/wait_for_response/render/custom-result-name.png +0 -0
  151. package/screenshots/truth/nodes/wait_for_response/render/no-timeout.png +0 -0
  152. package/screenshots/truth/nodes/wait_for_response/render/short-timeout.png +0 -0
  153. package/screenshots/truth/omnibox/selected.png +0 -0
  154. package/screenshots/truth/select/functions.png +0 -0
  155. package/screenshots/truth/select/multi-with-endpoint.png +0 -0
  156. package/screenshots/truth/select/search-enabled.png +0 -0
  157. package/src/events.ts +8 -1
  158. package/src/excellent/helpers.ts +2 -2
  159. package/src/flow/CanvasNode.ts +22 -1
  160. package/src/flow/Editor.ts +12 -1
  161. package/src/flow/NodeEditor.ts +186 -374
  162. package/src/flow/actions/add_input_labels.ts +45 -0
  163. package/src/flow/actions/call_llm.ts +57 -3
  164. package/src/flow/actions/call_webhook.ts +1 -1
  165. package/src/flow/actions/open_ticket.ts +74 -3
  166. package/src/flow/actions/set_run_result.ts +83 -0
  167. package/src/flow/config.ts +4 -0
  168. package/src/flow/nodes/split_by_llm_categorize.ts +277 -0
  169. package/src/flow/nodes/split_by_ticket.ts +19 -0
  170. package/src/flow/nodes/wait_for_response.ts +28 -1
  171. package/src/flow/types.ts +26 -127
  172. package/src/form/ArrayEditor.ts +34 -82
  173. package/src/form/FieldRenderer.ts +465 -0
  174. package/src/form/FormField.ts +3 -3
  175. package/src/form/TextInput.ts +1 -1
  176. package/src/form/select/Select.ts +51 -20
  177. package/src/live/ContactChat.ts +39 -15
  178. package/src/markdown.ts +19 -11
  179. package/src/store/flow-definition.d.ts +5 -2
  180. package/static/api/labels.json +31 -0
  181. package/static/api/topics.json +24 -9
  182. package/static/api/users.json +35 -16
  183. package/static/css/temba-components.css +3 -3
  184. package/stress-test.js +18 -13
  185. package/test/ActionHelper.ts +2 -0
  186. package/test/NodeHelper.ts +184 -0
  187. package/test/actions/call_llm.test.ts +137 -0
  188. package/test/nodes/README.md +78 -0
  189. package/test/nodes/split_by_llm_categorize.test.ts +698 -0
  190. package/test/nodes/split_by_random.test.ts +177 -0
  191. package/test/nodes/wait_for_digits.test.ts +176 -0
  192. package/test/nodes/wait_for_response.test.ts +206 -0
  193. package/test/temba-add-input-labels.test.ts +87 -0
  194. package/test/temba-field-renderer.test.ts +482 -0
  195. package/test/temba-markdown.test.ts +1 -1
  196. package/test/temba-node-editor.test.ts +496 -0
  197. package/test/temba-select.test.ts +6 -6
  198. package/test/temba-webchat.test.ts +1 -1
  199. package/test-assets/select/llms.json +18 -0
  200. package/web-dev-mock.mjs +96 -6
  201. package/web-dev-server.config.mjs +29 -7
  202. package/test/temba-flow-editor.test.ts.backup +0 -563
  203. package/test/temba-utils-index.test.ts.backup +0 -1737
@@ -0,0 +1,177 @@
1
+ import { expect } from '@open-wc/testing';
2
+ import { split_by_random } from '../../src/flow/nodes/split_by_random';
3
+ import { Node } from '../../src/store/flow-definition';
4
+ import { NodeTest } from '../NodeHelper';
5
+
6
+ /**
7
+ * Test suite for the split_by_random node configuration.
8
+ */
9
+ describe('split_by_random node config', () => {
10
+ const helper = new NodeTest(split_by_random, 'split_by_random');
11
+
12
+ describe('basic properties', () => {
13
+ helper.testBasicProperties();
14
+
15
+ it('has correct name', () => {
16
+ expect(split_by_random.name).to.equal('Split by Random');
17
+ });
18
+
19
+ it('has correct type', () => {
20
+ expect(split_by_random.type).to.equal('split_by_random');
21
+ });
22
+
23
+ it('has correct color', () => {
24
+ expect(split_by_random.color).to.exist;
25
+ });
26
+
27
+ it('has router configuration', () => {
28
+ expect(split_by_random.router).to.exist;
29
+ expect(split_by_random.router.type).to.equal('random');
30
+ });
31
+
32
+ it('is a simple node config without form or layout', () => {
33
+ expect(split_by_random.form).to.be.undefined;
34
+ expect(split_by_random.layout).to.be.undefined;
35
+ expect(split_by_random.toFormData).to.be.undefined;
36
+ expect(split_by_random.fromFormData).to.be.undefined;
37
+ });
38
+ });
39
+
40
+ describe('node scenarios', () => {
41
+ helper.testNode(
42
+ {
43
+ uuid: 'test-random-node-1',
44
+ actions: [],
45
+ router: {
46
+ type: 'random',
47
+ categories: [
48
+ {
49
+ uuid: 'random-cat-1',
50
+ name: 'Bucket A',
51
+ exit_uuid: 'random-exit-1'
52
+ },
53
+ {
54
+ uuid: 'random-cat-2',
55
+ name: 'Bucket B',
56
+ exit_uuid: 'random-exit-2'
57
+ }
58
+ ]
59
+ },
60
+ exits: [
61
+ { uuid: 'random-exit-1', destination_uuid: null },
62
+ { uuid: 'random-exit-2', destination_uuid: null }
63
+ ]
64
+ } as Node,
65
+ { type: 'split_by_random' },
66
+ 'two-bucket-split'
67
+ );
68
+
69
+ helper.testNode(
70
+ {
71
+ uuid: 'test-random-node-2',
72
+ actions: [],
73
+ router: {
74
+ type: 'random',
75
+ categories: [
76
+ {
77
+ uuid: 'random-cat-1',
78
+ name: 'Group A',
79
+ exit_uuid: 'random-exit-1'
80
+ },
81
+ {
82
+ uuid: 'random-cat-2',
83
+ name: 'Group B',
84
+ exit_uuid: 'random-exit-2'
85
+ },
86
+ {
87
+ uuid: 'random-cat-3',
88
+ name: 'Group C',
89
+ exit_uuid: 'random-exit-3'
90
+ }
91
+ ]
92
+ },
93
+ exits: [
94
+ { uuid: 'random-exit-1', destination_uuid: null },
95
+ { uuid: 'random-exit-2', destination_uuid: null },
96
+ { uuid: 'random-exit-3', destination_uuid: null }
97
+ ]
98
+ } as Node,
99
+ { type: 'split_by_random' },
100
+ 'three-way-split'
101
+ );
102
+
103
+ helper.testNode(
104
+ {
105
+ uuid: 'test-random-node-3',
106
+ actions: [],
107
+ router: {
108
+ type: 'random',
109
+ categories: [
110
+ {
111
+ uuid: 'random-cat-1',
112
+ name: 'Treatment',
113
+ exit_uuid: 'random-exit-1'
114
+ },
115
+ {
116
+ uuid: 'random-cat-2',
117
+ name: 'Control',
118
+ exit_uuid: 'random-exit-2'
119
+ },
120
+ {
121
+ uuid: 'random-cat-3',
122
+ name: 'Variant A',
123
+ exit_uuid: 'random-exit-3'
124
+ },
125
+ {
126
+ uuid: 'random-cat-4',
127
+ name: 'Variant B',
128
+ exit_uuid: 'random-exit-4'
129
+ },
130
+ {
131
+ uuid: 'random-cat-5',
132
+ name: 'Holdout',
133
+ exit_uuid: 'random-exit-5'
134
+ }
135
+ ]
136
+ },
137
+ exits: [
138
+ { uuid: 'random-exit-1', destination_uuid: null },
139
+ { uuid: 'random-exit-2', destination_uuid: null },
140
+ { uuid: 'random-exit-3', destination_uuid: null },
141
+ { uuid: 'random-exit-4', destination_uuid: null },
142
+ { uuid: 'random-exit-5', destination_uuid: null }
143
+ ]
144
+ } as Node,
145
+ { type: 'split_by_random' },
146
+ 'ab-test-multiple-variants'
147
+ );
148
+
149
+ helper.testNode(
150
+ {
151
+ uuid: 'test-random-node-4',
152
+ actions: [],
153
+ router: {
154
+ type: 'random',
155
+ categories: [
156
+ {
157
+ uuid: 'random-cat-1',
158
+ name: 'Sample Group',
159
+ exit_uuid: 'random-exit-1'
160
+ },
161
+ {
162
+ uuid: 'random-cat-2',
163
+ name: 'Remaining Population',
164
+ exit_uuid: 'random-exit-2'
165
+ }
166
+ ]
167
+ },
168
+ exits: [
169
+ { uuid: 'random-exit-1', destination_uuid: null },
170
+ { uuid: 'random-exit-2', destination_uuid: null }
171
+ ]
172
+ } as Node,
173
+ { type: 'split_by_random' },
174
+ 'sampling-split'
175
+ );
176
+ });
177
+ });
@@ -0,0 +1,176 @@
1
+ import { expect } from '@open-wc/testing';
2
+ import { wait_for_digits } from '../../src/flow/nodes/wait_for_digits';
3
+ import { Node } from '../../src/store/flow-definition';
4
+ import { NodeTest } from '../NodeHelper';
5
+
6
+ /**
7
+ * Test suite for the wait_for_digits node configuration.
8
+ */
9
+ describe('wait_for_digits node config', () => {
10
+ const helper = new NodeTest(wait_for_digits, 'wait_for_digits');
11
+
12
+ describe('basic properties', () => {
13
+ helper.testBasicProperties();
14
+
15
+ it('has correct name', () => {
16
+ expect(wait_for_digits.name).to.equal('Wait for Digits');
17
+ });
18
+
19
+ it('has correct type', () => {
20
+ expect(wait_for_digits.type).to.equal('wait_for_digits');
21
+ });
22
+
23
+ it('has correct color', () => {
24
+ expect(wait_for_digits.color).to.exist;
25
+ });
26
+
27
+ it('is a simple node config without form or layout', () => {
28
+ expect(wait_for_digits.form).to.be.undefined;
29
+ expect(wait_for_digits.layout).to.be.undefined;
30
+ expect(wait_for_digits.toFormData).to.be.undefined;
31
+ expect(wait_for_digits.fromFormData).to.be.undefined;
32
+ });
33
+ });
34
+
35
+ describe('node scenarios', () => {
36
+ helper.testNode(
37
+ {
38
+ uuid: 'test-digits-node-1',
39
+ actions: [],
40
+ router: {
41
+ type: 'switch',
42
+ wait: {
43
+ type: 'msg',
44
+ hint: {
45
+ type: 'digits',
46
+ count: 4
47
+ }
48
+ },
49
+ result_name: 'digits',
50
+ categories: [
51
+ {
52
+ uuid: 'digits-cat-1',
53
+ name: 'Has Number',
54
+ exit_uuid: 'digits-exit-1'
55
+ },
56
+ { uuid: 'digits-cat-2', name: 'Other', exit_uuid: 'digits-exit-2' }
57
+ ]
58
+ },
59
+ exits: [
60
+ { uuid: 'digits-exit-1', destination_uuid: null },
61
+ { uuid: 'digits-exit-2', destination_uuid: null }
62
+ ]
63
+ } as Node,
64
+ { type: 'wait_for_digits' },
65
+ 'basic-digits-wait'
66
+ );
67
+
68
+ helper.testNode(
69
+ {
70
+ uuid: 'test-digits-node-2',
71
+ actions: [],
72
+ router: {
73
+ type: 'switch',
74
+ wait: {
75
+ type: 'msg',
76
+ hint: {
77
+ type: 'digits',
78
+ count: 1
79
+ },
80
+ timeout: {
81
+ category_uuid: 'timeout-cat',
82
+ seconds: 30
83
+ }
84
+ },
85
+ result_name: 'pin_digit',
86
+ categories: [
87
+ {
88
+ uuid: 'digits-cat-1',
89
+ name: 'Has Number',
90
+ exit_uuid: 'digits-exit-1'
91
+ },
92
+ {
93
+ uuid: 'timeout-cat',
94
+ name: 'No Response',
95
+ exit_uuid: 'timeout-exit'
96
+ },
97
+ { uuid: 'digits-cat-2', name: 'Other', exit_uuid: 'digits-exit-2' }
98
+ ]
99
+ },
100
+ exits: [
101
+ { uuid: 'digits-exit-1', destination_uuid: null },
102
+ { uuid: 'timeout-exit', destination_uuid: null },
103
+ { uuid: 'digits-exit-2', destination_uuid: null }
104
+ ]
105
+ } as Node,
106
+ { type: 'wait_for_digits' },
107
+ 'single-digit-with-timeout'
108
+ );
109
+
110
+ helper.testNode(
111
+ {
112
+ uuid: 'test-digits-node-3',
113
+ actions: [],
114
+ router: {
115
+ type: 'switch',
116
+ wait: {
117
+ type: 'msg',
118
+ hint: {
119
+ type: 'digits',
120
+ count: 10
121
+ }
122
+ },
123
+ result_name: 'phone_number',
124
+ categories: [
125
+ {
126
+ uuid: 'phone-cat-1',
127
+ name: 'Valid Phone',
128
+ exit_uuid: 'phone-exit-1'
129
+ },
130
+ { uuid: 'phone-cat-2', name: 'Invalid', exit_uuid: 'phone-exit-2' },
131
+ { uuid: 'phone-cat-3', name: 'Other', exit_uuid: 'phone-exit-3' }
132
+ ]
133
+ },
134
+ exits: [
135
+ { uuid: 'phone-exit-1', destination_uuid: null },
136
+ { uuid: 'phone-exit-2', destination_uuid: null },
137
+ { uuid: 'phone-exit-3', destination_uuid: null }
138
+ ]
139
+ } as Node,
140
+ { type: 'wait_for_digits' },
141
+ 'phone-number-collection'
142
+ );
143
+
144
+ helper.testNode(
145
+ {
146
+ uuid: 'test-digits-node-4',
147
+ actions: [],
148
+ router: {
149
+ type: 'switch',
150
+ wait: {
151
+ type: 'msg',
152
+ hint: {
153
+ type: 'digits',
154
+ count: 6
155
+ }
156
+ },
157
+ result_name: 'verification_code',
158
+ categories: [
159
+ {
160
+ uuid: 'code-cat-1',
161
+ name: 'Valid Code',
162
+ exit_uuid: 'code-exit-1'
163
+ },
164
+ { uuid: 'code-cat-2', name: 'Other', exit_uuid: 'code-exit-2' }
165
+ ]
166
+ },
167
+ exits: [
168
+ { uuid: 'code-exit-1', destination_uuid: null },
169
+ { uuid: 'code-exit-2', destination_uuid: null }
170
+ ]
171
+ } as Node,
172
+ { type: 'wait_for_digits' },
173
+ 'verification-code'
174
+ );
175
+ });
176
+ });
@@ -0,0 +1,206 @@
1
+ import { expect } from '@open-wc/testing';
2
+ import { wait_for_response } from '../../src/flow/nodes/wait_for_response';
3
+ import { Node } from '../../src/store/flow-definition';
4
+ import { NodeTest } from '../NodeHelper';
5
+
6
+ /**
7
+ * Test suite for the wait_for_response node configuration.
8
+ */
9
+ describe('wait_for_response node config', () => {
10
+ const helper = new NodeTest(wait_for_response, 'wait_for_response');
11
+
12
+ describe('basic properties', () => {
13
+ helper.testBasicProperties();
14
+
15
+ it('has correct name', () => {
16
+ expect(wait_for_response.name).to.equal('Wait for Response');
17
+ });
18
+
19
+ it('has correct type', () => {
20
+ expect(wait_for_response.type).to.equal('wait_for_response');
21
+ });
22
+
23
+ it('has form configuration', () => {
24
+ expect(wait_for_response.form).to.exist;
25
+ expect(wait_for_response.form.result_name).to.exist;
26
+ });
27
+
28
+ it('has layout configuration', () => {
29
+ expect(wait_for_response.layout).to.exist;
30
+ expect(wait_for_response.layout).to.deep.equal([
31
+ 'timeout',
32
+ 'result_name'
33
+ ]);
34
+ });
35
+ });
36
+
37
+ describe('node scenarios', () => {
38
+ helper.testNode(
39
+ {
40
+ uuid: 'test-wait-node-1',
41
+ actions: [],
42
+ router: {
43
+ type: 'switch',
44
+ wait: {
45
+ type: 'msg',
46
+ timeout: {
47
+ category_uuid: 'timeout-cat-1',
48
+ seconds: 300
49
+ }
50
+ },
51
+ result_name: 'response',
52
+ categories: [
53
+ {
54
+ uuid: 'timeout-cat-1',
55
+ name: 'No Response',
56
+ exit_uuid: 'timeout-exit-1'
57
+ }
58
+ ]
59
+ },
60
+ exits: [{ uuid: 'timeout-exit-1', destination_uuid: null }]
61
+ } as Node,
62
+ { type: 'wait_for_response' },
63
+ 'basic-wait'
64
+ );
65
+
66
+ helper.testNode(
67
+ {
68
+ uuid: 'test-wait-node-2',
69
+ actions: [],
70
+ router: {
71
+ type: 'switch',
72
+ wait: {
73
+ type: 'msg',
74
+ timeout: {
75
+ category_uuid: 'timeout-cat-2',
76
+ seconds: 1800
77
+ }
78
+ },
79
+ result_name: 'user_input',
80
+ categories: [
81
+ {
82
+ uuid: 'timeout-cat-2',
83
+ name: 'No Response',
84
+ exit_uuid: 'timeout-exit-2'
85
+ }
86
+ ]
87
+ },
88
+ exits: [{ uuid: 'timeout-exit-2', destination_uuid: null }]
89
+ } as Node,
90
+ { type: 'wait_for_response' },
91
+ 'custom-result-name'
92
+ );
93
+
94
+ helper.testNode(
95
+ {
96
+ uuid: 'test-wait-node-3',
97
+ actions: [],
98
+ router: {
99
+ type: 'switch',
100
+ wait: {
101
+ type: 'msg',
102
+ timeout: {
103
+ category_uuid: 'timeout-cat-3',
104
+ seconds: 60
105
+ }
106
+ },
107
+ result_name: 'quick_response',
108
+ categories: [
109
+ {
110
+ uuid: 'timeout-cat-3',
111
+ name: 'No Response',
112
+ exit_uuid: 'timeout-exit-3'
113
+ }
114
+ ]
115
+ },
116
+ exits: [{ uuid: 'timeout-exit-3', destination_uuid: null }]
117
+ } as Node,
118
+ { type: 'wait_for_response' },
119
+ 'short-timeout'
120
+ );
121
+
122
+ helper.testNode(
123
+ {
124
+ uuid: 'test-wait-node-4',
125
+ actions: [],
126
+ router: {
127
+ type: 'switch',
128
+ wait: {
129
+ type: 'msg'
130
+ // No timeout specified
131
+ },
132
+ result_name: 'response',
133
+ categories: []
134
+ },
135
+ exits: []
136
+ } as Node,
137
+ { type: 'wait_for_response' },
138
+ 'no-timeout'
139
+ );
140
+ });
141
+
142
+ describe('data transformation', () => {
143
+ it('converts node to form data correctly', () => {
144
+ const node: Node = {
145
+ uuid: 'test-node',
146
+ actions: [],
147
+ router: {
148
+ type: 'switch',
149
+ result_name: 'user_response',
150
+ categories: []
151
+ },
152
+ exits: []
153
+ };
154
+
155
+ const formData = wait_for_response.toFormData!(node);
156
+
157
+ expect(formData.uuid).to.equal('test-node');
158
+ expect(formData.result_name).to.equal('user_response');
159
+ });
160
+
161
+ it('converts form data to node correctly', () => {
162
+ const formData = {
163
+ uuid: 'test-node',
164
+ result_name: 'custom_response'
165
+ };
166
+
167
+ const originalNode: Node = {
168
+ uuid: 'test-node',
169
+ actions: [],
170
+ exits: [],
171
+ router: {
172
+ type: 'switch',
173
+ result_name: 'response',
174
+ categories: []
175
+ }
176
+ };
177
+
178
+ const result = wait_for_response.fromFormData!(formData, originalNode);
179
+
180
+ expect(result.uuid).to.equal('test-node');
181
+ expect(result.router?.result_name).to.equal('custom_response');
182
+ });
183
+
184
+ it('handles default result name', () => {
185
+ const formData = {
186
+ uuid: 'test-node'
187
+ // No result_name specified
188
+ };
189
+
190
+ const originalNode: Node = {
191
+ uuid: 'test-node',
192
+ actions: [],
193
+ exits: [],
194
+ router: {
195
+ type: 'switch',
196
+ categories: []
197
+ }
198
+ };
199
+
200
+ const result = wait_for_response.fromFormData!(formData, originalNode);
201
+
202
+ expect(result.uuid).to.equal('test-node');
203
+ expect(result.router?.result_name).to.equal('response');
204
+ });
205
+ });
206
+ });
@@ -0,0 +1,87 @@
1
+ import { fixture, expect } from '@open-wc/testing';
2
+ import { html } from 'lit';
3
+ import { NodeEditor } from '../src/flow/NodeEditor';
4
+ import { AddInputLabels } from '../src/store/flow-definition';
5
+
6
+ // Register the component
7
+ customElements.define('temba-node-editor', NodeEditor);
8
+
9
+ describe('add_input_labels action editor', () => {
10
+ it('renders form editor for add_input_labels action', async () => {
11
+ const action: AddInputLabels = {
12
+ uuid: 'test-action-uuid',
13
+ type: 'add_input_labels',
14
+ labels: [
15
+ { uuid: 'label-1', name: 'Important' },
16
+ { uuid: 'label-2', name: 'Spam' }
17
+ ]
18
+ };
19
+
20
+ const el = (await fixture(html`
21
+ <temba-node-editor .action=${action} .isOpen=${true}></temba-node-editor>
22
+ `)) as NodeEditor;
23
+
24
+ await el.updateComplete;
25
+ expect(el.shadowRoot).to.not.be.null;
26
+ expect(el.action).to.equal(action);
27
+ });
28
+
29
+ it('can create new labels through the multi-select', async () => {
30
+ const action: AddInputLabels = {
31
+ uuid: 'test-action-uuid',
32
+ type: 'add_input_labels',
33
+ labels: []
34
+ };
35
+
36
+ const el = (await fixture(html`
37
+ <temba-node-editor .action=${action} .isOpen=${true}></temba-node-editor>
38
+ `)) as NodeEditor;
39
+
40
+ await el.updateComplete;
41
+
42
+ // Find the select element for labels
43
+ const selectElement = el.shadowRoot?.querySelector(
44
+ 'temba-select[name="labels"]'
45
+ );
46
+ expect(selectElement).to.not.be.null;
47
+
48
+ // Verify it has the correct configuration (no longer checking for tags)
49
+ expect(selectElement?.getAttribute('multi')).to.not.be.null;
50
+ expect(selectElement?.getAttribute('searchable')).to.not.be.null;
51
+ expect(selectElement?.getAttribute('endpoint')).to.equal(
52
+ '/api/v2/labels.json'
53
+ );
54
+ });
55
+
56
+ it('transforms form data correctly', async () => {
57
+ const action: AddInputLabels = {
58
+ uuid: 'test-action-uuid',
59
+ type: 'add_input_labels',
60
+ labels: [
61
+ { uuid: 'label-1', name: 'Important' },
62
+ { uuid: 'label-2', name: 'Follow Up' }
63
+ ]
64
+ };
65
+
66
+ const el = (await fixture(html`
67
+ <temba-node-editor .action=${action} .isOpen=${true}></temba-node-editor>
68
+ `)) as NodeEditor;
69
+
70
+ await el.updateComplete;
71
+
72
+ // Test toFormData transformation
73
+ const expectedFormData = {
74
+ labels: [
75
+ { uuid: 'label-1', name: 'Important' },
76
+ { uuid: 'label-2', name: 'Follow Up' }
77
+ ],
78
+ uuid: 'test-action-uuid'
79
+ };
80
+
81
+ // Access the private formData property
82
+ const formData = (el as any).formData;
83
+ expect(formData).to.not.be.undefined;
84
+ expect(formData.labels).to.deep.equal(expectedFormData.labels);
85
+ expect(formData.uuid).to.equal(expectedFormData.uuid);
86
+ });
87
+ });