@appsemble/utils 0.30.14-test.6 → 0.32.1-test.15

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 (171) hide show
  1. package/README.md +3 -3
  2. package/allActions.js +5 -3
  3. package/api/components/parameters/$orderby.js +2 -2
  4. package/api/components/parameters/index.d.ts +2 -1
  5. package/api/components/parameters/index.js +2 -1
  6. package/api/components/parameters/webhookName.d.ts +2 -0
  7. package/api/components/parameters/webhookName.js +10 -0
  8. package/api/components/parameters/webhookSecretId.d.ts +2 -0
  9. package/api/components/parameters/webhookSecretId.js +8 -0
  10. package/api/components/schemas/ActionDefinition.js +3 -0
  11. package/api/components/schemas/App.js +8 -0
  12. package/api/components/schemas/AppDefinition.js +6 -0
  13. package/api/components/schemas/AppLayoutDefinition.js +8 -0
  14. package/api/components/schemas/AppServiceSecret.js +5 -0
  15. package/api/components/schemas/AppWebhookSecret.d.ts +2 -0
  16. package/api/components/schemas/AppWebhookSecret.js +25 -0
  17. package/api/components/schemas/DialogOkActionDefinition.js +1 -1
  18. package/api/components/schemas/FilterParametersDefinition.d.ts +2 -0
  19. package/api/components/schemas/FilterParametersDefinition.js +15 -0
  20. package/api/components/schemas/FlowCancelActionDefinition.js +1 -1
  21. package/api/components/schemas/FlowFinishActionDefinition.js +1 -1
  22. package/api/components/schemas/GroupMemberDeleteActionDefinition.js +1 -1
  23. package/api/components/schemas/ResourceDefinition.js +5 -0
  24. package/api/components/schemas/ResourceDeleteAllActionDefinition.d.ts +1 -0
  25. package/api/components/schemas/ResourceDeleteAllActionDefinition.js +21 -0
  26. package/api/components/schemas/ResourceDeleteBulkActionDefinition.d.ts +1 -0
  27. package/api/components/schemas/ResourceDeleteBulkActionDefinition.js +18 -0
  28. package/api/components/schemas/ResourceGetActionDefinition.js +3 -0
  29. package/api/components/schemas/ResourcePatchActionDefinition.js +3 -0
  30. package/api/components/schemas/ResourceSubscriptionStatusActionDefinition.js +1 -0
  31. package/api/components/schemas/ResourceSubscriptionSubscribeActionDefinition.js +1 -0
  32. package/api/components/schemas/ResourceSubscriptionToggleActionDefinition.js +1 -0
  33. package/api/components/schemas/ResourceSubscriptionUnsubscribeActionDefinition.js +1 -0
  34. package/api/components/schemas/ResourceUpdatePositionsActionDefinition.d.ts +1 -0
  35. package/api/components/schemas/ResourceUpdatePositionsActionDefinition.js +21 -0
  36. package/api/components/schemas/SecurityCronDefinition.d.ts +2 -0
  37. package/api/components/schemas/SecurityCronDefinition.js +26 -0
  38. package/api/components/schemas/SecurityDefinition.js +1 -0
  39. package/api/components/schemas/StorageSubtractActionDefinition.js +2 -2
  40. package/api/components/schemas/Training.js +2 -25
  41. package/api/components/schemas/TrainingCompleted.d.ts +2 -0
  42. package/api/components/schemas/TrainingCompleted.js +17 -0
  43. package/api/components/schemas/WebhookDefinition.d.ts +2 -0
  44. package/api/components/schemas/WebhookDefinition.js +17 -0
  45. package/api/components/schemas/index.d.ts +8 -1
  46. package/api/components/schemas/index.js +8 -1
  47. package/api/components/schemas/utils.js +1 -1
  48. package/api/components/securitySchemes/index.d.ts +1 -0
  49. package/api/components/securitySchemes/index.js +1 -0
  50. package/api/components/securitySchemes/webhook.d.ts +2 -0
  51. package/api/components/securitySchemes/webhook.js +6 -0
  52. package/api/paths/apps/appId/resources/resourceType/resourceId/positions.js +54 -0
  53. package/api/paths/apps/appId/secrets/webhook/secretId.js +61 -0
  54. package/api/paths/apps/appId/secrets/webhook.js +44 -0
  55. package/api/paths/apps/appId/webhooks/webhookName.js +35 -0
  56. package/api/paths/apps/appId.js +6 -0
  57. package/api/paths/auth/email/patchPassword.js +30 -0
  58. package/api/paths/index.d.ts +7 -5
  59. package/api/paths/index.js +16 -12
  60. package/api/paths/trainings/completeTraining.js +18 -0
  61. package/api/paths/trainings/completedTrainings.d.ts +2 -0
  62. package/api/paths/trainings/completedTrainings.js +21 -0
  63. package/api/paths/trainings/trainingIds.d.ts +2 -0
  64. package/api/paths/trainings/trainingIds.js +20 -0
  65. package/api/tags/index.js +4 -4
  66. package/appMessages.js +1 -1
  67. package/assets.js +1 -1
  68. package/authorization.d.ts +1 -1
  69. package/authorization.js +1 -1
  70. package/blockUtils.d.ts +1 -1
  71. package/blockUtils.js +1 -0
  72. package/convertToCsv.js +2 -0
  73. package/examples.js +214 -4
  74. package/formatRequestAction.js +2 -2
  75. package/has.d.ts +1 -1
  76. package/has.js +1 -1
  77. package/i18n.js +6 -8
  78. package/ics.js +1 -1
  79. package/iterApp.js +3 -3
  80. package/jsonschema.js +16 -3
  81. package/package.json +15 -11
  82. package/reference-schemas/actions/appMember.d.ts +2 -0
  83. package/reference-schemas/actions/appMember.js +21 -0
  84. package/reference-schemas/actions/flow.d.ts +2 -0
  85. package/reference-schemas/actions/flow.js +13 -0
  86. package/reference-schemas/actions/group.d.ts +2 -0
  87. package/reference-schemas/actions/group.js +13 -0
  88. package/reference-schemas/actions/index.d.ts +7 -0
  89. package/reference-schemas/actions/index.js +8 -0
  90. package/reference-schemas/actions/link.d.ts +2 -0
  91. package/reference-schemas/actions/link.js +9 -0
  92. package/reference-schemas/actions/miscellaneous.d.ts +2 -0
  93. package/reference-schemas/actions/miscellaneous.js +41 -0
  94. package/reference-schemas/actions/resources.d.ts +2 -0
  95. package/reference-schemas/actions/resources.js +19 -0
  96. package/reference-schemas/actions/storage.d.ts +2 -0
  97. package/reference-schemas/actions/storage.js +15 -0
  98. package/reference-schemas/remappers/conditionals.js +39 -0
  99. package/reference-schemas/remappers/data.js +26 -2
  100. package/reference-schemas/remappers/index.d.ts +1 -0
  101. package/reference-schemas/remappers/index.js +1 -0
  102. package/reference-schemas/remappers/objects.js +32 -0
  103. package/reference-schemas/remappers/odata.d.ts +2 -0
  104. package/reference-schemas/remappers/odata.js +95 -0
  105. package/reference-schemas/remappers/strings.js +33 -0
  106. package/reference-schemas/remappers/unsorted.js +9 -0
  107. package/remap.d.ts +2 -0
  108. package/remap.js +192 -15
  109. package/serializeResource.d.ts +7 -0
  110. package/serializeResource.js +7 -0
  111. package/serverActions.d.ts +1 -1
  112. package/serverActions.js +2 -0
  113. package/theme.js +5 -1
  114. package/validateStyle.js +2 -0
  115. package/validation.js +52 -16
  116. package/api/components/parameters/trainingBlockId.d.ts +0 -2
  117. package/api/components/parameters/trainingBlockId.js +0 -8
  118. package/api/components/schemas/TrainingBlock.d.ts +0 -2
  119. package/api/components/schemas/TrainingBlock.js +0 -38
  120. package/api/components/securitySchemes/cli.test.d.ts +0 -1
  121. package/api/components/securitySchemes/cli.test.js +0 -7
  122. package/api/index.test.d.ts +0 -1
  123. package/api/index.test.js +0 -180
  124. package/api/paths/trainingBlocks/trainingBlockId.js +0 -41
  125. package/api/paths/trainings/trainingId/blocks.js +0 -51
  126. package/api/paths/trainings/trainingId/users/current.js +0 -62
  127. package/api/paths/trainings/trainingId/users.js +0 -25
  128. package/api/paths/trainings/trainingId.js +0 -85
  129. package/api/paths/trainings.js +0 -44
  130. package/appMessages.test.d.ts +0 -1
  131. package/appMessages.test.js +0 -409
  132. package/blockUtils.test.d.ts +0 -1
  133. package/blockUtils.test.js +0 -77
  134. package/constants/patterns.test.d.ts +0 -1
  135. package/constants/patterns.test.js +0 -83
  136. package/convertToCsv.test.d.ts +0 -1
  137. package/convertToCsv.test.js +0 -55
  138. package/has.test.d.ts +0 -1
  139. package/has.test.js +0 -17
  140. package/i18n.test.d.ts +0 -1
  141. package/i18n.test.js +0 -76
  142. package/iterApp.test.d.ts +0 -1
  143. package/iterApp.test.js +0 -439
  144. package/jsonschema.test.d.ts +0 -1
  145. package/jsonschema.test.js +0 -256
  146. package/mapValues.test.d.ts +0 -1
  147. package/mapValues.test.js +0 -16
  148. package/miscellaneous.test.d.ts +0 -1
  149. package/miscellaneous.test.js +0 -87
  150. package/normalize.test.d.ts +0 -1
  151. package/normalize.test.js +0 -23
  152. package/objectCache.test.d.ts +0 -1
  153. package/objectCache.test.js +0 -20
  154. package/prefix.test.d.ts +0 -1
  155. package/prefix.test.js +0 -11
  156. package/remap.test.d.ts +0 -1
  157. package/remap.test.js +0 -1387
  158. package/string.test.d.ts +0 -1
  159. package/string.test.js +0 -27
  160. package/theme.test.d.ts +0 -1
  161. package/theme.test.js +0 -91
  162. package/validateStyle.test.d.ts +0 -1
  163. package/validateStyle.test.js +0 -13
  164. package/validation.test.d.ts +0 -1
  165. package/validation.test.js +0 -3121
  166. /package/api/paths/{trainingBlocks/trainingBlockId.d.ts → apps/appId/resources/resourceType/resourceId/positions.d.ts} +0 -0
  167. /package/api/paths/{trainings/trainingId.d.ts → apps/appId/secrets/webhook/secretId.d.ts} +0 -0
  168. /package/api/paths/{trainings.d.ts → apps/appId/secrets/webhook.d.ts} +0 -0
  169. /package/api/paths/{trainings/trainingId/blocks.d.ts → apps/appId/webhooks/webhookName.d.ts} +0 -0
  170. /package/api/paths/{trainings/trainingId/users.d.ts → auth/email/patchPassword.d.ts} +0 -0
  171. /package/api/paths/trainings/{trainingId/users/current.d.ts → completeTraining.d.ts} +0 -0
package/i18n.test.js DELETED
@@ -1,76 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { detectLocale, sortLocales } from './i18n.js';
3
- describe('sortLocales', () => {
4
- const tests = [
5
- [
6
- // The user prefers any form of English.
7
- ['en'],
8
- ['en'],
9
- ],
10
- [
11
- // The user prefers international English, but is willing to accept any other form of English.
12
- ['en-US', 'en'],
13
- ['en-us', 'en'],
14
- ],
15
- [
16
- // The user accepts English, preferably international English.
17
- ['en', 'en-US'],
18
- ['en-us', 'en'],
19
- ],
20
- [
21
- // The user accepts any for of English, preferably international English, or British over
22
- // alternative forms.
23
- ['en', 'en-US', 'en-GB'],
24
- ['en-us', 'en-gb', 'en'],
25
- ],
26
- [
27
- // The accepts English, or Dutch.
28
- ['en', 'nl'],
29
- ['en', 'nl'],
30
- ],
31
- [
32
- // The accepts English, or Dutch (Netherlands).
33
- ['en', 'nl-NL'],
34
- ['en', 'nl-nl'],
35
- ],
36
- [
37
- // XXX because Britsh is a subtag of English, it should be preferred over Dutch
38
- ['en', 'en-US', 'nl', 'nl-NL', 'nl-BE', 'en-GB'],
39
- ['en-us', 'en', 'nl-nl', 'nl-be', 'nl', 'en-gb'],
40
- ],
41
- [
42
- // More specific languages of the same subtag should be sorted first.
43
- ['zh', 'zh-Hant', 'zh-Hant-HK'],
44
- ['zh-hant-hk', 'zh-hant', 'zh'],
45
- ],
46
- [
47
- // XXX because international English is a subtag of English, it should be preferred over
48
- // Chinese.
49
- ['en', 'zh', 'zh-Hant', 'zh-Hant-HK', 'en-US'],
50
- ['en', 'zh-hant-hk', 'zh-hant', 'zh', 'en-us'],
51
- ],
52
- [
53
- // Locales that share the same starting characters should be treated differently.
54
- ['cu', 'custom', 'custom-locale', 'cu'],
55
- ['cu', 'custom-locale', 'custom', 'cu'],
56
- ],
57
- ];
58
- it.each(tests)('should sort %p as %p', (languages, expected) => {
59
- const result = sortLocales(languages);
60
- expect(result).toStrictEqual(expected);
61
- });
62
- });
63
- describe('detectLocale', () => {
64
- const tests = [
65
- [['en'], ['en'], 'en'],
66
- [['en', 'en-US'], ['en', 'en-US'], 'en-us'],
67
- [['nl'], ['en', 'en-US'], undefined],
68
- // XXX The following need to be handled by the sorting algorithm in `sortLocales()`,
69
- [['en', 'nl', 'en-US'], ['en', 'nl', 'en-US'], 'en'],
70
- ];
71
- it.each(tests)('%p %p %p', (languages, choices, expected) => {
72
- const result = detectLocale(languages, choices);
73
- expect(result).toBe(expected);
74
- });
75
- });
76
- //# sourceMappingURL=i18n.test.js.map
package/iterApp.test.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/iterApp.test.js DELETED
@@ -1,439 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
- import { iterAction, iterApp, iterBlock, iterBlockList, iterPage } from './iterApp.js';
3
- describe('iterAction', () => {
4
- it('should call the appropriate callbacks', () => {
5
- const onAction = vi.fn();
6
- const onBlockList = vi.fn();
7
- const action = {
8
- type: 'dialog',
9
- blocks: [{ type: 'list', version: '0.1.2' }],
10
- };
11
- const result = iterAction(action, { onAction, onBlockList });
12
- expect(onAction).toHaveBeenCalledWith(action, []);
13
- expect(onBlockList).toHaveBeenCalledWith(action.blocks, ['blocks']);
14
- expect(result).toBe(false);
15
- });
16
- it('should abort if the onAction callback returns true', () => {
17
- const onAction = vi.fn().mockReturnValue(true);
18
- const onBlockList = vi.fn();
19
- const action = {
20
- type: 'dialog',
21
- blocks: [{ type: 'list', version: '0.1.2' }],
22
- };
23
- const result = iterAction(action, { onAction, onBlockList });
24
- expect(onAction).toHaveBeenCalledWith(action, []);
25
- expect(onBlockList).not.toHaveBeenCalled();
26
- expect(result).toBe(true);
27
- });
28
- it('should call onAction for onSuccess', () => {
29
- const onAction = vi.fn();
30
- const onBlockList = vi.fn();
31
- const action = {
32
- type: 'noop',
33
- onSuccess: {
34
- type: 'noop',
35
- },
36
- };
37
- const result = iterAction(action, { onAction, onBlockList });
38
- expect(onAction).toHaveBeenCalledTimes(2);
39
- expect(onAction).toHaveBeenCalledWith(action, []);
40
- expect(onAction).toHaveBeenCalledWith(action.onSuccess, ['onSuccess']);
41
- expect(result).toBe(false);
42
- });
43
- it('should return true if onAction returns true for onSuccess', () => {
44
- const onAction = vi.fn().mockImplementation((a, [prefix]) => prefix === 'onSuccess');
45
- const onBlockList = vi.fn();
46
- const action = {
47
- type: 'noop',
48
- onSuccess: {
49
- type: 'noop',
50
- },
51
- };
52
- const result = iterAction(action, { onAction, onBlockList });
53
- expect(onAction).toHaveBeenCalledTimes(2);
54
- expect(onAction).toHaveBeenCalledWith(action, []);
55
- expect(onAction).toHaveBeenCalledWith(action.onSuccess, ['onSuccess']);
56
- expect(result).toBe(true);
57
- });
58
- it('should call onAction for onError', () => {
59
- const onAction = vi.fn();
60
- const onBlockList = vi.fn();
61
- const action = {
62
- type: 'noop',
63
- onError: {
64
- type: 'noop',
65
- },
66
- };
67
- const result = iterAction(action, { onAction, onBlockList });
68
- expect(onAction).toHaveBeenCalledTimes(2);
69
- expect(onAction).toHaveBeenCalledWith(action, []);
70
- expect(onAction).toHaveBeenCalledWith(action.onError, ['onError']);
71
- expect(result).toBe(false);
72
- });
73
- it('should return true if onAction returns true for onError', () => {
74
- const onAction = vi.fn().mockImplementation((a, [prefix]) => prefix === 'onError');
75
- const onBlockList = vi.fn();
76
- const action = {
77
- type: 'noop',
78
- onError: {
79
- type: 'noop',
80
- },
81
- };
82
- const result = iterAction(action, { onAction, onBlockList });
83
- expect(onAction).toHaveBeenCalledTimes(2);
84
- expect(onAction).toHaveBeenCalledWith(action, []);
85
- expect(onAction).toHaveBeenCalledWith(action.onError, ['onError']);
86
- expect(result).toBe(true);
87
- });
88
- it('should call then and else for conditional actions', () => {
89
- const onAction = vi.fn();
90
- const action = {
91
- type: 'condition',
92
- if: true,
93
- then: { type: 'noop' },
94
- else: { type: 'noop' },
95
- };
96
- const result = iterAction(action, { onAction });
97
- expect(onAction).toHaveBeenCalledWith(action, []);
98
- expect(onAction).toHaveBeenCalledWith(action.then, ['then']);
99
- expect(onAction).toHaveBeenCalledWith(action.else, ['else']);
100
- expect(result).toBe(false);
101
- });
102
- it('should return the return value of iterBlockList', () => {
103
- const onAction = vi.fn();
104
- const onBlockList = vi.fn().mockReturnValue(true);
105
- const action = {
106
- type: 'dialog',
107
- blocks: [{ type: 'list', version: '0.1.2' }],
108
- };
109
- const result = iterAction(action, {
110
- onAction,
111
- onBlockList,
112
- });
113
- expect(onAction).toHaveBeenCalledWith(action, []);
114
- expect(onBlockList).toHaveBeenCalledWith(action.blocks, ['blocks']);
115
- expect(result).toBe(true);
116
- });
117
- it('should not call iterBlockList if the action has no blocks', () => {
118
- const onAction = vi.fn();
119
- const onBlockList = vi.fn();
120
- const action = {
121
- type: 'log',
122
- };
123
- const result = iterAction(action, {
124
- onAction,
125
- onBlockList,
126
- });
127
- expect(onAction).toHaveBeenCalledWith(action, []);
128
- expect(onBlockList).not.toHaveBeenCalled();
129
- expect(result).toBe(false);
130
- });
131
- });
132
- describe('iterBlock', () => {
133
- it('should call the appropriate callbacks', () => {
134
- const onAction = vi.fn();
135
- const onBlock = vi.fn();
136
- const block = {
137
- type: 'list',
138
- version: '1.2.3',
139
- actions: {
140
- onClick: {
141
- type: 'log',
142
- },
143
- },
144
- };
145
- const result = iterBlock(block, { onAction, onBlock });
146
- expect(onAction).toHaveBeenCalledWith(block.actions.onClick, ['actions', 'onClick']);
147
- expect(onBlock).toHaveBeenCalledWith(block, []);
148
- expect(result).toBe(false);
149
- });
150
- it('should abort if onBlock returns true', () => {
151
- const onAction = vi.fn();
152
- const onBlock = vi.fn().mockReturnValue(true);
153
- const block = {
154
- type: 'list',
155
- version: '1.2.3',
156
- actions: {
157
- onClick: {
158
- type: 'log',
159
- },
160
- },
161
- };
162
- const result = iterBlock(block, { onAction, onBlock });
163
- expect(onAction).not.toHaveBeenCalled();
164
- expect(onBlock).toHaveBeenCalledWith(block, []);
165
- expect(result).toBe(true);
166
- });
167
- it('should return the return value of onAction', () => {
168
- const onAction = vi.fn().mockReturnValue(true);
169
- const onBlock = vi.fn();
170
- const block = {
171
- type: 'list',
172
- version: '1.2.3',
173
- actions: {
174
- onClick: {
175
- type: 'log',
176
- },
177
- },
178
- };
179
- const result = iterBlock(block, { onAction, onBlock });
180
- expect(onAction).toHaveBeenCalledWith(block.actions.onClick, ['actions', 'onClick']);
181
- expect(onBlock).toHaveBeenCalledWith(block, []);
182
- expect(result).toBe(true);
183
- });
184
- });
185
- describe('iterBlockList', () => {
186
- it('should call the appropriate callbacks', () => {
187
- const onBlock = vi.fn();
188
- const onBlockList = vi.fn();
189
- const blocks = [
190
- {
191
- type: 'list',
192
- version: '1.2.3',
193
- actions: {
194
- onClick: {
195
- type: 'log',
196
- },
197
- },
198
- },
199
- ];
200
- const result = iterBlockList(blocks, { onBlockList, onBlock });
201
- expect(onBlockList).toHaveBeenCalledWith(blocks, []);
202
- expect(onBlock).toHaveBeenCalledWith(blocks[0], [0]);
203
- expect(result).toBe(false);
204
- });
205
- it('should abort if onBlockList returns true', () => {
206
- const onBlock = vi.fn();
207
- const onBlockList = vi.fn().mockReturnValue(true);
208
- const blocks = [
209
- {
210
- type: 'list',
211
- version: '1.2.3',
212
- actions: {
213
- onClick: {
214
- type: 'log',
215
- },
216
- },
217
- },
218
- ];
219
- const result = iterBlockList(blocks, { onBlockList, onBlock });
220
- expect(onBlockList).toHaveBeenCalledWith(blocks, []);
221
- expect(onBlock).not.toHaveBeenCalled();
222
- expect(result).toBe(true);
223
- });
224
- });
225
- describe('iterPage', () => {
226
- it('should iterate over a page', () => {
227
- const onBlockList = vi.fn();
228
- const onPage = vi.fn();
229
- const page = {
230
- name: 'Page',
231
- blocks: [],
232
- };
233
- const result = iterPage(page, { onBlockList, onPage });
234
- expect(onBlockList).toHaveBeenCalledWith(page.blocks, ['blocks']);
235
- expect(onPage).toHaveBeenCalledWith(page, []);
236
- expect(result).toBe(false);
237
- });
238
- it('should iterate over a container page', () => {
239
- const onBlockList = vi.fn();
240
- const onPage = vi.fn();
241
- const page = {
242
- name: 'Container Page',
243
- type: 'container',
244
- pages: [
245
- {
246
- name: 'Page 1',
247
- blocks: [],
248
- },
249
- {
250
- name: 'Page 2',
251
- blocks: [],
252
- },
253
- ],
254
- };
255
- const result = iterPage(page, { onBlockList, onPage });
256
- expect(onBlockList).toHaveBeenCalledWith(page.pages[0].blocks, [
257
- 'blocks',
258
- ]);
259
- expect(onBlockList).toHaveBeenCalledWith(page.pages[1].blocks, [
260
- 'blocks',
261
- ]);
262
- expect(onPage).toHaveBeenCalledWith(page, []);
263
- expect(result).toBe(false);
264
- });
265
- it('should abort if onPage returns true', () => {
266
- const onBlockList = vi.fn();
267
- const onPage = vi.fn().mockReturnValue(true);
268
- const page = {
269
- name: 'Page',
270
- blocks: [],
271
- };
272
- const result = iterPage(page, { onBlockList, onPage });
273
- expect(onBlockList).not.toHaveBeenCalled();
274
- expect(onPage).toHaveBeenCalledWith(page, []);
275
- expect(result).toBe(true);
276
- });
277
- it('should iterate a flow page', () => {
278
- const onBlockList = vi.fn();
279
- const onPage = vi.fn();
280
- const page = {
281
- name: 'Page',
282
- type: 'flow',
283
- steps: [
284
- {
285
- name: 'Flow page 1',
286
- blocks: [],
287
- },
288
- ],
289
- };
290
- const result = iterPage(page, { onBlockList, onPage });
291
- expect(onBlockList).toHaveBeenCalledWith(page.steps[0].blocks, ['steps', 0, 'blocks']);
292
- expect(onPage).toHaveBeenCalledWith(page, []);
293
- expect(result).toBe(false);
294
- });
295
- it('should iterate a tabs page', () => {
296
- const onBlockList = vi.fn();
297
- const onPage = vi.fn();
298
- const page = {
299
- name: 'Page',
300
- type: 'tabs',
301
- tabs: [
302
- {
303
- name: 'Tabs page 1',
304
- blocks: [],
305
- },
306
- ],
307
- };
308
- const result = iterPage(page, { onBlockList, onPage });
309
- expect(onBlockList).toHaveBeenCalledWith(page.tabs[0].blocks, ['tabs', 0, 'blocks']);
310
- expect(onPage).toHaveBeenCalledWith(page, []);
311
- expect(result).toBe(false);
312
- });
313
- it('should call onAction for page actions', () => {
314
- const onAction = vi.fn();
315
- const onPage = vi.fn();
316
- const page = {
317
- name: 'Page',
318
- type: 'flow',
319
- actions: {
320
- onFlowFinish: {
321
- type: 'log',
322
- },
323
- },
324
- steps: [],
325
- };
326
- const result = iterPage(page, { onAction, onPage });
327
- expect(onAction).toHaveBeenCalledWith(page.actions.onFlowFinish, ['actions', 'onFlowFinish']);
328
- expect(onPage).toHaveBeenCalledWith(page, []);
329
- expect(result).toBe(false);
330
- });
331
- it('should call onAction and onBlockList for pages with actions and sub pages', () => {
332
- const onAction = vi.fn();
333
- const onPage = vi.fn();
334
- const onBlockList = vi.fn();
335
- const page = {
336
- name: 'Page',
337
- type: 'flow',
338
- actions: {
339
- onFlowFinish: {
340
- type: 'log',
341
- },
342
- },
343
- steps: [
344
- {
345
- name: 'Test Subpage 1',
346
- blocks: [
347
- {
348
- type: 'list',
349
- version: '1.2.3',
350
- actions: {
351
- onClick: {
352
- type: 'log',
353
- },
354
- },
355
- },
356
- ],
357
- },
358
- ],
359
- };
360
- const result = iterPage(page, { onAction, onPage, onBlockList });
361
- expect(onAction).toHaveBeenCalledWith(page.actions.onFlowFinish, ['actions', 'onFlowFinish']);
362
- expect(onPage).toHaveBeenCalledWith(page, []);
363
- expect(onBlockList).toHaveBeenCalledWith(page.steps[0].blocks, ['steps', 0, 'blocks']);
364
- expect(result).toBe(false);
365
- });
366
- });
367
- describe('iterApp', () => {
368
- it('should iterate over the page of an app', () => {
369
- const onPage = vi.fn();
370
- const app = {
371
- name: 'App',
372
- defaultPage: 'Page',
373
- pages: [
374
- {
375
- name: 'Page',
376
- blocks: [],
377
- },
378
- ],
379
- };
380
- const result = iterApp(app, { onPage });
381
- expect(onPage).toHaveBeenCalledWith(app.pages[0], ['pages', 0]);
382
- expect(result).toBe(false);
383
- });
384
- it('should abort page iteration if a callback returns true', () => {
385
- const onPage = vi.fn().mockReturnValue(true);
386
- const app = {
387
- name: 'App',
388
- defaultPage: 'Page 1',
389
- pages: [
390
- {
391
- name: 'Page 1',
392
- blocks: [],
393
- },
394
- {
395
- name: 'Page 2',
396
- blocks: [],
397
- },
398
- ],
399
- };
400
- const result = iterApp(app, { onPage });
401
- expect(onPage).toHaveBeenCalledTimes(1);
402
- expect(onPage).toHaveBeenCalledWith(app.pages[0], ['pages', 0]);
403
- expect(result).toBe(true);
404
- });
405
- it('should iterate over cron jobs', () => {
406
- const onAction = vi.fn();
407
- const app = {
408
- name: 'App',
409
- defaultPage: 'Page 1',
410
- pages: [],
411
- cron: {
412
- foo: { schedule: '', action: { type: 'noop' } },
413
- bar: { schedule: '', action: { type: 'noop' } },
414
- },
415
- };
416
- const result = iterApp(app, { onAction });
417
- expect(onAction).toHaveBeenCalledTimes(2);
418
- expect(onAction).toHaveBeenCalledWith(app.cron.foo.action, ['cron', 'foo', 'action']);
419
- expect(onAction).toHaveBeenCalledWith(app.cron.bar.action, ['cron', 'bar', 'action']);
420
- expect(result).toBe(false);
421
- });
422
- it('should abort cron iteration if a callback returns true', () => {
423
- const onAction = vi.fn().mockReturnValue(true);
424
- const app = {
425
- name: 'App',
426
- defaultPage: 'Page 1',
427
- pages: [],
428
- cron: {
429
- foo: { schedule: '', action: { type: 'noop' } },
430
- bar: { schedule: '', action: { type: 'noop' } },
431
- },
432
- };
433
- const result = iterApp(app, { onAction });
434
- expect(onAction).toHaveBeenCalledTimes(1);
435
- expect(onAction).toHaveBeenCalledWith(app.cron.foo.action, ['cron', 'foo', 'action']);
436
- expect(result).toBe(true);
437
- });
438
- });
439
- //# sourceMappingURL=iterApp.test.js.map
@@ -1 +0,0 @@
1
- export {};