@nyaruka/temba-components 0.129.7 → 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 (269) hide show
  1. package/.devcontainer/Dockerfile +11 -4
  2. package/.devcontainer/devcontainer.json +3 -2
  3. package/.github/workflows/build.yml +4 -14
  4. package/CHANGELOG.md +29 -0
  5. package/demo/components/flow/example.html +1 -1
  6. package/demo/components/message-editor/example.html +125 -0
  7. package/demo/components/textinput/completion.html +1 -0
  8. package/demo/data/flows/food-order.json +12 -21
  9. package/demo/data/flows/sample-flow.json +210 -104
  10. package/dist/temba-components.js +715 -364
  11. package/dist/temba-components.js.map +1 -1
  12. package/out-tsc/src/display/Thumbnail.js +2 -1
  13. package/out-tsc/src/display/Thumbnail.js.map +1 -1
  14. package/out-tsc/src/events.js.map +1 -1
  15. package/out-tsc/src/excellent/helpers.js +2 -2
  16. package/out-tsc/src/excellent/helpers.js.map +1 -1
  17. package/out-tsc/src/flow/CanvasNode.js +25 -7
  18. package/out-tsc/src/flow/CanvasNode.js.map +1 -1
  19. package/out-tsc/src/flow/Editor.js +11 -1
  20. package/out-tsc/src/flow/Editor.js.map +1 -1
  21. package/out-tsc/src/flow/NodeEditor.js +342 -276
  22. package/out-tsc/src/flow/NodeEditor.js.map +1 -1
  23. package/out-tsc/src/flow/actions/add_input_labels.js +40 -0
  24. package/out-tsc/src/flow/actions/add_input_labels.js.map +1 -1
  25. package/out-tsc/src/flow/actions/call_llm.js +56 -3
  26. package/out-tsc/src/flow/actions/call_llm.js.map +1 -1
  27. package/out-tsc/src/flow/actions/call_webhook.js +26 -17
  28. package/out-tsc/src/flow/actions/call_webhook.js.map +1 -1
  29. package/out-tsc/src/flow/actions/open_ticket.js +65 -3
  30. package/out-tsc/src/flow/actions/open_ticket.js.map +1 -1
  31. package/out-tsc/src/flow/actions/send_msg.js +147 -6
  32. package/out-tsc/src/flow/actions/send_msg.js.map +1 -1
  33. package/out-tsc/src/flow/actions/set_run_result.js +75 -0
  34. package/out-tsc/src/flow/actions/set_run_result.js.map +1 -1
  35. package/out-tsc/src/flow/config.js +4 -0
  36. package/out-tsc/src/flow/config.js.map +1 -1
  37. package/out-tsc/src/flow/nodes/split_by_llm_categorize.js +227 -0
  38. package/out-tsc/src/flow/nodes/split_by_llm_categorize.js.map +1 -0
  39. package/out-tsc/src/flow/nodes/split_by_ticket.js +18 -0
  40. package/out-tsc/src/flow/nodes/split_by_ticket.js.map +1 -0
  41. package/out-tsc/src/flow/nodes/wait_for_response.js +27 -1
  42. package/out-tsc/src/flow/nodes/wait_for_response.js.map +1 -1
  43. package/out-tsc/src/flow/types.js +0 -65
  44. package/out-tsc/src/flow/types.js.map +1 -1
  45. package/out-tsc/src/form/ArrayEditor.js +87 -57
  46. package/out-tsc/src/form/ArrayEditor.js.map +1 -1
  47. package/out-tsc/src/form/BaseListEditor.js +19 -4
  48. package/out-tsc/src/form/BaseListEditor.js.map +1 -1
  49. package/out-tsc/src/form/FieldRenderer.js +305 -0
  50. package/out-tsc/src/form/FieldRenderer.js.map +1 -0
  51. package/out-tsc/src/form/FormField.js +4 -4
  52. package/out-tsc/src/form/FormField.js.map +1 -1
  53. package/out-tsc/src/form/KeyValueEditor.js +1 -1
  54. package/out-tsc/src/form/KeyValueEditor.js.map +1 -1
  55. package/out-tsc/src/form/MediaPicker.js +13 -1
  56. package/out-tsc/src/form/MediaPicker.js.map +1 -1
  57. package/out-tsc/src/form/MessageEditor.js +422 -0
  58. package/out-tsc/src/form/MessageEditor.js.map +1 -0
  59. package/out-tsc/src/form/TextInput.js +13 -6
  60. package/out-tsc/src/form/TextInput.js.map +1 -1
  61. package/out-tsc/src/form/select/Select.js +52 -24
  62. package/out-tsc/src/form/select/Select.js.map +1 -1
  63. package/out-tsc/src/live/ContactChat.js +66 -15
  64. package/out-tsc/src/live/ContactChat.js.map +1 -1
  65. package/out-tsc/src/markdown.js +13 -11
  66. package/out-tsc/src/markdown.js.map +1 -1
  67. package/out-tsc/temba-modules.js +2 -0
  68. package/out-tsc/temba-modules.js.map +1 -1
  69. package/out-tsc/test/ActionHelper.js +2 -0
  70. package/out-tsc/test/ActionHelper.js.map +1 -1
  71. package/out-tsc/test/NodeHelper.js +148 -0
  72. package/out-tsc/test/NodeHelper.js.map +1 -0
  73. package/out-tsc/test/actions/call_llm.test.js +103 -0
  74. package/out-tsc/test/actions/call_llm.test.js.map +1 -0
  75. package/out-tsc/test/nodes/split_by_llm_categorize.test.js +532 -0
  76. package/out-tsc/test/nodes/split_by_llm_categorize.test.js.map +1 -0
  77. package/out-tsc/test/nodes/split_by_random.test.js +150 -0
  78. package/out-tsc/test/nodes/split_by_random.test.js.map +1 -0
  79. package/out-tsc/test/nodes/wait_for_digits.test.js +150 -0
  80. package/out-tsc/test/nodes/wait_for_digits.test.js.map +1 -0
  81. package/out-tsc/test/nodes/wait_for_response.test.js +171 -0
  82. package/out-tsc/test/nodes/wait_for_response.test.js.map +1 -0
  83. package/out-tsc/test/temba-add-input-labels.test.js +70 -0
  84. package/out-tsc/test/temba-add-input-labels.test.js.map +1 -0
  85. package/out-tsc/test/temba-field-config.test.js +4 -2
  86. package/out-tsc/test/temba-field-config.test.js.map +1 -1
  87. package/out-tsc/test/temba-field-renderer.test.js +296 -0
  88. package/out-tsc/test/temba-field-renderer.test.js.map +1 -0
  89. package/out-tsc/test/temba-markdown.test.js +1 -1
  90. package/out-tsc/test/temba-markdown.test.js.map +1 -1
  91. package/out-tsc/test/temba-message-editor.test.js +194 -0
  92. package/out-tsc/test/temba-message-editor.test.js.map +1 -0
  93. package/out-tsc/test/temba-node-editor.test.js +471 -0
  94. package/out-tsc/test/temba-node-editor.test.js.map +1 -1
  95. package/out-tsc/test/temba-select.test.js +7 -4
  96. package/out-tsc/test/temba-select.test.js.map +1 -1
  97. package/out-tsc/test/temba-textinput.test.js +16 -0
  98. package/out-tsc/test/temba-textinput.test.js.map +1 -1
  99. package/out-tsc/test/temba-webchat.test.js +5 -1
  100. package/out-tsc/test/temba-webchat.test.js.map +1 -1
  101. package/out-tsc/test/utils.test.js +2 -8
  102. package/out-tsc/test/utils.test.js.map +1 -1
  103. package/package.json +7 -4
  104. package/screenshots/truth/actions/add_contact_groups/editor/descriptive-group-names.png +0 -0
  105. package/screenshots/truth/actions/add_contact_groups/editor/long-group-names.png +0 -0
  106. package/screenshots/truth/actions/add_contact_groups/editor/many-groups.png +0 -0
  107. package/screenshots/truth/actions/add_contact_groups/editor/multiple-groups.png +0 -0
  108. package/screenshots/truth/actions/add_contact_groups/editor/single-group.png +0 -0
  109. package/screenshots/truth/actions/call_llm/editor/information-extraction.png +0 -0
  110. package/screenshots/truth/actions/call_llm/editor/sentiment-analysis.png +0 -0
  111. package/screenshots/truth/actions/call_llm/editor/summarization.png +0 -0
  112. package/screenshots/truth/actions/call_llm/editor/translation-task.png +0 -0
  113. package/screenshots/truth/actions/call_llm/render/information-extraction.png +0 -0
  114. package/screenshots/truth/actions/call_llm/render/sentiment-analysis.png +0 -0
  115. package/screenshots/truth/actions/call_llm/render/summarization.png +0 -0
  116. package/screenshots/truth/actions/call_llm/render/translation-task.png +0 -0
  117. package/screenshots/truth/actions/remove_contact_groups/editor/cleanup-groups.png +0 -0
  118. package/screenshots/truth/actions/remove_contact_groups/editor/long-descriptive-group-names.png +0 -0
  119. package/screenshots/truth/actions/remove_contact_groups/editor/many-groups.png +0 -0
  120. package/screenshots/truth/actions/remove_contact_groups/editor/multiple-groups.png +0 -0
  121. package/screenshots/truth/actions/remove_contact_groups/editor/remove-from-all-groups.png +0 -0
  122. package/screenshots/truth/actions/remove_contact_groups/editor/single-group.png +0 -0
  123. package/screenshots/truth/actions/send_email/editor/complex-business-email.png +0 -0
  124. package/screenshots/truth/actions/send_email/editor/empty-body.png +0 -0
  125. package/screenshots/truth/actions/send_email/editor/empty-subject.png +0 -0
  126. package/screenshots/truth/actions/send_email/editor/long-subject.png +0 -0
  127. package/screenshots/truth/actions/send_email/editor/multiline-body.png +0 -0
  128. package/screenshots/truth/actions/send_email/editor/multiple-recipients.png +0 -0
  129. package/screenshots/truth/actions/send_email/editor/simple-email.png +0 -0
  130. package/screenshots/truth/actions/send_email/editor/with-expressions.png +0 -0
  131. package/screenshots/truth/actions/send_msg/editor/long-quick-replies.png +0 -0
  132. package/screenshots/truth/actions/send_msg/editor/multiline-text-with-replies.png +0 -0
  133. package/screenshots/truth/actions/send_msg/editor/simple-text.png +0 -0
  134. package/screenshots/truth/actions/send_msg/editor/text-with-linebreaks.png +0 -0
  135. package/screenshots/truth/actions/send_msg/editor/text-with-many-quick-replies.png +0 -0
  136. package/screenshots/truth/actions/send_msg/editor/text-with-quick-replies.png +0 -0
  137. package/screenshots/truth/actions/send_msg/editor/text-without-quick-replies.png +0 -0
  138. package/screenshots/truth/editor/router.png +0 -0
  139. package/screenshots/truth/editor/send_msg.png +0 -0
  140. package/screenshots/truth/editor/set_contact_language.png +0 -0
  141. package/screenshots/truth/editor/set_contact_name.png +0 -0
  142. package/screenshots/truth/editor/set_run_result.png +0 -0
  143. package/screenshots/truth/editor/wait.png +0 -0
  144. package/screenshots/truth/field-renderer/checkbox-checked.png +0 -0
  145. package/screenshots/truth/field-renderer/checkbox-unchecked.png +0 -0
  146. package/screenshots/truth/field-renderer/checkbox-with-errors.png +0 -0
  147. package/screenshots/truth/field-renderer/context-comparison.png +0 -0
  148. package/screenshots/truth/field-renderer/key-value-with-label.png +0 -0
  149. package/screenshots/truth/field-renderer/message-editor-with-label.png +0 -0
  150. package/screenshots/truth/field-renderer/select-multi.png +0 -0
  151. package/screenshots/truth/field-renderer/select-no-label.png +0 -0
  152. package/screenshots/truth/field-renderer/select-with-label.png +0 -0
  153. package/screenshots/truth/field-renderer/text-evaluated.png +0 -0
  154. package/screenshots/truth/field-renderer/text-no-label.png +0 -0
  155. package/screenshots/truth/field-renderer/text-with-errors.png +0 -0
  156. package/screenshots/truth/field-renderer/text-with-label.png +0 -0
  157. package/screenshots/truth/field-renderer/textarea-evaluated.png +0 -0
  158. package/screenshots/truth/field-renderer/textarea-with-label.png +0 -0
  159. package/screenshots/truth/formfield/markdown-errors.png +0 -0
  160. package/screenshots/truth/formfield/no-errors.png +0 -0
  161. package/screenshots/truth/formfield/plain-text-errors.png +0 -0
  162. package/screenshots/truth/message-editor/autogrow-initial-content.png +0 -0
  163. package/screenshots/truth/message-editor/default.png +0 -0
  164. package/screenshots/truth/message-editor/drag-highlight.png +0 -0
  165. package/screenshots/truth/message-editor/filtered-attachments.png +0 -0
  166. package/screenshots/truth/message-editor/with-completion.png +0 -0
  167. package/screenshots/truth/message-editor/with-properties.png +0 -0
  168. package/screenshots/truth/nodes/split_by_llm_categorize/editor/basic-categorization.png +0 -0
  169. package/screenshots/truth/nodes/split_by_llm_categorize/editor/custom-input-and-result-name.png +0 -0
  170. package/screenshots/truth/nodes/split_by_llm_categorize/editor/feedback-categorization.png +0 -0
  171. package/screenshots/truth/nodes/split_by_llm_categorize/editor/many-categories.png +0 -0
  172. package/screenshots/truth/nodes/split_by_llm_categorize/editor/minimal-categories.png +0 -0
  173. package/screenshots/truth/nodes/split_by_llm_categorize/render/basic-categorization.png +0 -0
  174. package/screenshots/truth/nodes/split_by_llm_categorize/render/custom-input-and-result-name.png +0 -0
  175. package/screenshots/truth/nodes/split_by_llm_categorize/render/feedback-categorization.png +0 -0
  176. package/screenshots/truth/nodes/split_by_llm_categorize/render/many-categories.png +0 -0
  177. package/screenshots/truth/nodes/split_by_llm_categorize/render/minimal-categories.png +0 -0
  178. package/screenshots/truth/nodes/split_by_random/editor/ab-test-multiple-variants.png +0 -0
  179. package/screenshots/truth/nodes/split_by_random/editor/sampling-split.png +0 -0
  180. package/screenshots/truth/nodes/split_by_random/editor/three-way-split.png +0 -0
  181. package/screenshots/truth/nodes/split_by_random/editor/two-bucket-split.png +0 -0
  182. package/screenshots/truth/nodes/split_by_random/render/ab-test-multiple-variants.png +0 -0
  183. package/screenshots/truth/nodes/split_by_random/render/sampling-split.png +0 -0
  184. package/screenshots/truth/nodes/split_by_random/render/three-way-split.png +0 -0
  185. package/screenshots/truth/nodes/split_by_random/render/two-bucket-split.png +0 -0
  186. package/screenshots/truth/nodes/wait_for_digits/editor/basic-digits-wait.png +0 -0
  187. package/screenshots/truth/nodes/wait_for_digits/editor/phone-number-collection.png +0 -0
  188. package/screenshots/truth/nodes/wait_for_digits/editor/single-digit-with-timeout.png +0 -0
  189. package/screenshots/truth/nodes/wait_for_digits/editor/verification-code.png +0 -0
  190. package/screenshots/truth/nodes/wait_for_digits/render/basic-digits-wait.png +0 -0
  191. package/screenshots/truth/nodes/wait_for_digits/render/phone-number-collection.png +0 -0
  192. package/screenshots/truth/nodes/wait_for_digits/render/single-digit-with-timeout.png +0 -0
  193. package/screenshots/truth/nodes/wait_for_digits/render/verification-code.png +0 -0
  194. package/screenshots/truth/nodes/wait_for_response/editor/basic-wait.png +0 -0
  195. package/screenshots/truth/nodes/wait_for_response/editor/custom-result-name.png +0 -0
  196. package/screenshots/truth/nodes/wait_for_response/editor/no-timeout.png +0 -0
  197. package/screenshots/truth/nodes/wait_for_response/editor/short-timeout.png +0 -0
  198. package/screenshots/truth/nodes/wait_for_response/render/basic-wait.png +0 -0
  199. package/screenshots/truth/nodes/wait_for_response/render/custom-result-name.png +0 -0
  200. package/screenshots/truth/nodes/wait_for_response/render/no-timeout.png +0 -0
  201. package/screenshots/truth/nodes/wait_for_response/render/short-timeout.png +0 -0
  202. package/screenshots/truth/omnibox/selected.png +0 -0
  203. package/screenshots/truth/select/functions.png +0 -0
  204. package/screenshots/truth/select/multi-with-endpoint.png +0 -0
  205. package/screenshots/truth/select/search-enabled.png +0 -0
  206. package/screenshots/truth/textinput/autogrow-initial.png +0 -0
  207. package/screenshots/truth/textinput/input-form.png +0 -0
  208. package/src/display/Thumbnail.ts +2 -1
  209. package/src/events.ts +13 -1
  210. package/src/excellent/helpers.ts +2 -2
  211. package/src/flow/CanvasNode.ts +22 -1
  212. package/src/flow/Editor.ts +12 -1
  213. package/src/flow/NodeEditor.ts +412 -354
  214. package/src/flow/actions/add_input_labels.ts +45 -0
  215. package/src/flow/actions/call_llm.ts +57 -3
  216. package/src/flow/actions/call_webhook.ts +28 -18
  217. package/src/flow/actions/open_ticket.ts +74 -3
  218. package/src/flow/actions/send_msg.ts +170 -6
  219. package/src/flow/actions/set_run_result.ts +83 -0
  220. package/src/flow/config.ts +4 -0
  221. package/src/flow/nodes/split_by_llm_categorize.ts +277 -0
  222. package/src/flow/nodes/split_by_ticket.ts +19 -0
  223. package/src/flow/nodes/wait_for_response.ts +28 -1
  224. package/src/flow/types.ts +46 -128
  225. package/src/form/ArrayEditor.ts +96 -66
  226. package/src/form/BaseListEditor.ts +22 -6
  227. package/src/form/FieldRenderer.ts +465 -0
  228. package/src/form/FormField.ts +4 -4
  229. package/src/form/KeyValueEditor.ts +1 -1
  230. package/src/form/MediaPicker.ts +13 -1
  231. package/src/form/MessageEditor.ts +449 -0
  232. package/src/form/TextInput.ts +16 -8
  233. package/src/form/select/Select.ts +55 -24
  234. package/src/live/ContactChat.ts +69 -19
  235. package/src/markdown.ts +19 -11
  236. package/src/store/flow-definition.d.ts +5 -2
  237. package/static/api/labels.json +31 -0
  238. package/static/api/topics.json +24 -9
  239. package/static/api/users.json +35 -16
  240. package/static/css/temba-components.css +5 -3
  241. package/static/mr/docs/en-us/editor.json +2588 -0
  242. package/stress-test.js +143 -0
  243. package/temba-modules.ts +2 -0
  244. package/test/ActionHelper.ts +2 -0
  245. package/test/NodeHelper.ts +184 -0
  246. package/test/actions/call_llm.test.ts +137 -0
  247. package/test/nodes/README.md +78 -0
  248. package/test/nodes/split_by_llm_categorize.test.ts +698 -0
  249. package/test/nodes/split_by_random.test.ts +177 -0
  250. package/test/nodes/wait_for_digits.test.ts +176 -0
  251. package/test/nodes/wait_for_response.test.ts +206 -0
  252. package/test/temba-add-input-labels.test.ts +87 -0
  253. package/test/temba-field-config.test.ts +4 -2
  254. package/test/temba-field-renderer.test.ts +482 -0
  255. package/test/temba-markdown.test.ts +1 -1
  256. package/test/temba-message-editor.test.ts +300 -0
  257. package/test/temba-node-editor.test.ts +590 -0
  258. package/test/temba-select.test.ts +7 -7
  259. package/test/temba-textinput.test.ts +26 -0
  260. package/test/temba-webchat.test.ts +6 -1
  261. package/test/utils.test.ts +2 -13
  262. package/test-assets/contacts/history.json +19 -0
  263. package/test-assets/select/llms.json +18 -0
  264. package/test-assets/style.css +2 -0
  265. package/web-dev-mock.mjs +523 -0
  266. package/web-dev-server.config.mjs +74 -6
  267. package/web-test-runner.config.mjs +9 -4
  268. package/test/temba-flow-editor.test.ts.backup +0 -563
  269. package/test/temba-utils-index.test.ts.backup +0 -1737
@@ -1,563 +0,0 @@
1
- import { html, fixture, expect } from '@open-wc/testing';
2
- import { Editor } from '../src/flow/Editor';
3
- import { Plumber } from '../src/flow/Plumber';
4
- import { stub, restore } from 'sinon';
5
-
6
- // Register the component
7
- customElements.define('temba-flow-editor', Editor);
8
-
9
- describe('Editor', () => {
10
- let editor: Editor;
11
-
12
- beforeEach(() => {
13
- // Reset any stubs
14
- restore();
15
- });
16
-
17
- afterEach(() => {
18
- restore();
19
- });
20
-
21
- describe('basic functionality', () => {
22
- it('creates render root as element itself', () => {
23
- const editor = new Editor();
24
- expect(editor.createRenderRoot()).to.equal(editor);
25
- });
26
-
27
- it('has correct CSS styles defined', () => {
28
- const styles = Editor.styles;
29
- expect(styles).to.exist;
30
- expect(styles.cssText).to.contain('#editor');
31
- expect(styles.cssText).to.contain('#grid');
32
- expect(styles.cssText).to.contain('#canvas');
33
- expect(styles.cssText).to.contain('.plumb-source');
34
- expect(styles.cssText).to.contain('.plumb-target');
35
- expect(styles.cssText).to.contain('.plumb-connector');
36
- });
37
-
38
- it('creates with default properties', () => {
39
- editor = new Editor();
40
- expect(editor.flow).to.be.undefined;
41
- expect(editor.version).to.be.undefined;
42
- });
43
-
44
- it('accepts flow and version properties without getStore call', async () => {
45
- editor = document.createElement('temba-flow-editor') as Editor;
46
- editor.flow = 'test-flow-uuid';
47
- editor.version = '1.0';
48
-
49
- expect(editor.flow).to.equal('test-flow-uuid');
50
- expect(editor.version).to.equal('1.0');
51
- });
52
- });
53
-
54
- describe('lifecycle methods', () => {
55
- it('calls firstUpdated and initializes plumber', async () => {
56
- editor = await fixture(html`
57
- <temba-flow-editor>
58
- <div id="canvas"></div>
59
- </temba-flow-editor>
60
- `);
61
-
62
- // Verify that plumber is initialized
63
- expect((editor as any).plumber).to.be.instanceOf(Plumber);
64
- });
65
-
66
- it('verifies firstUpdated method exists and can be called', () => {
67
- editor = new Editor();
68
-
69
- // Mock canvas element
70
- const mockCanvas = document.createElement('div');
71
- mockCanvas.id = 'canvas';
72
-
73
- // Mock querySelector to return our mock canvas
74
- stub(editor, 'querySelector').returns(mockCanvas);
75
-
76
- // Verify firstUpdated method exists
77
- expect(typeof (editor as any).firstUpdated).to.equal('function');
78
-
79
- // Test that calling firstUpdated doesn't throw (without getStore)
80
- expect(() => {
81
- // Only test the plumber initialization part
82
- (editor as any).plumber = new Plumber(mockCanvas);
83
- }).to.not.throw();
84
- });
85
-
86
- it('handles updated with canvasSize changes', async () => {
87
- editor = await fixture(html`
88
- <temba-flow-editor>
89
- <div id="canvas"></div>
90
- </temba-flow-editor>
91
- `);
92
-
93
- // Simulate canvasSize change
94
- (editor as any).canvasSize = { width: 800, height: 600 };
95
- const changes = new Map();
96
- changes.set('canvasSize', true);
97
-
98
- (editor as any).updated(changes);
99
-
100
- // Verify the canvasSize was set correctly
101
- expect((editor as any).canvasSize).to.deep.equal({
102
- width: 800,
103
- height: 600
104
- });
105
- });
106
-
107
- it('handles updated without canvasSize changes', async () => {
108
- editor = await fixture(html`
109
- <temba-flow-editor>
110
- <div id="canvas"></div>
111
- </temba-flow-editor>
112
- `);
113
-
114
- const consoleStub = stub(console, 'log');
115
-
116
- const changes = new Map();
117
- changes.set('other', true);
118
-
119
- (editor as any).updated(changes);
120
-
121
- expect(consoleStub).to.not.have.been.called;
122
-
123
- consoleStub.restore();
124
- });
125
- });
126
-
127
- describe('render method', () => {
128
- it('renders loading when no definition', async () => {
129
- editor = await fixture(html`
130
- <temba-flow-editor>
131
- <div id="canvas"></div>
132
- </temba-flow-editor>
133
- `);
134
-
135
- // Set canvas size to avoid undefined errors
136
- (editor as any).canvasSize = { width: 800, height: 600 };
137
- await editor.updateComplete;
138
-
139
- const loadingElement = editor.querySelector('temba-loading');
140
- expect(loadingElement).to.exist;
141
- });
142
-
143
- it('renders nodes when definition exists', async () => {
144
- const mockDefinition = {
145
- nodes: [
146
- {
147
- uuid: 'node-1',
148
- actions: [],
149
- exits: []
150
- },
151
- {
152
- uuid: 'node-2',
153
- actions: [],
154
- exits: []
155
- }
156
- ],
157
- _ui: {
158
- nodes: {
159
- 'node-1': { position: { left: 100, top: 200 } },
160
- 'node-2': { position: { left: 300, top: 400 } }
161
- }
162
- }
163
- };
164
-
165
- editor = await fixture(html`
166
- <temba-flow-editor>
167
- <div id="canvas"></div>
168
- </temba-flow-editor>
169
- `);
170
-
171
- // Set properties
172
- (editor as any).definition = mockDefinition;
173
- (editor as any).canvasSize = { width: 800, height: 600 };
174
- await editor.updateComplete;
175
-
176
- const flowNodes = editor.querySelectorAll('temba-flow-node');
177
- expect(flowNodes).to.have.length(2);
178
- });
179
-
180
- it('includes style elements in light DOM', async () => {
181
- editor = await fixture(html`
182
- <temba-flow-editor>
183
- <div id="canvas"></div>
184
- </temba-flow-editor>
185
- `);
186
-
187
- // Set canvas size
188
- (editor as any).canvasSize = { width: 800, height: 600 };
189
- await editor.updateComplete;
190
-
191
- const styleElements = editor.querySelectorAll('style');
192
- expect(styleElements.length).to.be.greaterThan(0);
193
- });
194
-
195
- it('renders with correct grid dimensions', async () => {
196
- editor = await fixture(html`
197
- <temba-flow-editor>
198
- <div id="canvas"></div>
199
- </temba-flow-editor>
200
- `);
201
-
202
- // Set canvas size to specific dimensions
203
- (editor as any).canvasSize = { width: 1200, height: 900 };
204
- await editor.updateComplete;
205
-
206
- const gridElement = editor.querySelector('#grid');
207
- expect(gridElement).to.exist;
208
-
209
- // Check that grid has correct dimensions
210
- const gridStyle = gridElement.getAttribute('style');
211
- expect(gridStyle).to.contain('width:1200px');
212
- expect(gridStyle).to.contain('height:900px');
213
- });
214
- });
215
-
216
- describe('multi-selection functionality', () => {
217
- let mockDefinition: any;
218
-
219
- beforeEach(() => {
220
- mockDefinition = {
221
- nodes: [
222
- {
223
- uuid: 'node-1',
224
- actions: [],
225
- exits: []
226
- },
227
- {
228
- uuid: 'node-2',
229
- actions: [],
230
- exits: []
231
- }
232
- ],
233
- _ui: {
234
- nodes: {
235
- 'node-1': { position: { left: 100, top: 200 } },
236
- 'node-2': { position: { left: 300, top: 400 } }
237
- },
238
- stickies: {
239
- 'sticky-1': {
240
- position: { left: 200, top: 100 },
241
- title: 'Test Sticky',
242
- body: 'Test content',
243
- color: 'yellow'
244
- }
245
- }
246
- }
247
- };
248
- });
249
-
250
- it('initializes with empty selection', async () => {
251
- editor = await fixture(html`
252
- <temba-flow-editor>
253
- <div id="canvas"></div>
254
- </temba-flow-editor>
255
- `);
256
-
257
- expect((editor as any).selectedItems.size).to.equal(0);
258
- expect((editor as any).isSelecting).to.be.false;
259
- expect((editor as any).selectionBox).to.be.null;
260
- });
261
-
262
- it('adds visual selection styling to selected items', async () => {
263
- editor = await fixture(html`
264
- <temba-flow-editor>
265
- <div id="canvas"></div>
266
- </temba-flow-editor>
267
- `);
268
-
269
- // Set up mock definition and selection
270
- (editor as any).definition = mockDefinition;
271
- (editor as any).canvasSize = { width: 800, height: 600 };
272
- (editor as any).selectedItems = new Set(['node-1']);
273
- await editor.updateComplete;
274
-
275
- const selectedNode = editor.querySelector('temba-flow-node[uuid="node-1"]');
276
- expect(selectedNode).to.exist;
277
- expect(selectedNode.classList.contains('selected')).to.be.true;
278
- });
279
-
280
- it('renders selection box when selecting', async () => {
281
- editor = await fixture(html`
282
- <temba-flow-editor>
283
- <div id="canvas"></div>
284
- </temba-flow-editor>
285
- `);
286
-
287
- // Set up selection state
288
- (editor as any).definition = mockDefinition;
289
- (editor as any).canvasSize = { width: 800, height: 600 };
290
- (editor as any).isSelecting = true;
291
- (editor as any).selectionBox = {
292
- startX: 50,
293
- startY: 50,
294
- endX: 150,
295
- endY: 150
296
- };
297
- await editor.updateComplete;
298
-
299
- const selectionBox = editor.querySelector('.selection-box');
300
- expect(selectionBox).to.exist;
301
-
302
- const style = selectionBox.getAttribute('style');
303
- expect(style).to.contain('left: 50px');
304
- expect(style).to.contain('top: 50px');
305
- expect(style).to.contain('width: 100px');
306
- expect(style).to.contain('height: 100px');
307
- });
308
-
309
- it('does not render selection box when not selecting', async () => {
310
- editor = await fixture(html`
311
- <temba-flow-editor>
312
- <div id="canvas"></div>
313
- </temba-flow-editor>
314
- `);
315
-
316
- (editor as any).definition = mockDefinition;
317
- (editor as any).canvasSize = { width: 800, height: 600 };
318
- (editor as any).isSelecting = false;
319
- await editor.updateComplete;
320
-
321
- const selectionBox = editor.querySelector('.selection-box');
322
- expect(selectionBox).to.not.exist;
323
- });
324
-
325
- it('handles canvas mouse down for selection start', async () => {
326
- editor = await fixture(html`
327
- <temba-flow-editor>
328
- <div id="canvas"></div>
329
- </temba-flow-editor>
330
- `);
331
-
332
- (editor as any).definition = mockDefinition;
333
- (editor as any).canvasSize = { width: 800, height: 600 };
334
-
335
- // Pre-select an item
336
- (editor as any).selectedItems.add('node-1');
337
- await editor.updateComplete;
338
-
339
- const canvas = editor.querySelector('#canvas');
340
- const mockEvent = new MouseEvent('mousedown', {
341
- clientX: 100,
342
- clientY: 100,
343
- bubbles: true
344
- });
345
-
346
- // Mock getBoundingClientRect for canvas
347
- stub(canvas, 'getBoundingClientRect').returns({
348
- left: 0,
349
- top: 0,
350
- width: 800,
351
- height: 600
352
- } as DOMRect);
353
-
354
- // Set event target to canvas
355
- Object.defineProperty(mockEvent, 'target', {
356
- value: canvas,
357
- writable: false
358
- });
359
-
360
- (editor as any).handleCanvasMouseDown(mockEvent);
361
-
362
- // Should clear selection and start selection box
363
- expect((editor as any).selectedItems.size).to.equal(0);
364
- expect((editor as any).canvasMouseDown).to.be.true;
365
- expect((editor as any).selectionBox).to.not.be.null;
366
- });
367
-
368
- it('handles keyboard delete key with confirmation', async () => {
369
- editor = await fixture(html`
370
- <temba-flow-editor>
371
- <div id="canvas"></div>
372
- </temba-flow-editor>
373
- `);
374
-
375
- // Mock window.confirm
376
- const confirmStub = stub(window, 'confirm');
377
- confirmStub.returns(true);
378
-
379
- // Set up selection
380
- (editor as any).selectedItems.add('node-1');
381
-
382
- const mockEvent = new KeyboardEvent('keydown', { key: 'Delete' });
383
- (editor as any).handleKeyDown(mockEvent);
384
-
385
- expect(confirmStub).to.have.been.calledWith('Are you sure you want to delete 1 item?');
386
-
387
- confirmStub.restore();
388
- });
389
-
390
- it('handles escape key to clear selection', async () => {
391
- editor = await fixture(html`
392
- <temba-flow-editor>
393
- <div id="canvas"></div>
394
- </temba-flow-editor>
395
- `);
396
-
397
- // Set up selection
398
- (editor as any).selectedItems.add('node-1');
399
- (editor as any).selectedItems.add('node-2');
400
-
401
- const mockEvent = new KeyboardEvent('keydown', { key: 'Escape' });
402
- (editor as any).handleKeyDown(mockEvent);
403
-
404
- expect((editor as any).selectedItems.size).to.equal(0);
405
- });
406
-
407
- it('updates selection box coordinates during mouse move', async () => {
408
- editor = await fixture(html`
409
- <temba-flow-editor>
410
- <div id="canvas"></div>
411
- </temba-flow-editor>
412
- `);
413
-
414
- const canvas = editor.querySelector('#canvas');
415
-
416
- // Mock getBoundingClientRect
417
- stub(canvas, 'getBoundingClientRect').returns({
418
- left: 0,
419
- top: 0,
420
- width: 800,
421
- height: 600
422
- } as DOMRect);
423
-
424
- // Set up initial selection state
425
- (editor as any).canvasMouseDown = true;
426
- (editor as any).selectionBox = {
427
- startX: 50,
428
- startY: 50,
429
- endX: 50,
430
- endY: 50
431
- };
432
- (editor as any).definition = mockDefinition;
433
-
434
- const mockEvent = new MouseEvent('mousemove', {
435
- clientX: 150,
436
- clientY: 150
437
- });
438
-
439
- (editor as any).updateSelectionBox(mockEvent);
440
-
441
- expect((editor as any).selectionBox.endX).to.equal(150);
442
- expect((editor as any).selectionBox.endY).to.equal(150);
443
- });
444
-
445
- it('calculates intersections correctly for node selection', async () => {
446
- editor = await fixture(html`
447
- <temba-flow-editor>
448
- <div id="canvas"></div>
449
- </temba-flow-editor>
450
- `);
451
-
452
- (editor as any).definition = mockDefinition;
453
- (editor as any).canvasSize = { width: 800, height: 600 };
454
- await editor.updateComplete;
455
-
456
- // Mock node element and its bounding rect
457
- const nodeElement = editor.querySelector('temba-flow-node[uuid="node-1"]');
458
- stub(nodeElement, 'getBoundingClientRect').returns({
459
- width: 200,
460
- height: 100
461
- } as DOMRect);
462
-
463
- // Set selection box that intersects with node-1 (position: left: 100, top: 200)
464
- (editor as any).selectionBox = {
465
- startX: 50, // Selection box from 50,150 to 250,250
466
- startY: 150, // This should intersect node-1 at 100,200 with size 200x100
467
- endX: 250,
468
- endY: 250
469
- };
470
-
471
- (editor as any).updateSelectedItemsFromBox();
472
-
473
- expect((editor as any).selectedItems.has('node-1')).to.be.true;
474
- });
475
- });
476
-
477
- describe('canvas initialization', () => {
478
- <div id="canvas"></div>
479
- </temba-flow-editor>
480
- `);
481
-
482
- (editor as any).canvasSize = { width: 800, height: 600 };
483
- await editor.updateComplete;
484
-
485
- const editorElement = editor.querySelector('#editor');
486
- expect(editorElement).to.exist;
487
-
488
- const gridElement = editor.querySelector('#grid');
489
- expect(gridElement).to.exist;
490
-
491
- const canvasElement = editor.querySelector('#canvas');
492
- expect(canvasElement).to.exist;
493
- });
494
- });
495
-
496
- describe('property handling', () => {
497
- it('handles flow property change', async () => {
498
- editor = await fixture(html`
499
- <temba-flow-editor>
500
- <div id="canvas"></div>
501
- </temba-flow-editor>
502
- `);
503
-
504
- // Change flow property
505
- editor.flow = 'new-flow-uuid';
506
- await editor.updateComplete;
507
-
508
- expect(editor.flow).to.equal('new-flow-uuid');
509
- });
510
-
511
- it('handles version property change', async () => {
512
- editor = await fixture(html`
513
- <temba-flow-editor>
514
- <div id="canvas"></div>
515
- </temba-flow-editor>
516
- `);
517
-
518
- editor.version = '2.0';
519
- await editor.updateComplete;
520
-
521
- expect(editor.version).to.equal('2.0');
522
- });
523
- });
524
-
525
- describe('store integration', () => {
526
- it('has fromStore decorators for definition and canvasSize', () => {
527
- editor = new Editor();
528
-
529
- // Check that the properties exist (they are private but we can verify they exist)
530
- expect(editor).to.have.property('definition');
531
- expect(editor).to.have.property('canvasSize');
532
- });
533
- });
534
-
535
- describe('constructor behavior', () => {
536
- it('calls super in constructor', () => {
537
- // This mainly verifies the constructor doesn't throw
538
- expect(() => {
539
- new Editor();
540
- }).to.not.throw();
541
- });
542
- });
543
-
544
- describe('canvas initialization', () => {
545
- it('initializes plumber with canvas element', async () => {
546
- editor = await fixture(html`
547
- <temba-flow-editor>
548
- <div id="canvas"></div>
549
- </temba-flow-editor>
550
- `);
551
-
552
- const plumber = (editor as any).plumber;
553
- expect(plumber).to.be.instanceOf(Plumber);
554
- });
555
-
556
- it('handles missing canvas element gracefully', async () => {
557
- editor = await fixture(html`<temba-flow-editor></temba-flow-editor>`);
558
-
559
- // Should not throw even without canvas
560
- expect((editor as any).plumber).to.be.instanceOf(Plumber);
561
- });
562
- });
563
- });