basic-styles.js 13 KB

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