basic-styles.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  8. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  9. import Heading from '@ckeditor/ckeditor5-heading/src/heading';
  10. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
  11. import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
  12. import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
  13. import Strikethrough from '@ckeditor/ckeditor5-basic-styles/src/strikethrough';
  14. import PasteFromOffice from '../../../src/pastefromoffice';
  15. import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  16. import { expectPaste } from '../../_utils/utils';
  17. import { getFixtures } from '../../_utils/fixtures';
  18. // import boldWithinText from '../../_data/basic-styles/bold-within-text/input.word2016.html';
  19. // import italicStartingText from '../../_data/basic-styles/italic-starting-text/input.word2016.html';
  20. // import underlinedText from '../../_data/basic-styles/underlined-text/input.word2016.html';
  21. // import strikethroughEndingText from '../../_data/basic-styles/strikethrough-ending-text/input.word2016.html';
  22. // import multipleStylesSingleLine from '../../_data/basic-styles/multiple-styles-single-line/input.word2016.html';
  23. // import multipleStylesMultiline from '../../_data/basic-styles/multiple-styles-multiline/input.word2016.html';
  24. describe( 'Basic Styles – integration', () => {
  25. let element, editor, fixtures;
  26. before( () => {
  27. fixtures = getFixtures( 'basic-styles' ).input;
  28. element = document.createElement( 'div' );
  29. document.body.appendChild( element );
  30. return ClassicTestEditor
  31. .create( element, { plugins: [ Clipboard, Paragraph, Heading, Bold, Italic, Underline, Strikethrough, PasteFromOffice ] } )
  32. .then( editorInstance => {
  33. editor = editorInstance;
  34. } );
  35. } );
  36. beforeEach( () => {
  37. setData( editor.model, '<paragraph>[]</paragraph>' );
  38. } );
  39. after( () => {
  40. editor.destroy();
  41. element.remove();
  42. } );
  43. // Pastes: 'Some text <b>with bold</b>.'
  44. // Input same for: Chrome, Firefox and Edge.
  45. describe( 'bold within text', () => {
  46. it( 'pastes in the empty editor', () => {
  47. expectPaste( editor, fixtures.boldWithinText, '<paragraph>Some text <$text bold="true">with bold</$text>.[]</paragraph>' );
  48. } );
  49. it( 'pastes in the paragraph', () => {
  50. setData( editor.model, '<paragraph>More [] text</paragraph>' );
  51. expectPaste( editor, fixtures.boldWithinText,
  52. '<paragraph>More Some text <$text bold="true">with bold</$text>.[] text</paragraph>' );
  53. } );
  54. it( 'pastes in the different block context', () => {
  55. setData( editor.model, '<heading1>More [] text</heading1>' );
  56. expectPaste( editor, fixtures.boldWithinText,
  57. '<heading1>More Some text <$text bold="true">with bold</$text>.[] text</heading1>' );
  58. } );
  59. it( 'pastes in the inline styling context', () => {
  60. setData( editor.model, '<paragraph><$text italic="true">Ita[]lic</$text></paragraph>' );
  61. expectPaste( editor, fixtures.boldWithinText, '<paragraph><$text italic="true">Ita</$text>Some text ' +
  62. '<$text bold="true">with bold</$text>.[]<$text italic="true">lic</$text></paragraph>' );
  63. } );
  64. it( 'pastes inside another bold element', () => {
  65. setData( editor.model, '<paragraph><$text bold="true">Ita[]lic</$text></paragraph>' );
  66. expectPaste( editor, fixtures.boldWithinText, '<paragraph><$text bold="true">Ita</$text>Some text ' +
  67. '<$text bold="true">with bold</$text>.[]<$text bold="true">lic</$text></paragraph>' );
  68. } );
  69. } );
  70. // Pastes: '<i>Italic</i> text.'
  71. // Input same for: Chrome, Firefox and Edge.
  72. describe( 'italic starting text', () => {
  73. it( 'pastes in the empty editor', () => {
  74. expectPaste( editor, fixtures.italicStartingText, '<paragraph><$text italic="true">Italic</$text> text.[]</paragraph>' );
  75. } );
  76. it( 'pastes in the paragraph', () => {
  77. setData( editor.model, '<paragraph>More [] text</paragraph>' );
  78. expectPaste( editor, fixtures.italicStartingText,
  79. '<paragraph>More <$text italic="true">Italic</$text> text.[] text</paragraph>' );
  80. } );
  81. it( 'pastes in the different block context', () => {
  82. setData( editor.model, '<heading1>More [] text</heading1>' );
  83. expectPaste( editor, fixtures.italicStartingText,
  84. '<heading1>More <$text italic="true">Italic</$text> text.[] text</heading1>' );
  85. } );
  86. it( 'pastes in the inline styling context', () => {
  87. setData( editor.model, '<paragraph><$text bold="true">Bol[]d</$text></paragraph>' );
  88. expectPaste( editor, fixtures.italicStartingText, '<paragraph><$text bold="true">Bol</$text><$text italic="true">' +
  89. 'Italic</$text> text.[]<$text bold="true">d</$text></paragraph>' );
  90. } );
  91. it( 'pastes inside another italic element', () => {
  92. setData( editor.model, '<paragraph><$text italic="true">Italic[]</$text></paragraph>' );
  93. expectPaste( editor, fixtures.italicStartingText, '<paragraph><$text italic="true">ItalicItalic</$text> text.[]</paragraph>' );
  94. } );
  95. } );
  96. // Pastes: '<u>Whole text underlined</u>'
  97. // Input same for: Chrome, Firefox and Edge.
  98. describe( 'underlined text', () => {
  99. it( 'pastes in the empty editor', () => {
  100. expectPaste( editor, fixtures.underlinedText,
  101. '<paragraph><$text underline="true">Whole text underlined[]</$text></paragraph>' );
  102. } );
  103. it( 'pastes in the paragraph', () => {
  104. setData( editor.model, '<paragraph>More [] text</paragraph>' );
  105. expectPaste( editor, fixtures.underlinedText, '<paragraph>More <$text underline="true">Whole text underlined[]' +
  106. '</$text> text</paragraph>' );
  107. } );
  108. it( 'pastes in the different block context', () => {
  109. setData( editor.model, '<heading1>More [] text</heading1>' );
  110. expectPaste( editor, fixtures.underlinedText,
  111. '<heading1>More <$text underline="true">Whole text underlined[]</$text> text</heading1>' );
  112. } );
  113. it( 'pastes in the inline styling context', () => {
  114. setData( editor.model, '<paragraph><$text bold="true">Bol[]d</$text></paragraph>' );
  115. expectPaste( editor, fixtures.underlinedText, '<paragraph><$text bold="true">Bol</$text><$text underline="true">' +
  116. 'Whole text underlined[]</$text><$text bold="true">d</$text></paragraph>' );
  117. } );
  118. it( 'pastes inside another underlined element', () => {
  119. setData( editor.model, '<paragraph><$text underline="true">Under []line</$text></paragraph>' );
  120. expectPaste( editor, fixtures.underlinedText, '<paragraph><$text underline="true">Under Whole text underlined[]' +
  121. 'line</$text></paragraph>' );
  122. } );
  123. } );
  124. // Pastes: 'Text <s>incorrect</s>'
  125. // Input same for: Chrome, Firefox and Edge.
  126. describe( 'strikethrough ending text', () => {
  127. it( 'pastes in the empty editor', () => {
  128. expectPaste( editor, fixtures.strikethroughEndingText,
  129. '<paragraph>Text <$text strikethrough="true">incorrect[]</$text></paragraph>' );
  130. } );
  131. it( 'pastes in the paragraph', () => {
  132. setData( editor.model, '<paragraph>More [] text</paragraph>' );
  133. expectPaste( editor, fixtures.strikethroughEndingText, '<paragraph>More Text <$text strikethrough="true">incorrect[]' +
  134. '</$text> text</paragraph>' );
  135. } );
  136. it( 'pastes in the different block context', () => {
  137. setData( editor.model, '<heading1>More [] text</heading1>' );
  138. expectPaste( editor, fixtures.strikethroughEndingText, '<heading1>More Text <$text strikethrough="true">incorrect[]' +
  139. '</$text> text</heading1>' );
  140. } );
  141. it( 'pastes in the inline styling context', () => {
  142. setData( editor.model, '<paragraph><$text bold="true">Bol[]d</$text></paragraph>' );
  143. expectPaste( editor, fixtures.strikethroughEndingText, '<paragraph><$text bold="true">Bol</$text>' +
  144. 'Text <$text strikethrough="true">incorrect[]</$text><$text bold="true">d</$text></paragraph>' );
  145. } );
  146. it( 'pastes inside another strikethrough element', () => {
  147. setData( editor.model, '<paragraph><$text strikethrough="true">[]Foo</$text></paragraph>' );
  148. expectPaste( editor, fixtures.strikethroughEndingText, '<paragraph>Text <$text strikethrough="true">incorrect[]Foo' +
  149. '</$text></paragraph>' );
  150. } );
  151. } );
  152. // Pastes: 'Text <b><u>containi<s>ng</s></u></b><s><u> multi</u>ple</s><i>styling</i>.'
  153. // Input same for: Chrome, Firefox and Edge.
  154. describe( 'mulitple styles single line', () => {
  155. it( 'pastes in the empty editor', () => {
  156. expectPaste( editor, fixtures.multipleStylesSingleLine, '<paragraph>Text ' +
  157. '<$text bold="true" underline="true">containi</$text>' +
  158. '<$text bold="true" strikethrough="true" underline="true">ng</$text>' +
  159. '<$text strikethrough="true" underline="true"> multi</$text>' +
  160. '<$text strikethrough="true">ple </$text>' +
  161. '<$text italic="true">styling</$text>.[]</paragraph>' );
  162. } );
  163. it( 'pastes in the paragraph', () => {
  164. setData( editor.model, '<paragraph>More [] text</paragraph>' );
  165. expectPaste( editor, fixtures.multipleStylesSingleLine, '<paragraph>More Text ' +
  166. '<$text bold="true" underline="true">containi</$text>' +
  167. '<$text bold="true" strikethrough="true" underline="true">ng</$text>' +
  168. '<$text strikethrough="true" underline="true"> multi</$text>' +
  169. '<$text strikethrough="true">ple </$text>' +
  170. '<$text italic="true">styling</$text>.[] text</paragraph>' );
  171. } );
  172. it( 'pastes in the different block context', () => {
  173. setData( editor.model, '<heading1>More [] text</heading1>' );
  174. expectPaste( editor, fixtures.multipleStylesSingleLine, '<heading1>More Text ' +
  175. '<$text bold="true" underline="true">containi</$text>' +
  176. '<$text bold="true" strikethrough="true" underline="true">ng</$text>' +
  177. '<$text strikethrough="true" underline="true"> multi</$text>' +
  178. '<$text strikethrough="true">ple </$text>' +
  179. '<$text italic="true">styling</$text>.[] text</heading1>' );
  180. } );
  181. it( 'pastes in the inline styling context', () => {
  182. setData( editor.model, '<paragraph><$text bold="true">Bol[]d</$text></paragraph>' );
  183. expectPaste( editor, fixtures.multipleStylesSingleLine, '<paragraph><$text bold="true">Bol</$text>Text ' +
  184. '<$text bold="true" underline="true">containi</$text>' +
  185. '<$text bold="true" strikethrough="true" underline="true">ng</$text>' +
  186. '<$text strikethrough="true" underline="true"> multi</$text>' +
  187. '<$text strikethrough="true">ple </$text>' +
  188. '<$text italic="true">styling</$text>.[]' +
  189. '<$text bold="true">d</$text></paragraph>' );
  190. } );
  191. } );
  192. // Pastes:
  193. // <p>Line <b>bold</b> and <i>italics</i></p>
  194. // <p>Line <b><u>foo</u></b><u> bar</u></p>
  195. // <p><s>Third</s> line <b>styling, <i>space on e</i>nd </b></p>
  196. // Input same for: Chrome, Firefox and Edge.
  197. describe( 'mulitple styles multiline', () => {
  198. it( 'pastes in the empty editor', () => {
  199. expectPaste( editor, fixtures.multipleStylesMultiline, '<paragraph>Line ' +
  200. '<$text bold="true">bold</$text> and <$text italic="true">italics</$text></paragraph>' +
  201. '<paragraph>Line <$text bold="true" underline="true">foo</$text><$text underline="true"> bar</$text></paragraph>' +
  202. '<paragraph><$text strikethrough="true">Third</$text> line <$text bold="true">styling, </$text>' +
  203. '<$text bold="true" italic="true">space on e</$text>' +
  204. '<$text bold="true">nd []</$text></paragraph>' ); // The last space '...nd </b></p>' goes missing.
  205. } );
  206. it( 'pastes in the paragraph', () => {
  207. setData( editor.model, '<paragraph>More [] text</paragraph>' );
  208. expectPaste( editor, fixtures.multipleStylesMultiline, '<paragraph>More Line ' +
  209. '<$text bold="true">bold</$text> and <$text italic="true">italics</$text></paragraph>' +
  210. '<paragraph>Line <$text bold="true" underline="true">foo</$text><$text underline="true"> bar</$text></paragraph>' +
  211. '<paragraph><$text strikethrough="true">Third</$text> line <$text bold="true">styling, </$text>' +
  212. '<$text bold="true" italic="true">space on e</$text>' +
  213. '<$text bold="true">nd []</$text> text</paragraph>' ); // The last space '...nd </b></p>' goes missing.
  214. } );
  215. it( 'pastes in the different block context', () => {
  216. setData( editor.model, '<heading1>More [] text</heading1>' );
  217. expectPaste( editor, fixtures.multipleStylesMultiline, '<heading1>More Line ' +
  218. '<$text bold="true">bold</$text> and <$text italic="true">italics</$text></heading1>' +
  219. '<paragraph>Line <$text bold="true" underline="true">foo</$text><$text underline="true"> bar</$text></paragraph>' +
  220. '<paragraph><$text strikethrough="true">Third</$text> line <$text bold="true">styling, </$text>' +
  221. '<$text bold="true" italic="true">space on e</$text>' +
  222. '<$text bold="true">nd []</$text> text</paragraph>' ); // The last space '...nd </b></p>' goes missing.
  223. } );
  224. it( 'pastes in the inline styling context', () => {
  225. setData( editor.model, '<paragraph><$text bold="true">Bol[]d</$text></paragraph>' );
  226. expectPaste( editor, fixtures.multipleStylesMultiline, '<paragraph><$text bold="true">Bol</$text>Line ' +
  227. '<$text bold="true">bold</$text> and <$text italic="true">italics</$text></paragraph>' +
  228. '<paragraph>Line <$text bold="true" underline="true">foo</$text><$text underline="true"> bar</$text></paragraph>' +
  229. '<paragraph><$text strikethrough="true">Third</$text> line <$text bold="true">styling, </$text>' +
  230. '<$text bold="true" italic="true">space on e</$text>' +
  231. '<$text bold="true">nd []d</$text></paragraph>' ); // The last space '...nd </b></p>' goes missing.
  232. } );
  233. } );
  234. } );