8
0

unwrap.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { Client, syncClients, expectClients } from './utils.js';
  2. describe( 'transform', () => {
  3. let john, kate;
  4. beforeEach( () => {
  5. return Promise.all( [
  6. Client.get( 'john' ).then( client => ( john = client ) ),
  7. Client.get( 'kate' ).then( client => ( kate = client ) )
  8. ] );
  9. } );
  10. afterEach( () => {
  11. return Promise.all( [ john.destroy(), kate.destroy() ] );
  12. } );
  13. describe( 'unwrap', () => {
  14. describe( 'by unwrap', () => {
  15. it( 'element in different path', () => {
  16. john.setData(
  17. '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' +
  18. '<blockQuote><paragraph>Bar</paragraph></blockQuote>'
  19. );
  20. kate.setData(
  21. '<blockQuote><paragraph>Foo</paragraph></blockQuote>' +
  22. '<blockQuote>[<paragraph>Bar</paragraph>]</blockQuote>'
  23. );
  24. john.unwrap();
  25. kate.unwrap();
  26. syncClients();
  27. expectClients(
  28. '<paragraph>Foo</paragraph>' +
  29. '<paragraph>Bar</paragraph>'
  30. );
  31. } );
  32. it( 'the same element', () => {
  33. john.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  34. kate.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  35. john.unwrap();
  36. kate.unwrap();
  37. syncClients();
  38. expectClients( '<paragraph>Foo</paragraph>' );
  39. } );
  40. it.skip( 'the same element, then undo', () => {
  41. john.setData( '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote>' );
  42. kate.setData( '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote>' );
  43. john.unwrap();
  44. kate.unwrap();
  45. syncClients();
  46. expectClients( '<paragraph>Foo</paragraph>' );
  47. john.undo();
  48. syncClients();
  49. // Actual content for Kate:
  50. // <paragraph><paragraph>Foo</paragraph></paragraph>
  51. // Kate has a different order of nodes in graveyard after syncing.
  52. expectClients( '<blockQuote><paragraph>Foo</paragraph></blockQuote>' );
  53. } );
  54. } );
  55. describe( 'by delete', () => {
  56. it( 'text from two elements', () => {
  57. john.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote><paragraph>Bar</paragraph>' );
  58. kate.setData( '<blockQuote><paragraph>Fo[o</paragraph></blockQuote><paragraph>Ba]r</paragraph>' );
  59. john.unwrap();
  60. kate.delete();
  61. syncClients();
  62. expectClients( '<paragraph>For</paragraph>' );
  63. } );
  64. it( 'text in same path', () => {
  65. john.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  66. kate.setData( '<blockQuote><paragraph>F[oo]</paragraph></blockQuote>' );
  67. john.unwrap();
  68. kate.delete();
  69. syncClients();
  70. expectClients( '<paragraph>F</paragraph>' );
  71. } );
  72. } );
  73. describe( 'by merge', () => {
  74. it( 'element into paragraph #1', () => {
  75. john.setData( '<blockQuote>[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph></blockQuote>' );
  76. kate.setData( '<blockQuote><paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph></blockQuote>' );
  77. john.unwrap();
  78. kate.merge();
  79. syncClients();
  80. expectClients( '<paragraph>FooBar</paragraph>' );
  81. } );
  82. it( 'element into paragraph #2', () => {
  83. john.setData( '<blockQuote>[<paragraph>Foo</paragraph><paragraph>Bar</paragraph>]</blockQuote>' );
  84. kate.setData( '<blockQuote><paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph></blockQuote>' );
  85. john.unwrap();
  86. kate.merge();
  87. syncClients();
  88. expectClients( '<paragraph>FooBar</paragraph>' );
  89. } );
  90. it( 'unwrapped element', () => {
  91. john.setData( '<paragraph>Foo</paragraph><blockQuote>[<paragraph>Bar</paragraph>]</blockQuote>' );
  92. kate.setData( '<paragraph>Foo</paragraph>[]<blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  93. john.unwrap();
  94. kate.merge();
  95. syncClients();
  96. expectClients(
  97. '<paragraph>Foo</paragraph>' +
  98. '<paragraph>Bar</paragraph>'
  99. );
  100. } );
  101. } );
  102. } );
  103. } );