block-embed.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import Scroll from '../../../blots/scroll';
  2. describe('Block Embed', function() {
  3. it('insert', function() {
  4. const 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. const 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. const 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. const scroll = this.initialize(
  31. Scroll,
  32. '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
  33. );
  34. scroll.insertAt(0, 'Test');
  35. expect(scroll.domNode).toEqualHTML(`
  36. <p>Test</p>
  37. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  38. `);
  39. });
  40. it('insert text after', function() {
  41. const scroll = this.initialize(
  42. Scroll,
  43. '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
  44. );
  45. scroll.insertAt(1, 'Test');
  46. expect(scroll.domNode).toEqualHTML(`
  47. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  48. <p>Test</p>
  49. `);
  50. });
  51. it('insert inline embed before', function() {
  52. const scroll = this.initialize(
  53. Scroll,
  54. '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
  55. );
  56. scroll.insertAt(0, 'image', '/assets/favicon.png');
  57. expect(scroll.domNode).toEqualHTML(`
  58. <p><img src="/assets/favicon.png"></p>
  59. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  60. `);
  61. });
  62. it('insert inline embed after', function() {
  63. const scroll = this.initialize(
  64. Scroll,
  65. '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
  66. );
  67. scroll.insertAt(1, 'image', '/assets/favicon.png');
  68. expect(scroll.domNode).toEqualHTML(`
  69. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  70. <p><img src="/assets/favicon.png"></p>
  71. `);
  72. });
  73. it('insert block embed before', function() {
  74. const scroll = this.initialize(
  75. Scroll,
  76. '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
  77. );
  78. scroll.insertAt(0, 'video', '#1');
  79. expect(scroll.domNode).toEqualHTML(`
  80. <iframe src="#1" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  81. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  82. `);
  83. });
  84. it('insert block embed after', function() {
  85. const scroll = this.initialize(
  86. Scroll,
  87. '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
  88. );
  89. scroll.insertAt(1, 'video', '#1');
  90. expect(scroll.domNode).toEqualHTML(`
  91. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  92. <iframe src="#1" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  93. `);
  94. });
  95. it('insert newline before', function() {
  96. const scroll = this.initialize(
  97. Scroll,
  98. '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
  99. );
  100. scroll.insertAt(0, '\n');
  101. scroll.optimize();
  102. expect(scroll.domNode).toEqualHTML(`
  103. <p><br></p>
  104. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  105. `);
  106. });
  107. it('insert newline after', function() {
  108. const scroll = this.initialize(
  109. Scroll,
  110. '<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
  111. );
  112. scroll.insertAt(1, '\n');
  113. scroll.optimize();
  114. expect(scroll.domNode).toEqualHTML(`
  115. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  116. <p><br></p>
  117. `);
  118. });
  119. it('delete preceding newline', function() {
  120. const scroll = this.initialize(
  121. Scroll,
  122. '<p>0123</p><iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
  123. );
  124. scroll.deleteAt(4, 1);
  125. expect(scroll.domNode).toEqualHTML(`
  126. <p>0123</p>
  127. <iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>
  128. `);
  129. });
  130. });