table.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import Delta from 'quill-delta';
  2. import Quill from '../../../core/quill';
  3. describe('Table Module', function() {
  4. describe('insert table', function() {
  5. it('empty', function() {
  6. const quill = this.initialize(Quill, '<p><br></p>', this.container, {
  7. modules: {
  8. table: true,
  9. },
  10. });
  11. const table = quill.getModule('table');
  12. quill.setSelection(0);
  13. table.insertTable(2, 3);
  14. expect(quill.root).toEqualHTML(`
  15. <table>
  16. <tbody>
  17. <tr><td><br></td><td><br></td><td><br></td></tr>
  18. <tr><td><br></td><td><br></td><td><br></td></tr>
  19. </tbody>
  20. </table>
  21. <p><br></p>
  22. `);
  23. });
  24. it('split', function() {
  25. const quill = this.initialize(Quill, '<p>0123</p>', this.container, {
  26. modules: {
  27. table: true,
  28. },
  29. });
  30. const table = quill.getModule('table');
  31. quill.setSelection(2);
  32. table.insertTable(2, 3);
  33. expect(quill.root).toEqualHTML(`
  34. <table>
  35. <tbody>
  36. <tr><td>01</td><td><br></td><td><br></td></tr>
  37. <tr><td><br></td><td><br></td><td><br></td></tr>
  38. </tbody>
  39. </table>
  40. <p>23</p>
  41. `);
  42. });
  43. });
  44. describe('modify table', function() {
  45. beforeEach(function() {
  46. const tableHTML = `
  47. <table>
  48. <tbody>
  49. <tr><td>a1</td><td>a2</td><td>a3</td></tr>
  50. <tr><td>b1</td><td>b2</td><td>b3</td></tr>
  51. </tbody>
  52. </table>
  53. `;
  54. this.quill = this.initialize(Quill, tableHTML, this.container, {
  55. modules: {
  56. table: true,
  57. },
  58. });
  59. this.table = this.quill.getModule('table');
  60. });
  61. it('insertRowAbove', function() {
  62. this.quill.setSelection(0);
  63. this.table.insertRowAbove();
  64. expect(this.quill.root).toEqualHTML(`
  65. <table>
  66. <tbody>
  67. <tr><td><br></td><td><br></td><td><br></td></tr>
  68. <tr><td>a1</td><td>a2</td><td>a3</td></tr>
  69. <tr><td>b1</td><td>b2</td><td>b3</td></tr>
  70. </tbody>
  71. </table>
  72. `);
  73. });
  74. it('insertRowBelow', function() {
  75. this.quill.setSelection(0);
  76. this.table.insertRowBelow();
  77. expect(this.quill.root).toEqualHTML(`
  78. <table>
  79. <tbody>
  80. <tr><td>a1</td><td>a2</td><td>a3</td></tr>
  81. <tr><td><br></td><td><br></td><td><br></td></tr>
  82. <tr><td>b1</td><td>b2</td><td>b3</td></tr>
  83. </tbody>
  84. </table>
  85. `);
  86. });
  87. it('insertColumnLeft', function() {
  88. this.quill.setSelection(0);
  89. this.table.insertColumnLeft();
  90. expect(this.quill.root).toEqualHTML(`
  91. <table>
  92. <tbody>
  93. <tr><td><br></td><td>a1</td><td>a2</td><td>a3</td></tr>
  94. <tr><td><br></td><td>b1</td><td>b2</td><td>b3</td></tr>
  95. </tbody>
  96. </table>
  97. `);
  98. });
  99. it('insertColumnRight', function() {
  100. this.quill.setSelection(0);
  101. this.table.insertColumnRight();
  102. expect(this.quill.root).toEqualHTML(`
  103. <table>
  104. <tbody>
  105. <tr><td>a1</td><td><br></td><td>a2</td><td>a3</td></tr>
  106. <tr><td>b1</td><td><br></td><td>b2</td><td>b3</td></tr>
  107. </tbody>
  108. </table>
  109. `);
  110. });
  111. it('deleteRow', function() {
  112. this.quill.setSelection(0);
  113. this.table.deleteRow();
  114. expect(this.quill.root).toEqualHTML(`
  115. <table>
  116. <tbody>
  117. <tr><td>b1</td><td>b2</td><td>b3</td></tr>
  118. </tbody>
  119. </table>
  120. `);
  121. });
  122. it('deleteColumn', function() {
  123. this.quill.setSelection(0);
  124. this.table.deleteColumn();
  125. expect(this.quill.root).toEqualHTML(`
  126. <table>
  127. <tbody>
  128. <tr><td>a2</td><td>a3</td></tr>
  129. <tr><td>b2</td><td>b3</td></tr>
  130. </tbody>
  131. </table>
  132. `);
  133. });
  134. it('insertText before', function() {
  135. this.quill.updateContents(new Delta().insert('\n'));
  136. expect(this.quill.root).toEqualHTML(`
  137. <p><br></p>
  138. <table>
  139. <tbody>
  140. <tr><td>a1</td><td>a2</td><td>a3</td></tr>
  141. <tr><td>b1</td><td>b2</td><td>b3</td></tr>
  142. </tbody>
  143. </table>
  144. `);
  145. });
  146. it('insertText after', function() {
  147. this.quill.updateContents(new Delta().retain(18).insert('\n'));
  148. expect(this.quill.root).toEqualHTML(`
  149. <table>
  150. <tbody>
  151. <tr><td>a1</td><td>a2</td><td>a3</td></tr>
  152. <tr><td>b1</td><td>b2</td><td>b3</td></tr>
  153. </tbody>
  154. </table>
  155. <p><br></p>
  156. `);
  157. });
  158. });
  159. });