breakattributes.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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/core/treeview/writer.js';
  8. import Element from '/ckeditor5/core/treeview/element.js';
  9. import Text from '/ckeditor5/core/treeview/text.js';
  10. import utils from '/tests/core/treeview/writer/_utils/utils.js';
  11. describe( 'Writer', () => {
  12. const create = utils.create;
  13. const test = utils.test;
  14. let writer;
  15. beforeEach( () => {
  16. writer = new Writer();
  17. } );
  18. describe( 'breakAttributes', () => {
  19. // <p>{|foobar}</p> -> <p>|{foobar}</p>
  20. it( '<p>{|foobar}</p>', () => {
  21. const created = create( writer, {
  22. instanceOf: Element,
  23. name: 'p',
  24. children: [
  25. { instanceOf: Text, data: 'foobar', position: 0 }
  26. ]
  27. } );
  28. const newPosition = writer.breakAttributes( created.position );
  29. test( writer, newPosition, created.node, {
  30. instanceOf: Element,
  31. name: 'p',
  32. position: 0,
  33. children: [
  34. { instanceOf: Text, data: 'foobar' }
  35. ]
  36. } );
  37. } );
  38. it( '<p>foo|bar</p>', () => {
  39. // <p>{foo|bar}</p> -> <p>{foo}|{bar}</p>
  40. const created = create( writer, {
  41. instanceOf: Element,
  42. name: 'p',
  43. children: [
  44. { instanceOf: Text, data: 'foobar', position: 3 }
  45. ]
  46. } );
  47. const newPosition = writer.breakAttributes( created.position );
  48. test( writer, newPosition, created.node, {
  49. instanceOf: Element,
  50. name: 'p',
  51. position: 1,
  52. children: [
  53. { instanceOf: Text, data: 'foo' },
  54. { instanceOf: Text, data: 'bar' }
  55. ]
  56. } );
  57. } );
  58. it( '<p>{foobar|}</p>', () => {
  59. // <p>{foobar|}</p> -> <p>{foobar}|</p>
  60. const created = create( writer, {
  61. instanceOf: Element,
  62. name: 'p',
  63. children: [
  64. { instanceOf: Text, data: 'foobar', position: 6 }
  65. ]
  66. } );
  67. const newPosition = writer.breakAttributes( created.position );
  68. test( writer, newPosition, created.node, {
  69. instanceOf: Element,
  70. name: 'p',
  71. position: 1,
  72. children: [
  73. { instanceOf: Text, data: 'foobar' }
  74. ]
  75. } );
  76. } );
  77. it( '<p><b>{foo|bar}</b></p>', () => {
  78. // <p><b>{foo|bar}</b></p> -> <p><b>{foo}</b>|<b>{bar}</b></p>
  79. const created = create( writer, {
  80. instanceOf: Element,
  81. name: 'p',
  82. children: [
  83. {
  84. instanceOf: Element,
  85. name: 'b',
  86. priority: 1,
  87. children: [
  88. { instanceOf: Text, data: 'foobar', position: 3 }
  89. ]
  90. }
  91. ]
  92. } );
  93. const newPosition = writer.breakAttributes( created.position );
  94. test( writer, newPosition, created.node, {
  95. instanceOf: Element,
  96. name: 'p',
  97. position: 1,
  98. children: [
  99. {
  100. instanceOf: Element,
  101. name: 'b',
  102. priority: 1,
  103. children: [
  104. { instanceOf: Text, data: 'foo' }
  105. ]
  106. },
  107. {
  108. instanceOf: Element,
  109. name: 'b',
  110. priority: 1,
  111. children: [
  112. { instanceOf: Text, data: 'bar' }
  113. ]
  114. }
  115. ]
  116. } );
  117. } );
  118. it( '<p><b><u>{|foobar}</u></b></p>', () => {
  119. // <p><b><u>{|foobar}</u></b></p> -> <p>|<b><u>{foobar}</u></b></p>
  120. const created = create( writer, {
  121. instanceOf: Element,
  122. name: 'p',
  123. children: [
  124. {
  125. instanceOf: Element,
  126. name: 'b',
  127. priority: 1,
  128. children: [
  129. {
  130. instanceOf: Element,
  131. name: 'u',
  132. priority: 1,
  133. children: [
  134. { instanceOf: Text, data: 'foobar', position: 0 }
  135. ]
  136. }
  137. ]
  138. }
  139. ]
  140. } );
  141. const newPosition = writer.breakAttributes( created.position );
  142. test( writer, newPosition, created.node, {
  143. instanceOf: Element,
  144. name: 'p',
  145. position: 0,
  146. children: [
  147. {
  148. instanceOf: Element,
  149. name: 'b',
  150. priority: 1,
  151. children: [
  152. {
  153. instanceOf: Element,
  154. name: 'u',
  155. priority: 1,
  156. children: [
  157. { instanceOf: Text, data: 'foobar' }
  158. ]
  159. }
  160. ]
  161. }
  162. ]
  163. } );
  164. } );
  165. // <p><b><u>{foo|ba}r</u></b></p> -> <p><b><u>{foo}</u></b>|<b></u>{bar}</u></b></p>
  166. it( '<p><b><u>{foo|bar}</u></b></p>', () => {
  167. const created = create( writer, {
  168. instanceOf: Element,
  169. name: 'p',
  170. children: [
  171. {
  172. instanceOf: Element,
  173. name: 'b',
  174. priority: 1,
  175. children: [
  176. {
  177. instanceOf: Element,
  178. name: 'u',
  179. priority: 1,
  180. children: [
  181. { instanceOf: Text, data: 'foobar', position: 3 }
  182. ]
  183. }
  184. ]
  185. }
  186. ]
  187. } );
  188. const newPosition = writer.breakAttributes( created.position );
  189. test( writer, newPosition, created.node, {
  190. instanceOf: Element,
  191. name: 'p',
  192. position: 1,
  193. children: [
  194. {
  195. instanceOf: Element,
  196. name: 'b',
  197. priority: 1,
  198. children: [
  199. {
  200. instanceOf: Element,
  201. name: 'u',
  202. priority: 1,
  203. children: [
  204. { instanceOf: Text, data: 'foo' }
  205. ]
  206. }
  207. ]
  208. },
  209. {
  210. instanceOf: Element,
  211. name: 'b',
  212. priority: 1,
  213. children: [
  214. {
  215. instanceOf: Element,
  216. name: 'u',
  217. priority: 1,
  218. children: [
  219. { instanceOf: Text, data: 'bar' }
  220. ]
  221. }
  222. ]
  223. }
  224. ]
  225. } );
  226. } );
  227. it( '<p><b><u>{foobar|}</u></b></p>', () => {
  228. // <p><b><u>{foobar|}</u></b></p> -> <p><b><u>{foobar}</u></b>|</p>
  229. const created = create( writer, {
  230. instanceOf: Element,
  231. name: 'p',
  232. children: [
  233. {
  234. instanceOf: Element,
  235. name: 'b',
  236. priority: 1,
  237. children: [
  238. {
  239. instanceOf: Element,
  240. name: 'u',
  241. priority: 1,
  242. children: [
  243. { instanceOf: Text, data: 'foobar', position: 6 }
  244. ]
  245. }
  246. ]
  247. }
  248. ]
  249. } );
  250. const newPosition = writer.breakAttributes( created.position );
  251. test( writer, newPosition, created.node, {
  252. instanceOf: Element,
  253. name: 'p',
  254. position: 1,
  255. children: [
  256. {
  257. instanceOf: Element,
  258. name: 'b',
  259. priority: 1,
  260. children: [
  261. {
  262. instanceOf: Element,
  263. name: 'u',
  264. priority: 1,
  265. children: [
  266. { instanceOf: Text, data: 'foobar' }
  267. ]
  268. }
  269. ]
  270. }
  271. ]
  272. } );
  273. } );
  274. } );
  275. } );