@nyaruka/temba-components 0.43.8 → 0.45.0

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 (38) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/{005a8061.js → 0887303b.js} +75 -55
  3. package/dist/index.js +75 -55
  4. package/dist/sw.js +1 -1
  5. package/dist/sw.js.map +1 -1
  6. package/dist/templates/components-body.html +1 -1
  7. package/dist/templates/components-head.html +1 -1
  8. package/out-tsc/src/compose/Compose.js +143 -83
  9. package/out-tsc/src/compose/Compose.js.map +1 -1
  10. package/out-tsc/src/contacts/ContactChat.js +6 -12
  11. package/out-tsc/src/contacts/ContactChat.js.map +1 -1
  12. package/out-tsc/src/contacts/ContactFields.js +1 -1
  13. package/out-tsc/src/contacts/ContactFields.js.map +1 -1
  14. package/out-tsc/src/contacts/ContactNameFetch.js +2 -1
  15. package/out-tsc/src/contacts/ContactNameFetch.js.map +1 -1
  16. package/out-tsc/src/list/TembaMenu.js +1 -6
  17. package/out-tsc/src/list/TembaMenu.js.map +1 -1
  18. package/out-tsc/src/store/Store.js +32 -1
  19. package/out-tsc/src/store/Store.js.map +1 -1
  20. package/out-tsc/src/store/StoreElement.js +19 -5
  21. package/out-tsc/src/store/StoreElement.js.map +1 -1
  22. package/out-tsc/test/temba-compose.test.js +154 -5
  23. package/out-tsc/test/temba-compose.test.js.map +1 -1
  24. package/out-tsc/test/temba-store.test.js +1 -1
  25. package/out-tsc/test/temba-store.test.js.map +1 -1
  26. package/out-tsc/test/utils.test.js +2 -2
  27. package/out-tsc/test/utils.test.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/compose/Compose.ts +159 -94
  30. package/src/contacts/ContactChat.ts +8 -11
  31. package/src/contacts/ContactFields.ts +1 -1
  32. package/src/contacts/ContactNameFetch.ts +2 -1
  33. package/src/list/TembaMenu.ts +1 -6
  34. package/src/store/Store.ts +34 -2
  35. package/src/store/StoreElement.ts +16 -6
  36. package/test/temba-compose.test.ts +172 -5
  37. package/test/temba-store.test.ts +1 -1
  38. package/test/utils.test.ts +2 -2
@@ -23,11 +23,26 @@ export const updateComponent = async (
23
23
  attachments?: Attachment[],
24
24
  errorAttachments?: Attachment[]
25
25
  ): Promise<void> => {
26
- compose.currentChat = text ? text : '';
27
- compose.values = attachments ? attachments : [];
28
- compose.errorValues = errorAttachments ? errorAttachments : [];
26
+ compose.currentText = text ? text : '';
27
+ compose.currentAttachments = attachments ? attachments : [];
28
+ compose.failedAttachments = errorAttachments ? errorAttachments : [];
29
29
  await compose.updateComplete;
30
30
  };
31
+
32
+ const getInitialValue = (text?: string, attachments?: Attachment[]): any => {
33
+ const composeValue = {
34
+ text: text ? text : '',
35
+ attachments: attachments ? attachments : [],
36
+ };
37
+ return composeValue;
38
+ };
39
+ const getComposeValue = (value: any): string => {
40
+ return JSON.stringify(value);
41
+ };
42
+ const getComposeValues = (value: any): any[] => {
43
+ return [value];
44
+ };
45
+
31
46
  export const getSuccessText = () => {
32
47
  return 'sà-wàd-dee!';
33
48
  };
@@ -152,6 +167,25 @@ describe('temba-compose chatbox', () => {
152
167
  );
153
168
  });
154
169
 
170
+ it('chatbox counter and send button deserialize and serialize', async () => {
171
+ const initialValue = getInitialValue();
172
+ const composeValue = getComposeValue(initialValue);
173
+ const composeValues = getComposeValues(initialValue);
174
+
175
+ const compose: Compose = await getCompose({
176
+ chatbox: true,
177
+ counter: true,
178
+ button: true,
179
+ value: composeValue,
180
+ });
181
+ // deserialize
182
+ expect(compose.currentText).to.equal('');
183
+ expect(compose.currentAttachments).to.deep.equal([]);
184
+ // serialize
185
+ expect(compose.value).to.equal(composeValue);
186
+ expect(compose.values).to.deep.equal(composeValues);
187
+ });
188
+
155
189
  it('chatbox with text', async () => {
156
190
  const compose: Compose = await getCompose({
157
191
  chatbox: true,
@@ -162,6 +196,25 @@ describe('temba-compose chatbox', () => {
162
196
  await assertScreenshot('compose/chatbox-with-text', getClip(compose));
163
197
  });
164
198
 
199
+ it('chatbox with text deserialize and serialize', async () => {
200
+ const initialValue = getInitialValue(getSuccessText());
201
+ const composeValue = getComposeValue(initialValue);
202
+ const composeValues = getComposeValues(initialValue);
203
+
204
+ const compose: Compose = await getCompose({
205
+ chatbox: true,
206
+ counter: true,
207
+ button: true,
208
+ value: composeValue,
209
+ });
210
+ // deserialize
211
+ expect(compose.currentText).to.equal(getSuccessText());
212
+ expect(compose.currentAttachments).to.deep.equal([]);
213
+ // serialize
214
+ expect(compose.value).to.equal(composeValue);
215
+ expect(compose.values).to.deep.equal(composeValues);
216
+ });
217
+
165
218
  it('chatbox with text and spaces', async () => {
166
219
  const compose: Compose = await getCompose({
167
220
  chatbox: true,
@@ -258,6 +311,24 @@ describe('temba-compose attachments', () => {
258
311
  );
259
312
  });
260
313
 
314
+ it('attachments and send button deserialize and serialize', async () => {
315
+ const initialValue = getInitialValue();
316
+ const composeValue = getComposeValue(initialValue);
317
+ const composeValues = getComposeValues(initialValue);
318
+
319
+ const compose: Compose = await getCompose({
320
+ attachments: true,
321
+ button: true,
322
+ value: composeValue,
323
+ });
324
+ // deserialize
325
+ expect(compose.currentText).to.equal('');
326
+ expect(compose.currentAttachments).to.deep.equal([]);
327
+ // serialize
328
+ expect(compose.value).to.equal(composeValue);
329
+ expect(compose.values).to.deep.equal(composeValues);
330
+ });
331
+
261
332
  it('attachments with success uploaded files', async () => {
262
333
  const compose: Compose = await getCompose({
263
334
  attachments: true,
@@ -270,6 +341,24 @@ describe('temba-compose attachments', () => {
270
341
  );
271
342
  });
272
343
 
344
+ it('attachments with success uploaded files deserialize and serialize', async () => {
345
+ const initialValue = getInitialValue(null, getSuccessFiles());
346
+ const composeValue = getComposeValue(initialValue);
347
+ const composeValues = getComposeValues(initialValue);
348
+
349
+ const compose: Compose = await getCompose({
350
+ attachments: true,
351
+ button: true,
352
+ value: composeValue,
353
+ });
354
+ // deserialize
355
+ expect(compose.currentText).to.equal('');
356
+ expect(compose.currentAttachments).to.deep.equal(getSuccessFiles());
357
+ // serialize
358
+ expect(compose.value).to.equal(composeValue);
359
+ expect(compose.values).to.deep.equal(composeValues);
360
+ });
361
+
273
362
  it('attachments with failure uploaded files', async () => {
274
363
  const compose: Compose = await getCompose({
275
364
  attachments: true,
@@ -375,6 +464,26 @@ describe('temba-compose chatbox and attachments', () => {
375
464
  getClip(compose)
376
465
  );
377
466
  });
467
+
468
+ it('chatbox and attachments counter and send button deserialize and serialize', async () => {
469
+ const initialValue = getInitialValue();
470
+ const composeValue = getComposeValue(initialValue);
471
+ const composeValues = getComposeValues(initialValue);
472
+
473
+ const compose: Compose = await getCompose({
474
+ chatbox: true,
475
+ attachments: true,
476
+ counter: true,
477
+ button: true,
478
+ value: composeValue,
479
+ });
480
+ // deserialize
481
+ expect(compose.currentText).to.equal('');
482
+ expect(compose.currentAttachments).to.deep.equal([]);
483
+ // serialize
484
+ expect(compose.value).to.equal(composeValue);
485
+ expect(compose.values).to.deep.equal(composeValues);
486
+ });
378
487
  });
379
488
 
380
489
  describe('temba-compose chatbox with text and attachments no files', () => {
@@ -385,13 +494,33 @@ describe('temba-compose chatbox with text and attachments no files', () => {
385
494
  counter: true,
386
495
  button: true,
387
496
  });
388
- compose.currentChat = 'sà-wàd-dee!';
497
+ updateComponent(compose, getSuccessText());
389
498
  await assertScreenshot(
390
499
  'compose/chatbox-with-text-attachments-no-files',
391
500
  getClip(compose)
392
501
  );
393
502
  });
394
503
 
504
+ it('chatbox with text, attachments no files deserialize and serialize', async () => {
505
+ const initialValue = getInitialValue(getSuccessText());
506
+ const composeValue = getComposeValue(initialValue);
507
+ const composeValues = getComposeValues(initialValue);
508
+
509
+ const compose: Compose = await getCompose({
510
+ chatbox: true,
511
+ attachments: true,
512
+ counter: true,
513
+ button: true,
514
+ value: composeValue,
515
+ });
516
+ // deserialize
517
+ expect(compose.currentText).to.equal(getSuccessText());
518
+ expect(compose.currentAttachments).to.deep.equal([]);
519
+ // serialize
520
+ expect(compose.value).to.equal(composeValue);
521
+ expect(compose.values).to.deep.equal(composeValues);
522
+ });
523
+
395
524
  it('chatbox with text, attachments no files, and click send', async () => {
396
525
  const compose: Compose = await getCompose({
397
526
  chatbox: true,
@@ -399,7 +528,7 @@ describe('temba-compose chatbox with text and attachments no files', () => {
399
528
  counter: true,
400
529
  button: true,
401
530
  });
402
- compose.currentChat = 'sà-wàd-dee!';
531
+ updateComponent(compose, getSuccessText());
403
532
  const send = compose.shadowRoot.querySelector(
404
533
  'temba-button#send-button'
405
534
  ) as Button;
@@ -443,6 +572,25 @@ describe('temba-compose chatbox no text and attachments with files', () => {
443
572
  );
444
573
  });
445
574
 
575
+ it('chatbox no text, attachments with success uploaded files deserialize and serialize', async () => {
576
+ const initialValue = getInitialValue(null, getSuccessFiles());
577
+ const composeValue = getComposeValue(initialValue);
578
+ const composeValues = getComposeValues(initialValue);
579
+
580
+ const compose: Compose = await getCompose({
581
+ chatbox: true,
582
+ attachments: true,
583
+ button: true,
584
+ value: composeValue,
585
+ });
586
+ // deserialize
587
+ expect(compose.currentText).to.equal('');
588
+ expect(compose.currentAttachments).to.deep.equal(getSuccessFiles());
589
+ // serialize
590
+ expect(compose.value).to.equal(composeValue);
591
+ expect(compose.values).to.deep.equal(composeValues);
592
+ });
593
+
446
594
  it('chatbox no text, attachments with failure uploaded files', async () => {
447
595
  const compose: Compose = await getCompose({
448
596
  chatbox: true,
@@ -518,6 +666,25 @@ describe('temba-compose chatbox with text and attachments with files', () => {
518
666
  );
519
667
  });
520
668
 
669
+ it('chatbox with text, attachments with success uploaded files deserialize and serialize', async () => {
670
+ const initialValue = getInitialValue(getSuccessText(), getSuccessFiles());
671
+ const composeValue = getComposeValue(initialValue);
672
+ const composeValues = getComposeValues(initialValue);
673
+
674
+ const compose: Compose = await getCompose({
675
+ chatbox: true,
676
+ attachments: true,
677
+ button: true,
678
+ value: composeValue,
679
+ });
680
+ // deserialize
681
+ expect(compose.currentText).to.equal(getSuccessText());
682
+ expect(compose.currentAttachments).to.deep.equal(getSuccessFiles());
683
+ // serialize
684
+ expect(compose.value).to.equal(composeValue);
685
+ expect(compose.values).to.deep.equal(composeValues);
686
+ });
687
+
521
688
  it('chatbox with text, attachments with failure uploaded files', async () => {
522
689
  const compose: Compose = await getCompose({
523
690
  chatbox: true,
@@ -4,7 +4,7 @@ import './utils.test';
4
4
 
5
5
  const createStore = async (def: string): Promise<Store> => {
6
6
  const store = (await fixture(def)) as Store;
7
- await store.httpComplete;
7
+ await store.initialHttpComplete;
8
8
  return store;
9
9
  };
10
10
 
@@ -231,8 +231,8 @@ export const loadStore = async () => {
231
231
  fields='/test-assets/store/fields.json'
232
232
  />`
233
233
  );
234
- await store.httpComplete;
235
- await store.httpComplete;
234
+ await store.initialHttpComplete;
235
+ await store.initialHttpComplete;
236
236
 
237
237
  return store;
238
238
  };