basic-styles.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 { getFixtures } from '../../_utils/fixtures';
  17. import { expectModel } from '../../_utils/utils';
  18. describe( 'Basic Styles – integration', () => {
  19. let element, editor, input;
  20. before( () => {
  21. input = getFixtures( 'basic-styles' ).input;
  22. element = document.createElement( 'div' );
  23. document.body.appendChild( element );
  24. return ClassicTestEditor
  25. .create( element, { plugins: [ Clipboard, Paragraph, Heading, Bold, Italic, Underline, Strikethrough, PasteFromOffice ] } )
  26. .then( editorInstance => {
  27. editor = editorInstance;
  28. } );
  29. } );
  30. beforeEach( () => {
  31. setData( editor.model, '<paragraph>[]</paragraph>' );
  32. } );
  33. after( () => {
  34. editor.destroy();
  35. element.remove();
  36. } );
  37. // Pastes:
  38. // <p>Some text <b>with bold</b>.</p>
  39. it( 'pastes bold within text', () => {
  40. const expected = '<paragraph>Some text <$text bold="true">with bold</$text>.</paragraph>';
  41. expectModel( editor, input.boldWithinText, expected );
  42. } );
  43. // Pastes:
  44. // <p><i>Italic</i> text.</p>
  45. it( 'pastes italic starting text', () => {
  46. const expected = '<paragraph><$text italic="true">Italic</$text> text.</paragraph>';
  47. expectModel( editor, input.italicStartingText, expected );
  48. } );
  49. // Pastes:
  50. // <p><u>Whole text underlined</u></p>
  51. it( 'pastes underlined text', () => {
  52. const expected = '<paragraph><$text underline="true">Whole text underlined</$text></paragraph>';
  53. expectModel( editor, input.underlinedText, expected );
  54. } );
  55. // Pastes:
  56. // <p>Text <s>incorrect</s></p>
  57. it( 'pastes strikethrough ending text', () => {
  58. const expected = '<paragraph>Text <$text strikethrough="true">incorrect</$text></paragraph>';
  59. expectModel( editor, input.strikethroughEndingText, expected );
  60. } );
  61. // Pastes:
  62. // <p>Text <b><u>containi<s>ng</s></u></b><s><u> multi</u>ple</s><i>styling</i>.</p>
  63. it( 'pastes mulitple styles single line', () => {
  64. const expected = '<paragraph>Text ' +
  65. '<$text bold="true" underline="true">containi</$text>' +
  66. '<$text bold="true" strikethrough="true" underline="true">ng</$text>' +
  67. '<$text strikethrough="true" underline="true"> multi</$text>' +
  68. '<$text strikethrough="true">ple </$text>' +
  69. '<$text italic="true">styling</$text>.</paragraph>';
  70. expectModel( editor, input.multipleStylesSingleLine, expected );
  71. } );
  72. // Pastes:
  73. // <p>Line <b>bold</b> and <i>italics</i></p>
  74. // <p>Line <b><u>foo</u></b><u> bar</u></p>
  75. // <p><s>Third</s> line <b>styling, <i>space on e</i>nd </b></p>
  76. it( 'pastes mulitple styles multiline', () => {
  77. const expected = '<paragraph>Line ' +
  78. '<$text bold="true">bold</$text> and <$text italic="true">italics</$text></paragraph>' +
  79. '<paragraph>Line <$text bold="true" underline="true">foo</$text><$text underline="true"> bar</$text></paragraph>' +
  80. '<paragraph><$text strikethrough="true">Third</$text> line <$text bold="true">styling, </$text>' +
  81. '<$text bold="true" italic="true">space on e</$text>' +
  82. '<$text bold="true">nd </$text></paragraph>';
  83. expectModel( editor, input.multipleStylesMultiline, expected );
  84. } );
  85. } );