breakattributes.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: treeview */
  6. 'use strict';
  7. import Writer from '/ckeditor5/engine/treeview/writer.js';
  8. import { stringify, parse } from '/tests/engine/_utils/view.js';
  9. describe( 'Writer', () => {
  10. let writer;
  11. /**
  12. * Executes test using `parse` and `stringify` utils functions. Uses range delimiters `[]{}` to create and
  13. * test break position.
  14. *
  15. * @param {String} input
  16. * @param {String} expected
  17. */
  18. function test( input, expected ) {
  19. const { view, selection } = parse( input );
  20. const newPosition = writer.breakAttributes( selection.getFirstPosition() );
  21. expect( stringify( view, newPosition, { showType: true, showPriority: true } ) ).to.equal( expected );
  22. }
  23. beforeEach( () => {
  24. writer = new Writer();
  25. } );
  26. describe( 'breakAttributes', () => {
  27. it( 'should not break text nodes if they are not in attribute elements - middle', () => {
  28. test(
  29. '<container:p>foo{}bar</container:p>',
  30. '<container:p>foo{}bar</container:p>'
  31. );
  32. } );
  33. it( 'should not break text nodes if they are not in attribute elements - beginning', () => {
  34. test(
  35. '<container:p>{}foobar</container:p>',
  36. '<container:p>{}foobar</container:p>'
  37. );
  38. } );
  39. it( 'should not break text nodes if they are not in attribute elements #2 - end', () => {
  40. test(
  41. '<container:p>foobar{}</container:p>',
  42. '<container:p>foobar{}</container:p>'
  43. );
  44. } );
  45. it( 'should split attribute element', () => {
  46. test(
  47. '<container:p><attribute:b:1>foo{}bar</attribute:b:1></container:p>',
  48. '<container:p><attribute:b:1>foo</attribute:b:1>[]<attribute:b:1>bar</attribute:b:1></container:p>'
  49. );
  50. } );
  51. it( 'should move from beginning of the nested text node to the container', () => {
  52. test(
  53. '<container:p><attribute:b:1><attribute:u:1>{}foobar</attribute:u:1></attribute:b:1></container:p>',
  54. '<container:p>[]<attribute:b:1><attribute:u:1>foobar</attribute:u:1></attribute:b:1></container:p>'
  55. );
  56. } );
  57. it( 'should stick selection in text node if it is in container', () => {
  58. test(
  59. '<container:p>foo{}<attribute:b:1>bar</attribute:b:1></container:p>',
  60. '<container:p>foo{}<attribute:b:1>bar</attribute:b:1></container:p>'
  61. );
  62. } );
  63. it( 'should split nested attributes', () => {
  64. test(
  65. '<container:p><attribute:b:1><attribute:u:1>foo{}bar</attribute:u:1></attribute:b:1></container:p>',
  66. '<container:p>' +
  67. '<attribute:b:1>' +
  68. '<attribute:u:1>' +
  69. 'foo' +
  70. '</attribute:u:1>' +
  71. '</attribute:b:1>' +
  72. '[]' +
  73. '<attribute:b:1>' +
  74. '<attribute:u:1>' +
  75. 'bar' +
  76. '</attribute:u:1>' +
  77. '</attribute:b:1>' +
  78. '</container:p>'
  79. );
  80. } );
  81. it( 'should move from end of the nested text node to the container', () => {
  82. test(
  83. '<container:p><attribute:b:1><attribute:u:1>foobar{}</attribute:u:1></attribute:b:1></container:p>',
  84. '<container:p><attribute:b:1><attribute:u:1>foobar</attribute:u:1></attribute:b:1>[]</container:p>'
  85. );
  86. } );
  87. } );
  88. } );