block.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import Scroll from '../../../blots/scroll';
  2. describe('Block', function() {
  3. it('childless', function() {
  4. const scroll = this.initialize(Scroll, '');
  5. const block = scroll.create('block');
  6. block.optimize();
  7. expect(block.domNode).toEqualHTML('<br>');
  8. });
  9. it('insert into empty', function() {
  10. const scroll = this.initialize(Scroll, '');
  11. const block = scroll.create('block');
  12. block.insertAt(0, 'Test');
  13. expect(block.domNode).toEqualHTML('Test');
  14. });
  15. it('insert newlines', function() {
  16. const scroll = this.initialize(Scroll, '<p><br></p>');
  17. scroll.insertAt(0, '\n\n\n');
  18. expect(scroll.domNode).toEqualHTML(
  19. '<p><br></p><p><br></p><p><br></p><p><br></p>',
  20. );
  21. });
  22. it('insert multiline', function() {
  23. const scroll = this.initialize(Scroll, '<p>Hello World!</p>');
  24. scroll.insertAt(6, 'pardon\nthis\n\ninterruption\n');
  25. expect(scroll.domNode).toEqualHTML(`
  26. <p>Hello pardon</p>
  27. <p>this</p>
  28. <p><br></p>
  29. <p>interruption</p>
  30. <p>World!</p>
  31. `);
  32. });
  33. it('insert into formatted', function() {
  34. const scroll = this.initialize(Scroll, '<h1>Welcome</h1>');
  35. scroll.insertAt(3, 'l\n');
  36. expect(scroll.domNode.firstChild.outerHTML).toEqualHTML('<h1>Well</h1>');
  37. expect(scroll.domNode.childNodes[1].outerHTML).toEqualHTML('<h1>come</h1>');
  38. });
  39. it('delete line contents', function() {
  40. const scroll = this.initialize(Scroll, '<p>Hello</p><p>World!</p>');
  41. scroll.deleteAt(0, 5);
  42. expect(scroll.domNode).toEqualHTML('<p><br></p><p>World!</p>');
  43. });
  44. it('join lines', function() {
  45. const scroll = this.initialize(Scroll, '<h1>Hello</h1><h2>World!</h2>');
  46. scroll.deleteAt(5, 1);
  47. expect(scroll.domNode).toEqualHTML('<h2>HelloWorld!</h2>');
  48. });
  49. it('join line with empty', function() {
  50. const scroll = this.initialize(
  51. Scroll,
  52. '<p>Hello<strong>World</strong></p><p><br></p>',
  53. );
  54. scroll.deleteAt(10, 1);
  55. expect(scroll.domNode).toEqualHTML('<p>Hello<strong>World</strong></p>');
  56. });
  57. it('join empty lines', function() {
  58. const scroll = this.initialize(Scroll, '<h1><br></h1><p><br></p>');
  59. scroll.deleteAt(1, 1);
  60. expect(scroll.domNode).toEqualHTML('<h1><br></h1>');
  61. });
  62. it('format empty', function() {
  63. const scroll = this.initialize(Scroll, '<p><br></p>');
  64. scroll.formatAt(0, 1, 'header', 1);
  65. expect(scroll.domNode).toEqualHTML('<h1><br></h1>');
  66. });
  67. it('format newline', function() {
  68. const scroll = this.initialize(Scroll, '<h1>Hello</h1>');
  69. scroll.formatAt(5, 1, 'header', 2);
  70. expect(scroll.domNode).toEqualHTML('<h2>Hello</h2>');
  71. });
  72. it('remove unnecessary break', function() {
  73. const scroll = this.initialize(Scroll, '<p>Test</p>');
  74. scroll.children.head.domNode.appendChild(document.createElement('br'));
  75. scroll.update();
  76. expect(scroll.domNode).toEqualHTML('<p>Test</p>');
  77. });
  78. });