@@ -5,17 +5,17 @@ import {
5
5
createInstance
6
6
} from '../../helpers/index'
7
7
8
- function compileSnippet ( runtime , snippet ) {
8
+ function compileSnippet ( runtime , snippet , additional ) {
9
9
const { render, staticRenderFns } = compileAndStringify ( `<div>${ snippet } </div>` )
10
10
const instance = createInstance ( runtime , `
11
11
new Vue({
12
+ el: 'body',
12
13
render: ${ render } ,
13
14
staticRenderFns: ${ staticRenderFns } ,
14
- el: 'body'
15
+ ${ additional }
15
16
})
16
17
` )
17
- const result = instance . getRealRoot ( ) . children [ 0 ]
18
- return result
18
+ return instance . getRealRoot ( ) . children [ 0 ]
19
19
}
20
20
21
21
describe ( 'richtext component' , ( ) => {
@@ -57,6 +57,7 @@ describe('richtext component', () => {
57
57
} )
58
58
59
59
describe ( 'span' , ( ) => {
60
+ // pending('work in progress')
60
61
it ( 'single node' , ( ) => {
61
62
expect ( compileSnippet ( runtime , `
62
63
<richtext>
@@ -124,6 +125,7 @@ describe('richtext component', () => {
124
125
} )
125
126
126
127
describe ( 'a' , ( ) => {
128
+ // pending('work in progress')
127
129
it ( 'single node' , ( ) => {
128
130
expect ( compileSnippet ( runtime , `
129
131
<richtext>
@@ -162,6 +164,7 @@ describe('richtext component', () => {
162
164
} )
163
165
164
166
describe ( 'image' , ( ) => {
167
+ // pending('work in progress')
165
168
it ( 'single node' , ( ) => {
166
169
expect ( compileSnippet ( runtime , `
167
170
<richtext>
@@ -220,6 +223,7 @@ describe('richtext component', () => {
220
223
} )
221
224
222
225
describe ( 'nested' , ( ) => {
226
+ // pending('work in progress')
223
227
it ( 'span' , ( ) => {
224
228
expect ( compileSnippet ( runtime , `
225
229
<richtext>
@@ -296,6 +300,7 @@ describe('richtext component', () => {
296
300
describe ( 'with styles' , ( ) => {
297
301
// pending('work in progress')
298
302
it ( 'inline' , ( ) => {
303
+ // pending('work in progress')
299
304
expect ( compileSnippet ( runtime , `
300
305
<richtext>
301
306
<span style="font-size:16px;color:#FF6600;">ABCD</span>
@@ -316,5 +321,290 @@ describe('richtext component', () => {
316
321
}
317
322
} )
318
323
} )
324
+
325
+ it ( 'class list' , ( ) => {
326
+ // pending('work in progress')
327
+ expect ( compileSnippet ( runtime , `
328
+ <richtext>
329
+ <image class="icon" src="path/to/A.png"></image>
330
+ <span class="title large">ABCD</span>
331
+ </richtext>
332
+ ` , `
333
+ style: {
334
+ title: { color: '#FF6600' },
335
+ large: { fontSize: 24 },
336
+ icon: { width: 40, height: 60 }
337
+ }
338
+ ` ) ) . toEqual ( {
339
+ type : 'richtext' ,
340
+ attr : {
341
+ value : [ {
342
+ type : 'image' ,
343
+ style : { width : 40 , height : 60 } ,
344
+ attr : { src : 'path/to/A.png' }
345
+ } , {
346
+ type : 'span' ,
347
+ style : { fontSize : 24 , color : '#FF6600' } ,
348
+ attr : { value : 'ABCD' }
349
+ } ]
350
+ }
351
+ } )
352
+ } )
353
+ } )
354
+
355
+ describe ( 'data binding' , ( ) => {
356
+ // pending('work in progress')
357
+ it ( 'simple' , ( ) => {
358
+ expect ( compileSnippet ( runtime , `
359
+ <richtext>
360
+ <span>{{name}}</span>
361
+ </richtext>
362
+ ` , `data: { name: 'ABCDEFG' }` ) ) . toEqual ( {
363
+ type : 'richtext' ,
364
+ attr : {
365
+ value : [ {
366
+ type : 'span' ,
367
+ attr : { value : 'ABCDEFG' }
368
+ } ]
369
+ }
370
+ } )
371
+ } )
372
+
373
+ it ( 'nested' , ( ) => {
374
+ expect ( compileSnippet ( runtime , `
375
+ <richtext>
376
+ <span>{{a}}</span>
377
+ <span>{{b}}<span>{{c.d}}</span></span>
378
+ <span>{{e}}</span>
379
+ </richtext>
380
+ ` , `data: { a: 'A', b: 'B', c: { d: 'CD' }, e: 'E' }` ) )
381
+ . toEqual ( {
382
+ type : 'richtext' ,
383
+ attr : {
384
+ value : [ {
385
+ type : 'span' ,
386
+ attr : { value : 'A' }
387
+ } , {
388
+ type : 'span' ,
389
+ children : [ {
390
+ type : 'span' ,
391
+ attr : { value : 'B' }
392
+ } , {
393
+ type : 'span' ,
394
+ attr : { value : 'CD' }
395
+ } ]
396
+ } , {
397
+ type : 'span' ,
398
+ attr : { value : 'E' }
399
+ } ]
400
+ }
401
+ } )
402
+ } )
403
+
404
+ it ( 'update' , ( ) => {
405
+ expect ( compileSnippet ( runtime , `
406
+ <richtext>
407
+ <span>{{name}}</span>
408
+ </richtext>
409
+ ` , `
410
+ data: { name: 'default' },
411
+ created: function () {
412
+ this.name = 'updated'
413
+ }
414
+ ` ) ) . toEqual ( {
415
+ type : 'richtext' ,
416
+ attr : {
417
+ value : [ {
418
+ type : 'span' ,
419
+ attr : { value : 'updated' }
420
+ } ]
421
+ }
422
+ } )
423
+ } )
424
+
425
+ it ( 'attribute' , ( ) => {
426
+ expect ( compileSnippet ( runtime , `
427
+ <richtext>
428
+ <span :label="label">{{name}}</span>
429
+ </richtext>
430
+ ` , `
431
+ data: {
432
+ label: 'uid',
433
+ name: '10100'
434
+ }
435
+ ` ) ) . toEqual ( {
436
+ type : 'richtext' ,
437
+ attr : {
438
+ value : [ {
439
+ type : 'span' ,
440
+ attr : {
441
+ label : 'uid' ,
442
+ value : '10100'
443
+ }
444
+ } ]
445
+ }
446
+ } )
447
+ } )
448
+
449
+ it ( 'update attribute' , ( ) => {
450
+ expect ( compileSnippet ( runtime , `
451
+ <richtext>
452
+ <span :label="label">{{name}}</span>
453
+ </richtext>
454
+ ` , `
455
+ data: {
456
+ label: 'name',
457
+ name: 'Hanks'
458
+ },
459
+ created: function () {
460
+ this.label = 'uid';
461
+ this.name = '10100';
462
+ }
463
+ ` ) ) . toEqual ( {
464
+ type : 'richtext' ,
465
+ attr : {
466
+ value : [ {
467
+ type : 'span' ,
468
+ attr : {
469
+ label : 'uid' ,
470
+ value : '10100'
471
+ }
472
+ } ]
473
+ }
474
+ } )
475
+ } )
476
+
477
+ it ( 'inline style' , ( ) => {
478
+ expect ( compileSnippet ( runtime , `
479
+ <richtext>
480
+ <span :style="styleObject">ABCD</span>
481
+ <span :style="{ textAlign: align, color: 'red' }">EFGH</span>
482
+ </richtext>
483
+ ` , `
484
+ data: {
485
+ styleObject: { fontSize: '32px', color: '#F6F660' },
486
+ align: 'center'
487
+ }
488
+ ` ) ) . toEqual ( {
489
+ type : 'richtext' ,
490
+ attr : {
491
+ value : [ {
492
+ type : 'span' ,
493
+ style : { fontSize : 32 , color : '#F6F660' } ,
494
+ attr : { value : 'ABCD' }
495
+ } , {
496
+ type : 'span' ,
497
+ style : { textAlign : 'center' , color : 'red' } ,
498
+ attr : { value : 'EFGH' }
499
+ } ]
500
+ }
501
+ } )
502
+ } )
503
+
504
+ it ( 'class list' , ( ) => {
505
+ // pending('work in progress')
506
+ expect ( compileSnippet ( runtime , `
507
+ <richtext>
508
+ <image :class="classList" src="path/to/A.png"></image>
509
+ <span :class="['title', size]">ABCD</span>
510
+ <span class="large" style="color:#F6F0F4">EFGH</span>
511
+ </richtext>
512
+ ` , `
513
+ style: {
514
+ title: { color: '#FF6600' },
515
+ large: { fontSize: 24 },
516
+ icon: { width: 40, height: 60 }
517
+ },
518
+ data: {
519
+ classList: ['unknown'],
520
+ size: 'small'
521
+ },
522
+ created: function () {
523
+ this.classList = ['icon'];
524
+ this.size = 'large';
525
+ }
526
+ ` ) ) . toEqual ( {
527
+ type : 'richtext' ,
528
+ attr : {
529
+ value : [ {
530
+ type : 'image' ,
531
+ style : { width : 40 , height : 60 } ,
532
+ attr : { src : 'path/to/A.png' }
533
+ } , {
534
+ type : 'span' ,
535
+ style : { fontSize : 24 , color : '#FF6600' } ,
536
+ attr : { value : 'ABCD' }
537
+ } , {
538
+ type : 'span' ,
539
+ style : { fontSize : 24 , color : '#F6F0F4' } ,
540
+ attr : { value : 'EFGH' }
541
+ } ]
542
+ }
543
+ } )
544
+ } )
545
+
546
+ it ( 'update inline style' , ( ) => {
547
+ expect ( compileSnippet ( runtime , `
548
+ <richtext>
549
+ <span :style="styleObject">ABCD</span>
550
+ <span :style="{ textAlign: align, color: 'red' }">EFGH</span>
551
+ </richtext>
552
+ ` , `
553
+ data: {
554
+ styleObject: { fontSize: '32px', color: '#F6F660' }
555
+ },
556
+ created: function () {
557
+ this.styleObject = { fontSize: '24px', color: 'blue' }
558
+ this.styleObject.color = '#ABCDEF'
559
+ this.align = 'left'
560
+ }
561
+ ` ) ) . toEqual ( {
562
+ type : 'richtext' ,
563
+ attr : {
564
+ value : [ {
565
+ type : 'span' ,
566
+ style : { fontSize : 24 , color : '#ABCDEF' } ,
567
+ attr : { value : 'ABCD' }
568
+ } , {
569
+ type : 'span' ,
570
+ style : { textAlign : 'left' , color : 'red' } ,
571
+ attr : { value : 'EFGH' }
572
+ } ]
573
+ }
574
+ } )
575
+ } )
576
+ } )
577
+
578
+ describe ( 'bind events' , ( ) => {
579
+ pending ( 'work in progress' )
580
+ it ( 'inline' , ( ) => {
581
+ const { render, staticRenderFns } = compileAndStringify ( `
582
+ <div>
583
+ <richtext>
584
+ <span @click="handler">Button</span>
585
+ </richtext>
586
+ </div>
587
+ ` )
588
+ const instance = createInstance ( runtime , `
589
+ new Vue({
590
+ el: 'body',
591
+ render: ${ render } ,
592
+ staticRenderFns: ${ staticRenderFns } ,
593
+ methods: {
594
+ handler: function () {}
595
+ }
596
+ })
597
+ ` )
598
+ expect ( instance . getRealRoot ( ) . children [ 0 ] ) . toEqual ( {
599
+ type : 'richtext' ,
600
+ attr : {
601
+ value : [ {
602
+ type : 'span' ,
603
+ events : { click : 'handler' } ,
604
+ attr : { value : 'Button' }
605
+ } ]
606
+ }
607
+ } )
608
+ } )
319
609
} )
320
610
} )
0 commit comments