block-embed.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import Scroll from '../../../blots/scroll';
  2. describe('Block Embed', function() {
  3. it('insert', function() {
  4. let scroll = this.initialize(Scroll, '<p>0123</p>');
  5. scroll.insertAt(2, 'video', '#');
  6. expect(scroll.domNode).toEqualHTML(`
  7. <p>01</p>
  8. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  9. <p>23</p>
  10. `);
  11. });
  12. it('split newline', function() {
  13. let scroll = this.initialize(Scroll, '<p>0123</p>');
  14. scroll.insertAt(4, 'video', '#');
  15. expect(scroll.domNode).toEqualHTML(`
  16. <p>0123</p>
  17. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  18. <p><br></p>
  19. `);
  20. });
  21. it('insert end of document', function() {
  22. let scroll = this.initialize(Scroll, '<p>0123</p>');
  23. scroll.insertAt(5, 'video', '#');
  24. expect(scroll.domNode).toEqualHTML(`
  25. <p>0123</p>
  26. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  27. `);
  28. });
  29. it('insert text before', function() {
  30. let scroll = this.initialize(Scroll, '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>');
  31. scroll.insertAt(0, 'Test');
  32. expect(scroll.domNode).toEqualHTML(`
  33. <p>Test</p>
  34. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  35. `);
  36. });
  37. it('insert text after', function() {
  38. let scroll = this.initialize(Scroll, '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>');
  39. scroll.insertAt(1, 'Test');
  40. expect(scroll.domNode).toEqualHTML(`
  41. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  42. <p>Test</p>
  43. `);
  44. });
  45. it('insert inline embed before', function() {
  46. let scroll = this.initialize(Scroll, '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>');
  47. scroll.insertAt(0, 'image', '/assets/favicon.png');
  48. expect(scroll.domNode).toEqualHTML(`
  49. <p><img src="/assets/favicon.png"></p>
  50. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  51. `);
  52. });
  53. it('insert inline embed after', function() {
  54. let scroll = this.initialize(Scroll, '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>');
  55. scroll.insertAt(1, 'image', '/assets/favicon.png');
  56. expect(scroll.domNode).toEqualHTML(`
  57. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  58. <p><img src="/assets/favicon.png"></p>
  59. `);
  60. });
  61. it('insert block embed before', function() {
  62. let scroll = this.initialize(Scroll, '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>');
  63. scroll.insertAt(0, 'video', '#1');
  64. expect(scroll.domNode).toEqualHTML(`
  65. <iframe src="#1" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  66. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  67. `);
  68. });
  69. it('insert block embed after', function() {
  70. let scroll = this.initialize(Scroll, '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>');
  71. scroll.insertAt(1, 'video', '#1');
  72. expect(scroll.domNode).toEqualHTML(`
  73. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  74. <iframe src="#1" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  75. `);
  76. });
  77. it('insert newline before', function() {
  78. let scroll = this.initialize(Scroll, '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>');
  79. scroll.insertAt(0, '\n');
  80. scroll.optimize();
  81. expect(scroll.domNode).toEqualHTML(`
  82. <p><br></p>
  83. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  84. `);
  85. });
  86. it('insert newline after', function() {
  87. let scroll = this.initialize(Scroll, '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>');
  88. scroll.insertAt(1, '\n');
  89. scroll.optimize();
  90. expect(scroll.domNode).toEqualHTML(`
  91. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  92. <p><br></p>
  93. `);
  94. });
  95. it('delete preceding newline', function() {
  96. let scroll = this.initialize(Scroll, '<p>0123</p><iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>');
  97. scroll.deleteAt(4, 1);
  98. expect(scroll.domNode).toEqualHTML(`
  99. <p>0123</p>
  100. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  101. `);
  102. });
  103. });