@roeehrl/tinode-sdk 0.25.1-sqlite.1

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.
@@ -0,0 +1,1600 @@
1
+ import * as Drafty from './drafty';
2
+
3
+ // Drafty.parse test data.
4
+ const parse_this = [
5
+ [
6
+ 'This is *bold*, `code` and _italic_, ~strike~',
7
+ {
8
+ "fmt": [{
9
+ "at": 8,
10
+ "len": 4,
11
+ "tp": "ST"
12
+ },
13
+ {
14
+ "at": 14,
15
+ "len": 4,
16
+ "tp": "CO"
17
+ },
18
+ {
19
+ "at": 23,
20
+ "len": 6,
21
+ "tp": "EM"
22
+ },
23
+ {
24
+ "at": 31,
25
+ "len": 6,
26
+ "tp": "DL"
27
+ },
28
+ ],
29
+ "txt": "This is bold, code and italic, strike",
30
+ }
31
+ ],
32
+ [
33
+ 'Это *жЫрный*, `код` и _наклонный_, ~зачеркнутый~',
34
+ {
35
+ "fmt": [{
36
+ "at": 4,
37
+ "len": 6,
38
+ "tp": "ST"
39
+ },
40
+ {
41
+ "at": 12,
42
+ "len": 3,
43
+ "tp": "CO"
44
+ },
45
+ {
46
+ "at": 18,
47
+ "len": 9,
48
+ "tp": "EM"
49
+ },
50
+ {
51
+ "at": 29,
52
+ "len": 11,
53
+ "tp": "DL"
54
+ },
55
+ ],
56
+ "txt": "Это жЫрный, код и наклонный, зачеркнутый",
57
+ }
58
+ ],
59
+ [
60
+ 'combined *bold and _italic_*',
61
+ {
62
+ "fmt": [{
63
+ "at": 18,
64
+ "len": 6,
65
+ "tp": "EM"
66
+ },
67
+ {
68
+ "at": 9,
69
+ "len": 15,
70
+ "tp": "ST"
71
+ },
72
+ ],
73
+ "txt": "combined bold and italic",
74
+ }
75
+ ],
76
+ // FIXME: this test is inconsistent between golang, Android, and Javascript.
77
+ [
78
+ 'This *text _has* staggered_ formats',
79
+ {
80
+ "fmt": [{
81
+ "at": 5,
82
+ "len": 9,
83
+ "tp": "ST"
84
+ }, ],
85
+ "txt": "This text _has staggered_ formats",
86
+ },
87
+ ],
88
+ [
89
+ 'an url: https://www.example.com/abc#fragment and another _www.tinode.co_',
90
+ {
91
+ "ent": [{
92
+ "data": {
93
+ "url": "https://www.example.com/abc#fragment"
94
+ },
95
+ "tp": "LN"
96
+ },
97
+ {
98
+ "data": {
99
+ "url": "http://www.tinode.co"
100
+ },
101
+ "tp": "LN"
102
+ },
103
+ ],
104
+ "fmt": [{
105
+ "at": 57,
106
+ "len": 13,
107
+ "tp": "EM"
108
+ },
109
+ {
110
+ "at": 8,
111
+ "len": 36,
112
+ "key": 0
113
+ },
114
+ {
115
+ "at": 57,
116
+ "len": 13,
117
+ "key": 1
118
+ },
119
+ ],
120
+ "txt": "an url: https://www.example.com/abc#fragment and another www.tinode.co"
121
+ },
122
+ ],
123
+ [
124
+ 'this is a @mention and a #hashtag in a string',
125
+ {
126
+ "ent": [{
127
+ "data": {
128
+ "val": "mention"
129
+ },
130
+ "tp": "MN"
131
+ },
132
+ {
133
+ "data": {
134
+ "val": "hashtag"
135
+ },
136
+ "tp": "HT"
137
+ },
138
+ ],
139
+ "fmt": [{
140
+ "at": 10,
141
+ "key": 0,
142
+ "len": 8
143
+ },
144
+ {
145
+ "at": 25,
146
+ "key": 1,
147
+ "len": 8
148
+ },
149
+ ],
150
+ "txt": "this is a @mention and a #hashtag in a string"
151
+ },
152
+ ],
153
+ [
154
+ 'second #юникод',
155
+ {
156
+ "ent": [{
157
+ "data": {
158
+ "val": "юникод"
159
+ },
160
+ "tp": "HT"
161
+ }, ],
162
+ "fmt": [{
163
+ "at": 7,
164
+ "key": 0,
165
+ "len": 7
166
+ }, ],
167
+ "txt": "second #юникод",
168
+ },
169
+ ],
170
+ [
171
+ '😀 *b1👩🏽‍✈️b2* smile',
172
+ {
173
+ "txt": "😀 b1👩🏽‍✈️b2 smile",
174
+ "fmt": [{
175
+ "tp": "ST",
176
+ "at": 2,
177
+ "len": 5
178
+ }, ],
179
+ }
180
+ ],
181
+ [
182
+ 'first 😀 line\nsecond *line*',
183
+ {
184
+ "txt": "first 😀 line second line",
185
+ "fmt": [{
186
+ "tp": "BR",
187
+ "at": 12,
188
+ "len": 1
189
+ }, {
190
+ "tp": "ST",
191
+ "at": 20,
192
+ "len": 4
193
+ }, ],
194
+ }
195
+ ],
196
+ [
197
+ '🕯️ *bold* https://google.com',
198
+ {
199
+ txt: '🕯️ bold https://google.com',
200
+ fmt: [{
201
+ at: 2,
202
+ len: 4,
203
+ tp: 'ST',
204
+ },
205
+ {
206
+ at: 7,
207
+ key: 0,
208
+ len: 18,
209
+ },
210
+ ],
211
+ ent: [{
212
+ tp: 'LN',
213
+ data: {
214
+ url: 'https://google.com',
215
+ },
216
+ }, ]
217
+ }
218
+ ],
219
+ [
220
+ 'Hi 👋🏼 Visit http://localhost:6060\n*New* *line*🫡 Visit http://localhost:8080',
221
+ {
222
+ txt: 'Hi 👋🏼 Visit http://localhost:6060 New line🫡 Visit http://localhost:8080',
223
+ fmt: [{
224
+ at: 11,
225
+ len: 21,
226
+ key: 0,
227
+ },
228
+ {
229
+ at: 32,
230
+ len: 1,
231
+ tp: 'BR',
232
+ },
233
+ {
234
+ at: 33,
235
+ len: 3,
236
+ tp: 'ST',
237
+ },
238
+ {
239
+ at: 37,
240
+ len: 4,
241
+ tp: 'ST',
242
+ },
243
+ {
244
+ at: 49,
245
+ len: 21,
246
+ key: 1,
247
+ },
248
+ ],
249
+ ent: [{
250
+ tp: 'LN',
251
+ data: {
252
+ url: 'http://localhost:6060',
253
+ },
254
+ },
255
+ {
256
+ tp: 'LN',
257
+ data: {
258
+ url: 'http://localhost:8080',
259
+ },
260
+ },
261
+ ],
262
+ },
263
+ ],
264
+ [
265
+ '🔴Hello🔴\n🟠Hello🟠\n🟡Hello🟡',
266
+ {
267
+ "txt": "🔴Hello🔴 🟠Hello🟠 🟡Hello🟡",
268
+ "fmt": [{
269
+ "tp": "BR",
270
+ "at": 7,
271
+ "len": 1
272
+ }, {
273
+ "tp": "BR",
274
+ "at": 15,
275
+ "len": 1
276
+ }, ],
277
+ }
278
+ ]
279
+ ];
280
+
281
+ test.each(parse_this)('Drafty.parse %s', (src, exp) => {
282
+ expect(Drafty.parse(src)).toEqual(exp);
283
+ });
284
+
285
+ // Drafty docs for testing Drafty.preview and Drafty.normalize.
286
+ const shorten_this = [
287
+ [
288
+ "This is a plain text string.",
289
+ {
290
+ "txt": "This is a plai…"
291
+ },
292
+ ],
293
+ [{
294
+ "txt": "This is a string.", // Maybe remove extra space.
295
+ "fmt": [{
296
+ "at": 9,
297
+ "tp": "BR"
298
+ }]
299
+ },
300
+ {
301
+ "txt": "This is a stri…",
302
+ "fmt": [{
303
+ "at": 9,
304
+ len: 0,
305
+ "tp": "BR"
306
+ }]
307
+ },
308
+ ],
309
+ [{
310
+ "txt": "This is a string.",
311
+ "fmt": [{
312
+ "at": true,
313
+ "tp": "XX",
314
+ "len": {}
315
+ }]
316
+ },
317
+ {
318
+ "txt": "This is a stri…"
319
+ },
320
+ ],
321
+ [{
322
+ "txt": "This is a string.",
323
+ "fmt": [{
324
+ "at": {},
325
+ "tp": 123,
326
+ "len": null
327
+ }]
328
+ },
329
+ {
330
+ "txt": "This is a stri…"
331
+ },
332
+ ],
333
+ [{
334
+ "txt": "This is a string.",
335
+ "fmt": [{
336
+ "test": 123
337
+ }, {
338
+ "at": NaN,
339
+ "tp": 123,
340
+ "len": -12
341
+ }]
342
+ },
343
+ {
344
+ "txt": "This is a stri…"
345
+ },
346
+ ],
347
+ [{
348
+ "fmt": [{
349
+ "at": -1
350
+ }],
351
+ "ent": [{
352
+ "data": {
353
+ "mime": "image/jpeg",
354
+ "name": "hello.jpg",
355
+ "val": "<38992, bytes: 123456789012345678901234567890123456789012345678901234567890>",
356
+ "width": 100,
357
+ "height": 80
358
+ },
359
+ "tp": "EX"
360
+ }]
361
+ },
362
+ {
363
+ "txt": "",
364
+ "fmt": [{
365
+ "at": -1,
366
+ "key": 0,
367
+ "len": 0
368
+ }],
369
+ "ent": [{
370
+ "tp": "EX",
371
+ "data": {
372
+ "height": 80,
373
+ "mime": "image/jpeg",
374
+ "name": "hello.jpg",
375
+ "width": 100
376
+ }
377
+ }]
378
+ },
379
+ ],
380
+ [{
381
+ "fmt": [{
382
+ "at": -100,
383
+ "len": 99
384
+ }],
385
+ "ent": [{
386
+ "data": {
387
+ "mime": "image/jpeg",
388
+ "name": "hello.jpg",
389
+ "val": "<38992, bytes: 123456789012345678901234567890123456789012345678901234567890>",
390
+ "width": 100,
391
+ "height": 80
392
+ },
393
+ "tp": "EX"
394
+ }]
395
+ },
396
+ {
397
+ "txt": "",
398
+ "fmt": [{
399
+ "at": -1,
400
+ "key": 0,
401
+ "len": 0
402
+ }],
403
+ "ent": [{
404
+ "tp": "EX",
405
+ "data": {
406
+ "height": 80,
407
+ "mime": "image/jpeg",
408
+ "name": "hello.jpg",
409
+ "width": 100
410
+ }
411
+ }]
412
+ },
413
+ ],
414
+ [{
415
+ "fmt": [{
416
+ "at": -1,
417
+ "key": "fake"
418
+ }],
419
+ "ent": [{
420
+ "data": {
421
+ "width": 100
422
+ },
423
+ "tp": "EX"
424
+ }]
425
+ },
426
+ {
427
+ "txt": ""
428
+ },
429
+ ],
430
+ [{
431
+ "txt": "Message with attachment",
432
+ "fmt": [{
433
+ "at": -1,
434
+ "len": 0,
435
+ "key": 0
436
+ }, {
437
+ "at": 8,
438
+ "len": 4,
439
+ "tp": "ST"
440
+ }],
441
+ "ent": [{
442
+ "data": {
443
+ "mime": "image/jpeg",
444
+ "name": "hello.jpg",
445
+ "val": "<38992, bytes: 123456789012345678901234567890123456789012345678901234567890>",
446
+ "width": 100,
447
+ "height": 80
448
+ },
449
+ "tp": "EX"
450
+ }]
451
+ },
452
+ {
453
+ "txt": "Message with a…",
454
+ "fmt": [{
455
+ "at": 8,
456
+ "len": 4,
457
+ "tp": "ST"
458
+ }, {
459
+ "at": -1,
460
+ "len": 0,
461
+ "key": 0
462
+ }],
463
+ "ent": [{
464
+ "tp": "EX",
465
+ "data": {
466
+ "height": 80,
467
+ "mime": "image/jpeg",
468
+ "name": "hello.jpg",
469
+ "width": 100
470
+ }
471
+ }]
472
+ },
473
+ ],
474
+ [{
475
+ "txt": "https://api.tinode.co/",
476
+ "fmt": [{
477
+ "len": 22
478
+ }],
479
+ "ent": [{
480
+ "data": {
481
+ "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
482
+ },
483
+ "tp": "LN"
484
+ }]
485
+ },
486
+ {
487
+ "txt": "https://api.ti…",
488
+ "fmt": [{
489
+ "at": 0,
490
+ "len": 15,
491
+ "key": 0
492
+ }],
493
+ "ent": [{
494
+ "tp": "LN",
495
+ "data": {
496
+ "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
497
+ }
498
+ }]
499
+ },
500
+ ],
501
+ [{
502
+ "txt": "https://api.tinode.co/",
503
+ "fmt": [{
504
+ "len": 22
505
+ }],
506
+ "ent": [{
507
+ "data": {
508
+ "url": "https://api.tinode.co/"
509
+ },
510
+ "tp": "LN"
511
+ }]
512
+ },
513
+ {
514
+ "txt": "https://api.ti…",
515
+ "fmt": [{
516
+ "at": 0,
517
+ "len": 15,
518
+ "key": 0
519
+ }],
520
+ "ent": [{
521
+ "tp": "LN",
522
+ "data": {
523
+ "url": "https://api.tinode.co/"
524
+ }
525
+ }]
526
+ },
527
+ ],
528
+ [{
529
+ "txt": "Url one, two",
530
+ "fmt": [{
531
+ "at": 9,
532
+ "len": 3
533
+ }, {
534
+ "at": 4,
535
+ "len": 3
536
+ }],
537
+ "ent": [{
538
+ "data": {
539
+ "url": "http://tinode.co"
540
+ },
541
+ "tp": "LN"
542
+ }]
543
+ },
544
+ {
545
+ "txt": "Url one, two",
546
+ "fmt": [{
547
+ "at": 4,
548
+ "len": 3,
549
+ "key": 0
550
+ }, {
551
+ "at": 9,
552
+ "len": 3,
553
+ "key": 0
554
+ }],
555
+ "ent": [{
556
+ "tp": "LN",
557
+ "data": {
558
+ "url": "http://tinode.co"
559
+ }
560
+ }]
561
+ },
562
+ ],
563
+ [{
564
+ "txt": "Url one, two",
565
+ "fmt": [{
566
+ "at": 9,
567
+ "len": 3,
568
+ "key": 0
569
+ }, {
570
+ "at": 4,
571
+ "len": 3,
572
+ "key": 1
573
+ }],
574
+ "ent": [{
575
+ "data": {
576
+ "url": "http://tinode.co"
577
+ },
578
+ "tp": "LN"
579
+ }, {
580
+ "data": {
581
+ "url": "http://example.com"
582
+ },
583
+ "tp": "LN"
584
+ }]
585
+ },
586
+ {
587
+ "txt": "Url one, two",
588
+ "fmt": [{
589
+ "at": 4,
590
+ "len": 3,
591
+ "key": 0
592
+ }, {
593
+ "at": 9,
594
+ "len": 3,
595
+ "key": 1
596
+ }],
597
+ "ent": [{
598
+ "data": {
599
+ "url": "http://example.com"
600
+ },
601
+ "tp": "LN"
602
+ }, {
603
+ "data": {
604
+ "url": "http://tinode.co"
605
+ },
606
+ "tp": "LN"
607
+ }]
608
+ },
609
+ ],
610
+ [{
611
+ "txt": " ",
612
+ "fmt": [{
613
+ "len": 1
614
+ }],
615
+ "ent": [{
616
+ "data": {
617
+ "height": 213,
618
+ "mime": "image/jpeg",
619
+ "name": "roses.jpg",
620
+ "val": "<38992, bytes: 123456789012345678901234567890123456789012345678901234567890>",
621
+ "width": 638
622
+ },
623
+ "tp": "IM"
624
+ }]
625
+ },
626
+ {
627
+ "txt": " ",
628
+ "fmt": [{
629
+ "at": 0,
630
+ "len": 1,
631
+ "key": 0
632
+ }],
633
+ "ent": [{
634
+ "tp": "IM",
635
+ "data": {
636
+ "height": 213,
637
+ "mime": "image/jpeg",
638
+ "name": "roses.jpg",
639
+ "width": 638
640
+ }
641
+ }]
642
+ },
643
+ ],
644
+ [{
645
+ "txt": "This text has staggered formats",
646
+ "fmt": [{
647
+ "at": 5,
648
+ "len": 8,
649
+ "tp": "EM"
650
+ }, {
651
+ "at": 10,
652
+ "len": 13,
653
+ "tp": "ST"
654
+ }]
655
+ },
656
+ {
657
+ "txt": "This text has …",
658
+ "fmt": [{
659
+ "tp": "EM",
660
+ "at": 5,
661
+ "len": 8
662
+ }]
663
+ },
664
+ ],
665
+ [{
666
+ "txt": "This text is formatted and deleted too",
667
+ "fmt": [{
668
+ "at": 5,
669
+ "len": 4,
670
+ "tp": "ST"
671
+ }, {
672
+ "at": 13,
673
+ "len": 9,
674
+ "tp": "EM"
675
+ }, {
676
+ "at": 35,
677
+ "len": 3,
678
+ "tp": "ST"
679
+ }, {
680
+ "at": 27,
681
+ "len": 11,
682
+ "tp": "DL"
683
+ }]
684
+ },
685
+ {
686
+ "txt": "This text is f…",
687
+ "fmt": [{
688
+ "tp": "ST",
689
+ "at": 5,
690
+ "len": 4
691
+ }, {
692
+ "tp": "EM",
693
+ "at": 13,
694
+ "len": 2
695
+ }]
696
+ },
697
+ ],
698
+ [{
699
+ "txt": "мультибайтовый юникод",
700
+ "fmt": [{
701
+ "len": 14,
702
+ "tp": "ST"
703
+ }, {
704
+ "at": 15,
705
+ "len": 6,
706
+ "tp": "EM"
707
+ }]
708
+ },
709
+ {
710
+ "txt": "мультибайтовый…",
711
+ "fmt": [{
712
+ "at": 0,
713
+ "tp": "ST",
714
+ "len": 14
715
+ }]
716
+ },
717
+ ],
718
+ [{
719
+ "txt": "Alice Johnson This is a test",
720
+ "fmt": [{
721
+ "at": 13,
722
+ "len": 1,
723
+ "tp": "BR"
724
+ }, {
725
+ "at": 15,
726
+ "len": 1
727
+ }, {
728
+ "len": 13,
729
+ "key": 1
730
+ }, {
731
+ "len": 16,
732
+ "tp": "QQ"
733
+ }, {
734
+ "at": 16,
735
+ "len": 1,
736
+ "tp": "BR"
737
+ }],
738
+ "ent": [{
739
+ "tp": "IM",
740
+ "data": {
741
+ "mime": "image/jpeg",
742
+ "val": "<1292, bytes: /9j/4AAQSkZJ123456789012345678901234567890123456789012345678901234567890rehH5o6D/9k=>",
743
+ "width": 25,
744
+ "height": 14,
745
+ "size": 968
746
+ }
747
+ }, {
748
+ "tp": "MN",
749
+ "data": {
750
+ "val": "usr123abcDE"
751
+ }
752
+ }]
753
+ },
754
+ {
755
+ "txt": "Alice Johnson …",
756
+ "fmt": [{
757
+ "at": 0,
758
+ "len": 13,
759
+ "key": 0
760
+ }, {
761
+ "at": 13,
762
+ "len": 1,
763
+ "tp": "BR"
764
+ }, {
765
+ "at": 0,
766
+ "len": 15,
767
+ "tp": "QQ"
768
+ }],
769
+ "ent": [{
770
+ "tp": "MN",
771
+ "data": {
772
+ "val": "usr123abcDE"
773
+ }
774
+ }, ]
775
+ },
776
+ ],
777
+ [{
778
+ "txt": "a😀c😀d😀e😀f😀g😀h😀i😀j😀k😀l😀m"
779
+ },
780
+ {
781
+ "txt": "a😀c😀d😀e😀f😀g😀h😀…",
782
+ }
783
+ ],
784
+ [{
785
+ "txt": "😀 b1👩🏽‍✈️b2 smile 123 123 123 123",
786
+ "fmt": [{
787
+ "tp": "ST",
788
+ "at": 2,
789
+ "len": 8
790
+ }, {
791
+ "tp": "EM",
792
+ "at": 0,
793
+ "len": 20
794
+ }]
795
+ },
796
+ {
797
+ "txt": "😀 b1👩🏽‍✈️b2 smile …",
798
+ "fmt": [{
799
+ "tp": "ST",
800
+ "at": 2,
801
+ "len": 8
802
+ }, {
803
+ "tp": "EM",
804
+ "at": 0,
805
+ "len": 15
806
+ }]
807
+ },
808
+ ]
809
+ ];
810
+
811
+ test.each(shorten_this)('Drafty.shorten %j', (src, exp) => {
812
+ expect(Drafty.shorten(src, 15, true)).toEqual(exp);
813
+ });
814
+
815
+ // Drafty docs for testing Drafty.forwardedContent.
816
+ const forward_this = [
817
+ [{
818
+ "txt": " ",
819
+ "fmt": [{
820
+ "len": 1
821
+ }],
822
+ "ent": [{
823
+ "data": {
824
+ "height": 213,
825
+ "mime": "image/jpeg",
826
+ "name": "roses.jpg",
827
+ "val": "<38992, bytes: 123456789012345678901234567890123456789012345678901234567890>",
828
+ "width": 638
829
+ },
830
+ "tp": "IM"
831
+ }]
832
+ },
833
+ {
834
+ "txt": " ",
835
+ "fmt": [{
836
+ "at": 0,
837
+ "len": 1,
838
+ "key": 0
839
+ }],
840
+ "ent": [{
841
+ "tp": "IM",
842
+ "data": {
843
+ "height": 213,
844
+ "mime": "image/jpeg",
845
+ "name": "roses.jpg",
846
+ "val": "<38992, bytes: 123456789012345678901234567890123456789012345678901234567890>",
847
+ "width": 638
848
+ }
849
+ }]
850
+ },
851
+ ],
852
+ [{
853
+ "ent": [{
854
+ "data": {
855
+ "val": "usrCPvFc6lpAsw"
856
+ },
857
+ "tp": "MN"
858
+ }],
859
+ "fmt": [{
860
+ "len": 13
861
+ }, {
862
+ "at": 13,
863
+ "len": 1,
864
+ "tp": "BR"
865
+ }, {
866
+ "len": 38,
867
+ "tp": "QQ"
868
+ }],
869
+ "txt": "Alice Johnson This is a reply to replyThis is a Reply -> Forward -> Reply."
870
+ },
871
+ {
872
+ "ent": [{
873
+ "data": {
874
+ "val": "usrCPvFc6lpAsw"
875
+ },
876
+ "tp": "MN"
877
+ }],
878
+ "fmt": [{
879
+ "at": 0,
880
+ "len": 13,
881
+ "key": 0
882
+ }, {
883
+ "at": 13,
884
+ "len": 1,
885
+ "tp": "BR"
886
+ }, {
887
+ "at": 0,
888
+ "len": 38,
889
+ "tp": "QQ"
890
+ }],
891
+ "txt": "Alice Johnson This is a reply to replyThis is a Reply -> Forward -> Reply."
892
+ },
893
+ ],
894
+ [{
895
+ "ent": [{
896
+ "data": {
897
+ "val": "usrCPvFc6lpAsw"
898
+ },
899
+ "tp": "MN"
900
+ }, {
901
+ "data": {
902
+ "val": "usrCPvFc6lpAsw"
903
+ },
904
+ "tp": "MN"
905
+ }],
906
+ "fmt": [{
907
+ "len": 15
908
+ }, {
909
+ "at": 15,
910
+ "len": 1,
911
+ "tp": "BR"
912
+ }, {
913
+ "at": 16,
914
+ "key": 1,
915
+ "len": 13
916
+ }, {
917
+ "at": 29,
918
+ "len": 1,
919
+ "tp": "BR"
920
+ }, {
921
+ "at": 16,
922
+ "len": 36,
923
+ "tp": "QQ"
924
+ }],
925
+ "txt": "➦ Alice Johnson Alice Johnson This is a simple replyThis is a reply to reply"
926
+ },
927
+ {
928
+ "ent": [{
929
+ "data": {
930
+ "val": "usrCPvFc6lpAsw"
931
+ },
932
+ "tp": "MN"
933
+ }],
934
+ "fmt": [{
935
+ "at": 0,
936
+ "key": 0,
937
+ "len": 13
938
+ }, {
939
+ "at": 13,
940
+ "len": 1,
941
+ "tp": "BR"
942
+ }, {
943
+ "at": 0,
944
+ "len": 36,
945
+ "tp": "QQ"
946
+ }],
947
+ "txt": "Alice Johnson This is a simple replyThis is a reply to reply"
948
+ }
949
+ ],
950
+ [{
951
+ "txt": "➦ tinodeu 🔴Hello🔴 🟠Hello🟠 🟡Hello🟡 🟢Hello🟢",
952
+ "fmt": [{
953
+ "len": 9
954
+ },
955
+ {
956
+ "at": 9,
957
+ "len": 1,
958
+ "tp": "BR"
959
+ },
960
+ {
961
+ "at": 19,
962
+ "len": 1,
963
+ "tp": "BR"
964
+ },
965
+ {
966
+ "at": 29,
967
+ "len": 1,
968
+ "tp": "BR"
969
+ },
970
+ {
971
+ "at": 39,
972
+ "len": 1,
973
+ "tp": "BR"
974
+ }
975
+ ],
976
+ "ent": [{
977
+ "tp": "MN",
978
+ "data": {
979
+ "val": "usrfv76ZZoJQJc"
980
+ }
981
+ }]
982
+ },
983
+ {
984
+ "txt": "🔴Hello🔴 🟠Hello🟠 🟡Hello🟡 🟢Hello🟢",
985
+ "fmt": [{
986
+ "tp": "BR",
987
+ "at": 9,
988
+ "len": 1
989
+ },
990
+ {
991
+ "tp": "BR",
992
+ "at": 19,
993
+ "len": 1
994
+ },
995
+ {
996
+ "tp": "BR",
997
+ "at": 29,
998
+ "len": 1
999
+ }
1000
+ ]
1001
+ }
1002
+ ]
1003
+ ];
1004
+
1005
+ test.each(forward_this)('Drafty.forwardedContent %j', (src, exp) => {
1006
+ expect(Drafty.forwardedContent(src)).toEqual(exp);
1007
+ });
1008
+
1009
+ // Drafty docs for testing Drafty.preview.
1010
+ const preview_this = [
1011
+ [{
1012
+ "ent": [{
1013
+ "data": {
1014
+ "val": "usrCPvFc6lpAsw"
1015
+ },
1016
+ "tp": "MN"
1017
+ }],
1018
+ "fmt": [{
1019
+ "len": 13
1020
+ }, {
1021
+ "at": 13,
1022
+ "len": 1,
1023
+ "tp": "BR"
1024
+ }, {
1025
+ "len": 38,
1026
+ "tp": "QQ"
1027
+ }],
1028
+ "txt": "Alice Johnson This is a reply to replyThis is a Reply -> Forward -> Reply."
1029
+ },
1030
+ {
1031
+ "fmt": [{
1032
+ "at": 0,
1033
+ "len": 1,
1034
+ "tp": "QQ"
1035
+ }],
1036
+ "txt": " This is a Reply -> Forw…"
1037
+ },
1038
+ ],
1039
+ [{
1040
+ "ent": [{
1041
+ "data": {
1042
+ "val": "usrCPvFc6lpAsw"
1043
+ },
1044
+ "tp": "MN"
1045
+ }, {
1046
+ "data": {
1047
+ "val": "usrCPvFc6lpAsw"
1048
+ },
1049
+ "tp": "MN"
1050
+ }],
1051
+ "fmt": [{
1052
+ "len": 15
1053
+ }, {
1054
+ "at": 15,
1055
+ "len": 1,
1056
+ "tp": "BR"
1057
+ }, {
1058
+ "at": 16,
1059
+ "key": 1,
1060
+ "len": 13
1061
+ }, {
1062
+ "at": 29,
1063
+ "len": 1,
1064
+ "tp": "BR"
1065
+ }, {
1066
+ "at": 16,
1067
+ "len": 36,
1068
+ "tp": "QQ"
1069
+ }],
1070
+ "txt": "➦ Alice Johnson Alice Johnson This is a simple replyThis is a reply to reply"
1071
+ },
1072
+ {
1073
+ "ent": [{
1074
+ "data": {
1075
+ "val": "usrCPvFc6lpAsw"
1076
+ },
1077
+ "tp": "MN"
1078
+ }],
1079
+ "fmt": [{
1080
+ "at": 0,
1081
+ "key": 0,
1082
+ "len": 1
1083
+ }, {
1084
+ "at": 2,
1085
+ "len": 1,
1086
+ "tp": "QQ"
1087
+ }],
1088
+ "txt": "➦ This is a reply to re…"
1089
+ }
1090
+ ],
1091
+ [{
1092
+ "txt": 'Hi 👋🏼 Visit http://localhost:6060 New line🫡 Visit http://localhost:8080',
1093
+ "fmt": [{
1094
+ "at": 11,
1095
+ "len": 21,
1096
+ "key": 0,
1097
+ },
1098
+ {
1099
+ "at": 32,
1100
+ "len": 1,
1101
+ "tp": 'BR',
1102
+ },
1103
+ {
1104
+ "at": 33,
1105
+ "len": 3,
1106
+ "tp": 'ST',
1107
+ },
1108
+ {
1109
+ "at": 37,
1110
+ "len": 4,
1111
+ "tp": 'ST',
1112
+ },
1113
+ {
1114
+ "at": 49,
1115
+ "len": 21,
1116
+ "key": 1,
1117
+ },
1118
+ ],
1119
+ "ent": [{
1120
+ "tp": 'LN',
1121
+ "data": {
1122
+ "url": 'http://localhost:6060',
1123
+ },
1124
+ },
1125
+ {
1126
+ "tp": 'LN',
1127
+ "data": {
1128
+ "url": 'http://localhost:8080',
1129
+ },
1130
+ },
1131
+ ],
1132
+ },
1133
+ {
1134
+ "txt": "Hi 👋🏼 Visit http://localh…",
1135
+ "fmt": [{
1136
+ "at": 11,
1137
+ "len": 14,
1138
+ "key": 0
1139
+ }],
1140
+ "ent": [{
1141
+ "tp": "LN",
1142
+ "data": {
1143
+ "url": "http://localhost:6060"
1144
+ }
1145
+ }]
1146
+ }
1147
+ ]
1148
+ ];
1149
+
1150
+ test.each(preview_this)('Drafty.preview %j', (src, exp) => {
1151
+ expect(Drafty.preview(src, 25)).toEqual(exp);
1152
+ });
1153
+
1154
+ // Drafty docs for testing Drafty.replyContent.
1155
+ const reply_this = [
1156
+ [{
1157
+ "ent": [{
1158
+ "data": {
1159
+ "val": "usrCPvFc6lpAsw"
1160
+ },
1161
+ "tp": "MN"
1162
+ }],
1163
+ "fmt": [{
1164
+ "len": 13
1165
+ }, {
1166
+ "at": 13,
1167
+ "len": 1,
1168
+ "tp": "BR"
1169
+ }, {
1170
+ "len": 38,
1171
+ "tp": "QQ"
1172
+ }],
1173
+ "txt": "Alice Johnson This is a reply to replyThis is a Reply -> Forward -> Reply."
1174
+ },
1175
+ {
1176
+ "txt": "This is a Reply -> Forwa…"
1177
+ },
1178
+ ],
1179
+ [{
1180
+ "ent": [{
1181
+ "data": {
1182
+ "val": "usrCPvFc6lpAsw"
1183
+ },
1184
+ "tp": "MN"
1185
+ }, {
1186
+ "data": {
1187
+ "val": "usrCPvFc6lpAsw"
1188
+ },
1189
+ "tp": "MN"
1190
+ }],
1191
+ "fmt": [{
1192
+ "len": 15
1193
+ }, {
1194
+ "at": 15,
1195
+ "len": 1,
1196
+ "tp": "BR"
1197
+ }, {
1198
+ "at": 16,
1199
+ "key": 1,
1200
+ "len": 13
1201
+ }, {
1202
+ "at": 29,
1203
+ "len": 1,
1204
+ "tp": "BR"
1205
+ }, {
1206
+ "at": 16,
1207
+ "len": 36,
1208
+ "tp": "QQ"
1209
+ }],
1210
+ "txt": "➦ Alice Johnson Alice Johnson This is a simple replyThis is a reply to reply"
1211
+ },
1212
+ {
1213
+ "fmt": [{
1214
+ "at": 0,
1215
+ "tp": "MN",
1216
+ "len": 1
1217
+ }],
1218
+ "txt": "➦ This is a reply to rep…"
1219
+ }
1220
+ ],
1221
+ [{
1222
+ "txt": "Message with attachment",
1223
+ "fmt": [{
1224
+ "at": -1,
1225
+ "len": 0,
1226
+ "key": 0
1227
+ }, {
1228
+ "at": 8,
1229
+ "len": 4,
1230
+ "tp": "ST"
1231
+ }],
1232
+ "ent": [{
1233
+ "data": {
1234
+ "mime": "image/jpeg",
1235
+ "name": "hello.jpg",
1236
+ "val": "<38992, bytes: 123456789012345678901234567890123456789012345678901234567890>",
1237
+ "width": 100,
1238
+ "height": 80
1239
+ },
1240
+ "tp": "EX"
1241
+ }]
1242
+ },
1243
+ {
1244
+ "txt": "Message with attachment ",
1245
+ "fmt": [{
1246
+ "at": 8,
1247
+ "len": 4,
1248
+ "tp": "ST"
1249
+ }, {
1250
+ "at": 23,
1251
+ "len": 1,
1252
+ "key": 0
1253
+ }],
1254
+ "ent": [{
1255
+ "data": {
1256
+ "mime": "image/jpeg",
1257
+ "name": "hello.jpg",
1258
+ "width": 100,
1259
+ "height": 80
1260
+ },
1261
+ "tp": "EX"
1262
+ }]
1263
+ }
1264
+ ],
1265
+ [{
1266
+ "fmt": [{
1267
+ "at": -1
1268
+ }],
1269
+ "ent": [{
1270
+ "data": {
1271
+ "mime": "image/jpeg",
1272
+ "name": "hello.jpg",
1273
+ "val": "<38992, bytes: 123456789012345678901234567890123456789012345678901234567890>",
1274
+ "width": 100,
1275
+ "height": 80
1276
+ },
1277
+ "tp": "EX"
1278
+ }]
1279
+ },
1280
+ {
1281
+ "txt": " ",
1282
+ "fmt": [{
1283
+ "at": 0,
1284
+ "key": 0,
1285
+ "len": 1
1286
+ }],
1287
+ "ent": [{
1288
+ "tp": "EX",
1289
+ "data": {
1290
+ "height": 80,
1291
+ "mime": "image/jpeg",
1292
+ "name": "hello.jpg",
1293
+ "width": 100
1294
+ }
1295
+ }]
1296
+ },
1297
+ ],
1298
+ [{
1299
+ "txt": " ",
1300
+ "fmt": [{
1301
+ "len": 1
1302
+ }],
1303
+ "ent": [{
1304
+ "data": {
1305
+ "height": 213,
1306
+ "mime": "image/jpeg",
1307
+ "name": "roses.jpg",
1308
+ "val": "<38992, bytes: 123456789012345678901234567890123456789012345678901234567890>",
1309
+ "width": 638
1310
+ },
1311
+ "tp": "IM"
1312
+ }]
1313
+ },
1314
+ {
1315
+ "txt": " ",
1316
+ "fmt": [{
1317
+ "at": 0,
1318
+ "len": 1,
1319
+ "key": 0
1320
+ }],
1321
+ "ent": [{
1322
+ "tp": "IM",
1323
+ "data": {
1324
+ "height": 213,
1325
+ "mime": "image/jpeg",
1326
+ "name": "roses.jpg",
1327
+ "val": "<38992, bytes: 123456789012345678901234567890123456789012345678901234567890>",
1328
+ "width": 638
1329
+ }
1330
+ }]
1331
+ },
1332
+ ],
1333
+ ];
1334
+
1335
+ test.each(reply_this)('Drafty.replyContent %j', (src, exp) => {
1336
+ expect(Drafty.replyContent(src, 25)).toEqual(exp);
1337
+ });
1338
+
1339
+ // Drafty docs for testing Drafty.UNSAFE_toHTML and Drafty.toMarkdown.
1340
+ const html_this = [
1341
+ [{
1342
+ "ent": [{
1343
+ "data": {
1344
+ "val": "usrCPvFc6lpAsw"
1345
+ },
1346
+ "tp": "MN"
1347
+ }],
1348
+ "fmt": [{
1349
+ "len": 13
1350
+ }, {
1351
+ "at": 13,
1352
+ "len": 1,
1353
+ "tp": "BR"
1354
+ }, {
1355
+ "len": 38,
1356
+ "tp": "QQ"
1357
+ }],
1358
+ "txt": "Alice Johnson This is a reply to replyThis is a Reply -> Forward -> Reply."
1359
+ },
1360
+ "<div><a href=\"#usrCPvFc6lpAsw\">Alice Johnson</a><br/> This is a reply to reply</div>This is a Reply -> Forward -> Reply.",
1361
+ ],
1362
+ [{
1363
+ "ent": [{
1364
+ "data": {
1365
+ "val": "usrCPvFc6lpAsw"
1366
+ },
1367
+ "tp": "MN"
1368
+ }, {
1369
+ "data": {
1370
+ "val": "usrCPvFc6lpAsw"
1371
+ },
1372
+ "tp": "MN"
1373
+ }],
1374
+ "fmt": [{
1375
+ "len": 15
1376
+ }, {
1377
+ "at": 15,
1378
+ "len": 1,
1379
+ "tp": "BR"
1380
+ }, {
1381
+ "at": 16,
1382
+ "key": 1,
1383
+ "len": 13
1384
+ }, {
1385
+ "at": 29,
1386
+ "len": 1,
1387
+ "tp": "BR"
1388
+ }, {
1389
+ "at": 16,
1390
+ "len": 36,
1391
+ "tp": "QQ"
1392
+ }],
1393
+ "txt": "➦ Alice Johnson Alice Johnson This is a simple replyThis is a reply to reply"
1394
+ },
1395
+ "<a href=\"#usrCPvFc6lpAsw\">➦ Alice Johnson</a><br/> <div><a href=\"#usrCPvFc6lpAsw\">Alice Johnson</a><br/> This is a simple reply</div>This is a reply to reply"
1396
+ ],
1397
+ // Simple formatting.
1398
+ [{
1399
+ "txt": "Hello bold world",
1400
+ "fmt": [{
1401
+ "at": 6,
1402
+ "len": 4,
1403
+ "tp": "ST"
1404
+ }]
1405
+ },
1406
+ "Hello <b>bold</b> world"
1407
+ ],
1408
+ // Link with a javascript: URL. This demonstrates UNSAFE behavior.
1409
+ [{
1410
+ "txt": "Click me for a surprise!",
1411
+ "fmt": [{
1412
+ "at": 0,
1413
+ "len": 23,
1414
+ "key": 0
1415
+ }],
1416
+ "ent": [{
1417
+ "tp": "LN",
1418
+ "data": {
1419
+ "url": "javascript:alert('XSS')"
1420
+ }
1421
+ }]
1422
+ },
1423
+ "<a href=\"javascript:alert('XSS')\">Click me for a surprise</a>!"
1424
+ ],
1425
+ // Text containing unescaped HTML. This also demonstrates UNSAFE behavior.
1426
+ [{
1427
+ "txt": "Here is an image <img src=x onerror=alert('XSS')>",
1428
+ },
1429
+ "Here is an image <img src=x onerror=alert('XSS')>"
1430
+ ],
1431
+ ];
1432
+
1433
+ test.each(html_this)('Drafty.UNSAFE_toHTML %j', (src, exp) => {
1434
+ expect(Drafty.UNSAFE_toHTML(src)).toEqual(exp);
1435
+ });
1436
+
1437
+ // Drafty docs for testing Drafty.toMarkdown.
1438
+ const md_this = [
1439
+
1440
+ [{
1441
+ "fmt": [{
1442
+ "at": 8,
1443
+ "len": 4,
1444
+ "tp": "ST"
1445
+ }, {
1446
+ "at": 14,
1447
+ "len": 4,
1448
+ "tp": "CO"
1449
+ }, {
1450
+ "at": 23,
1451
+ "len": 6,
1452
+ "tp": "EM"
1453
+ }, {
1454
+ "at": 31,
1455
+ "len": 6,
1456
+ "tp": "DL"
1457
+ }],
1458
+ "txt": "This is bold, code and italic, strike"
1459
+ },
1460
+ 'This is *bold*, `code` and _italic_, ~strike~'
1461
+ ],
1462
+ [{
1463
+ "fmt": [{
1464
+ "at": 14,
1465
+ "len": 0,
1466
+ "tp": "BR"
1467
+ }, {
1468
+ "at": 23,
1469
+ "len": 15,
1470
+ "tp": "ST"
1471
+ }, {
1472
+ "at": 32,
1473
+ "len": 6,
1474
+ "tp": "EM"
1475
+ }],
1476
+ "txt": "two lines withcombined bold and italic"
1477
+ },
1478
+ "two lines with\ncombined *bold and _italic_*",
1479
+ ],
1480
+ [{
1481
+ "ent": [{
1482
+ "data": {
1483
+ "val": "mention"
1484
+ },
1485
+ "tp": "MN"
1486
+ },
1487
+ {
1488
+ "data": {
1489
+ "val": "hashtag"
1490
+ },
1491
+ "tp": "HT"
1492
+ },
1493
+ ],
1494
+ "fmt": [{
1495
+ "at": 10,
1496
+ "key": 0,
1497
+ "len": 8
1498
+ },
1499
+ {
1500
+ "at": 25,
1501
+ "key": 1,
1502
+ "len": 8
1503
+ },
1504
+ ],
1505
+ "txt": "this is a @mention and a #hashtag in a string"
1506
+ },
1507
+ "this is a @mention and a #hashtag in a string"
1508
+ ],
1509
+ ];
1510
+
1511
+
1512
+ test.each(md_this)('Drafty.toMarkdown %j', (src, exp) => {
1513
+ expect(Drafty.toMarkdown(src)).toEqual(exp);
1514
+ });
1515
+
1516
+ // Test for handling invalid Drafty.
1517
+ const invalid_this = [
1518
+ [{
1519
+ "fmt": [null, {
1520
+ "at": 5,
1521
+ "len": 5,
1522
+ "tp": "EM"
1523
+ }],
1524
+ "txt": "Null style in the middle"
1525
+ },
1526
+ "Null <i>style</i> in the middle",
1527
+ ],
1528
+ [{
1529
+ "ent": [null, {
1530
+ "data": {
1531
+ "val": "usrCPvFc6lpAsw"
1532
+ },
1533
+ "tp": "MN"
1534
+ }],
1535
+ "fmt": [{
1536
+ "len": 4
1537
+ }, {
1538
+ "at": 5,
1539
+ "key": 1,
1540
+ "len": 6
1541
+ }],
1542
+ "txt": "Null entity with reference"
1543
+ },
1544
+ "Null <a href=\"#usrCPvFc6lpAsw\">entity</a> with reference"
1545
+ ],
1546
+ ];
1547
+
1548
+ test.each(invalid_this)('Invalid Drafty %j', (src, exp) => {
1549
+ expect(Drafty.UNSAFE_toHTML(src)).toEqual(exp);
1550
+ });
1551
+
1552
+ const quote_this = [
1553
+ [{
1554
+ "txt": "😀 b1👩🏽‍✈️b2 smile 123 123 123 123",
1555
+ "fmt": [{
1556
+ "tp": "ST",
1557
+ "at": 8,
1558
+ "len": 5
1559
+ },
1560
+ {
1561
+ "tp": "EM",
1562
+ "at": 22,
1563
+ "len": 3
1564
+ }
1565
+ ]
1566
+ }, {
1567
+ "ent": [{
1568
+ "data": {
1569
+ "val": "usrbzV_721mIW0"
1570
+ },
1571
+ "tp": "MN",
1572
+ }, ],
1573
+ "fmt": [{
1574
+ "at": 0,
1575
+ "key": 0,
1576
+ "len": 11,
1577
+ }, {
1578
+ "at": 11,
1579
+ "len": 1,
1580
+ "tp": "BR",
1581
+ }, {
1582
+ "at": 20,
1583
+ "len": 5,
1584
+ "tp": "ST",
1585
+ }, {
1586
+ "at": 34,
1587
+ "len": 3,
1588
+ "tp": "EM",
1589
+ }, {
1590
+ "at": 0,
1591
+ "len": 41,
1592
+ "tp": "QQ"
1593
+ }, ],
1594
+ "txt": "tinode-user 😀 b1👩🏽‍✈️b2 smile 123 123 123 123"
1595
+ }],
1596
+ ]
1597
+
1598
+ test.each(quote_this)('Drafty.quote %j', (src, exp) => {
1599
+ expect(Drafty.quote("tinode-user", "usrbzV_721mIW0", src)).toEqual(exp);
1600
+ })