basic-styles.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 boldWithinText from '../../_data/basic-styles/bold-within-text/input.word2016.html';
  18. import italicStartingText from '../../_data/basic-styles/italic-starting-text/input.word2016.html';
  19. import underlinedText from '../../_data/basic-styles/underlined-text/input.word2016.html';
  20. import strikethroughEndingText from '../../_data/basic-styles/strikethrough-ending-text/input.word2016.html';
  21. import multipleStylesSingleLine from '../../_data/basic-styles/multiple-styles-single-line/input.word2016.html';
  22. import multipleStylesMultiline from '../../_data/basic-styles/multiple-styles-multiline/input.word2016.html';
  23. describe( 'Basic Styles – integration', () => {
  24. let element, editor;
  25. before( () => {
  26. element = document.createElement( 'div' );
  27. document.body.appendChild( element );
  28. return ClassicTestEditor
  29. .create( element, { plugins: [ Clipboard, Paragraph, Heading, Bold, Italic, Underline, Strikethrough, PasteFromOffice ] } )
  30. .then( editorInstance => {
  31. editor = editorInstance;
  32. } );
  33. } );
  34. beforeEach( () => {
  35. setData( editor.model, '<paragraph>[]</paragraph>' );
  36. } );
  37. after( () => {
  38. editor.destroy();
  39. element.remove();
  40. } );
  41. // Pastes: 'Some text <b>with bold</b>.'
  42. // Input same for: Chrome, Firefox and Edge.
  43. describe( 'bold within text', () => {
  44. it( 'pastes in the empty editor', () => {
  45. expectPaste( editor, boldWithinText, '<paragraph>Some text <$text bold="true">with bold</$text>.[]</paragraph>' );
  46. } );
  47. it( 'pastes in the paragraph', () => {
  48. setData( editor.model, '<paragraph>More [] text</paragraph>' );
  49. expectPaste( editor, boldWithinText, '<paragraph>More Some text <$text bold="true">with bold</$text>.[] text</paragraph>' );
  50. } );
  51. it( 'pastes in the different block context', () => {
  52. setData( editor.model, '<heading1>More [] text</heading1>' );
  53. expectPaste( editor, boldWithinText, '<heading1>More Some text <$text bold="true">with bold</$text>.[] text</heading1>' );
  54. } );
  55. it( 'pastes in the inline styling context', () => {
  56. setData( editor.model, '<paragraph><$text italic="true">Ita[]lic</$text></paragraph>' );
  57. expectPaste( editor, boldWithinText, '<paragraph><$text italic="true">Ita</$text>Some text ' +
  58. '<$text bold="true">with bold</$text>.[]<$text italic="true">lic</$text></paragraph>' );
  59. } );
  60. it( 'pastes inside another bold element', () => {
  61. setData( editor.model, '<paragraph><$text bold="true">Ita[]lic</$text></paragraph>' );
  62. expectPaste( editor, boldWithinText, '<paragraph><$text bold="true">Ita</$text>Some text ' +
  63. '<$text bold="true">with bold</$text>.[]<$text bold="true">lic</$text></paragraph>' );
  64. } );
  65. } );
  66. // Pastes: '<i>Italic</i> text.'
  67. // Input same for: Chrome, Firefox and Edge.
  68. describe( 'italic starting text', () => {
  69. it( 'pastes in the empty editor', () => {
  70. expectPaste( editor, italicStartingText, '<paragraph><$text italic="true">Italic</$text> text.[]</paragraph>' );
  71. } );
  72. it( 'pastes in the paragraph', () => {
  73. setData( editor.model, '<paragraph>More [] text</paragraph>' );
  74. expectPaste( editor, italicStartingText, '<paragraph>More <$text italic="true">Italic</$text> text.[] text</paragraph>' );
  75. } );
  76. it( 'pastes in the different block context', () => {
  77. setData( editor.model, '<heading1>More [] text</heading1>' );
  78. expectPaste( editor, italicStartingText, '<heading1>More <$text italic="true">Italic</$text> text.[] text</heading1>' );
  79. } );
  80. it( 'pastes in the inline styling context', () => {
  81. setData( editor.model, '<paragraph><$text bold="true">Bol[]d</$text></paragraph>' );
  82. expectPaste( editor, italicStartingText, '<paragraph><$text bold="true">Bol</$text><$text italic="true">' +
  83. 'Italic</$text> text.[]<$text bold="true">d</$text></paragraph>' );
  84. } );
  85. it( 'pastes inside another italic element', () => {
  86. setData( editor.model, '<paragraph><$text italic="true">Italic[]</$text></paragraph>' );
  87. expectPaste( editor, italicStartingText, '<paragraph><$text italic="true">ItalicItalic</$text> text.[]</paragraph>' );
  88. } );
  89. } );
  90. // Pastes: '<u>Whole text underlined</u>'
  91. // Input same for: Chrome, Firefox and Edge.
  92. describe( 'underlined text', () => {
  93. it( 'pastes in the empty editor', () => {
  94. expectPaste( editor, underlinedText, '<paragraph><$text underline="true">Whole text underlined[]</$text></paragraph>' );
  95. } );
  96. it( 'pastes in the paragraph', () => {
  97. setData( editor.model, '<paragraph>More [] text</paragraph>' );
  98. expectPaste( editor, underlinedText, '<paragraph>More <$text underline="true">Whole text underlined[]' +
  99. '</$text> text</paragraph>' );
  100. } );
  101. it( 'pastes in the different block context', () => {
  102. setData( editor.model, '<heading1>More [] text</heading1>' );
  103. expectPaste( editor, underlinedText, '<heading1>More <$text underline="true">Whole text underlined[]</$text> text</heading1>' );
  104. } );
  105. it( 'pastes in the inline styling context', () => {
  106. setData( editor.model, '<paragraph><$text bold="true">Bol[]d</$text></paragraph>' );
  107. expectPaste( editor, underlinedText, '<paragraph><$text bold="true">Bol</$text><$text underline="true">' +
  108. 'Whole text underlined[]</$text><$text bold="true">d</$text></paragraph>' );
  109. } );
  110. it( 'pastes inside another underlined element', () => {
  111. setData( editor.model, '<paragraph><$text underline="true">Under []line</$text></paragraph>' );
  112. expectPaste( editor, underlinedText, '<paragraph><$text underline="true">Under Whole text underlined[]' +
  113. 'line</$text></paragraph>' );
  114. } );
  115. } );
  116. // Pastes: 'Text <s>incorrect</s>'
  117. // Input same for: Chrome, Firefox and Edge.
  118. describe( 'strikethrough ending text', () => {
  119. it( 'pastes in the empty editor', () => {
  120. expectPaste( editor, strikethroughEndingText, '<paragraph>Text <$text strikethrough="true">incorrect[]</$text></paragraph>' );
  121. } );
  122. it( 'pastes in the paragraph', () => {
  123. setData( editor.model, '<paragraph>More [] text</paragraph>' );
  124. expectPaste( editor, strikethroughEndingText, '<paragraph>More Text <$text strikethrough="true">incorrect[]' +
  125. '</$text> text</paragraph>' );
  126. } );
  127. it( 'pastes in the different block context', () => {
  128. setData( editor.model, '<heading1>More [] text</heading1>' );
  129. expectPaste( editor, strikethroughEndingText, '<heading1>More Text <$text strikethrough="true">incorrect[]' +
  130. '</$text> text</heading1>' );
  131. } );
  132. it( 'pastes in the inline styling context', () => {
  133. setData( editor.model, '<paragraph><$text bold="true">Bol[]d</$text></paragraph>' );
  134. expectPaste( editor, strikethroughEndingText, '<paragraph><$text bold="true">Bol</$text>' +
  135. 'Text <$text strikethrough="true">incorrect[]</$text><$text bold="true">d</$text></paragraph>' );
  136. } );
  137. it( 'pastes inside another strikethrough element', () => {
  138. setData( editor.model, '<paragraph><$text strikethrough="true">[]Foo</$text></paragraph>' );
  139. expectPaste( editor, strikethroughEndingText, '<paragraph>Text <$text strikethrough="true">incorrect[]Foo' +
  140. '</$text></paragraph>' );
  141. } );
  142. } );
  143. // Pastes: 'Text <b><u>containi<s>ng</s></u></b><s><u> multi</u>ple</s><i>styling</i>.'
  144. // Input same for: Chrome, Firefox and Edge.
  145. describe( 'mulitple styles single line', () => {
  146. it( 'pastes in the empty editor', () => {
  147. expectPaste( editor, multipleStylesSingleLine, '<paragraph>Text ' +
  148. '<$text bold="true" underline="true">containi</$text>' +
  149. '<$text bold="true" strikethrough="true" underline="true">ng</$text>' +
  150. '<$text strikethrough="true" underline="true"> multi</$text>' +
  151. '<$text strikethrough="true">ple </$text>' +
  152. '<$text italic="true">styling</$text>.[]</paragraph>' );
  153. } );
  154. it( 'pastes in the paragraph', () => {
  155. setData( editor.model, '<paragraph>More [] text</paragraph>' );
  156. expectPaste( editor, multipleStylesSingleLine, '<paragraph>More 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>.[] text</paragraph>' );
  162. } );
  163. it( 'pastes in the different block context', () => {
  164. setData( editor.model, '<heading1>More [] text</heading1>' );
  165. expectPaste( editor, multipleStylesSingleLine, '<heading1>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</heading1>' );
  171. } );
  172. it( 'pastes in the inline styling context', () => {
  173. setData( editor.model, '<paragraph><$text bold="true">Bol[]d</$text></paragraph>' );
  174. expectPaste( editor, multipleStylesSingleLine, '<paragraph><$text bold="true">Bol</$text>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>.[]' +
  180. '<$text bold="true">d</$text></paragraph>' );
  181. } );
  182. } );
  183. // Pastes:
  184. // <p>Line <b>bold</b> and <i>italics</i></p>
  185. // <p>Line <b><u>foo</u></b><u> bar</u></p>
  186. // <p><s>Third</s> line <b>styling, <i>space on e</i>nd </b></p>
  187. // Input same for: Chrome, Firefox and Edge.
  188. describe( 'mulitple styles multiline', () => {
  189. it( 'pastes in the empty editor', () => {
  190. expectPaste( editor, multipleStylesMultiline, '<paragraph>Line ' +
  191. '<$text bold="true">bold</$text> and <$text italic="true">italics</$text></paragraph>' +
  192. '<paragraph>Line <$text bold="true" underline="true">foo</$text><$text underline="true"> bar</$text></paragraph>' +
  193. '<paragraph><$text strikethrough="true">Third</$text> line <$text bold="true">styling, </$text>' +
  194. '<$text bold="true" italic="true">space on e</$text>' +
  195. '<$text bold="true">nd []</$text></paragraph>' ); // The last space '...nd </b></p>' goes missing.
  196. } );
  197. it( 'pastes in the paragraph', () => {
  198. setData( editor.model, '<paragraph>More [] text</paragraph>' );
  199. expectPaste( editor, multipleStylesMultiline, '<paragraph>More 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> text</paragraph>' ); // The last space '...nd </b></p>' goes missing.
  205. } );
  206. it( 'pastes in the different block context', () => {
  207. setData( editor.model, '<heading1>More [] text</heading1>' );
  208. expectPaste( editor, multipleStylesMultiline, '<heading1>More Line ' +
  209. '<$text bold="true">bold</$text> and <$text italic="true">italics</$text></heading1>' +
  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 inline styling context', () => {
  216. setData( editor.model, '<paragraph><$text bold="true">Bol[]d</$text></paragraph>' );
  217. expectPaste( editor, multipleStylesMultiline, '<paragraph><$text bold="true">Bol</$text>Line ' +
  218. '<$text bold="true">bold</$text> and <$text italic="true">italics</$text></paragraph>' +
  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 []d</$text></paragraph>' ); // The last space '...nd </b></p>' goes missing.
  223. } );
  224. } );
  225. } );