/** * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md. */ /* globals document */ import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor'; import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard'; import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; import Heading from '@ckeditor/ckeditor5-heading/src/heading'; import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold'; import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic'; import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline'; import Strikethrough from '@ckeditor/ckeditor5-basic-styles/src/strikethrough'; import PasteFromOffice from '../../../src/pastefromoffice'; import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model'; import { expectPaste } from '../../_utils/utils'; import boldWithinText from '../../_data/basic-styles/bold-within-text/input.word2016.html'; import italicStartingText from '../../_data/basic-styles/italic-starting-text/input.word2016.html'; import underlinedText from '../../_data/basic-styles/underlined-text/input.word2016.html'; import strikethroughEndingText from '../../_data/basic-styles/strikethrough-ending-text/input.word2016.html'; import multipleStylesSingleLine from '../../_data/basic-styles/multiple-styles-single-line/input.word2016.html'; import multipleStylesMultiline from '../../_data/basic-styles/multiple-styles-multiline/input.word2016.html'; describe( 'Basic Styles – integration', () => { let element, editor; before( () => { element = document.createElement( 'div' ); document.body.appendChild( element ); return ClassicTestEditor .create( element, { plugins: [ Clipboard, Paragraph, Heading, Bold, Italic, Underline, Strikethrough, PasteFromOffice ] } ) .then( editorInstance => { editor = editorInstance; } ); } ); beforeEach( () => { setData( editor.model, '[]' ); } ); after( () => { editor.destroy(); element.remove(); } ); // Pastes: 'Some text with bold.' // Input same for: Chrome, Firefox and Edge. describe( 'bold within text', () => { it( 'pastes in the empty editor', () => { expectPaste( editor, boldWithinText, 'Some text <$text bold="true">with bold.[]' ); } ); it( 'pastes in the paragraph', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, boldWithinText, 'More Some text <$text bold="true">with bold.[] text' ); } ); it( 'pastes in the different block context', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, boldWithinText, 'More Some text <$text bold="true">with bold.[] text' ); } ); it( 'pastes in the inline styling context', () => { setData( editor.model, '<$text italic="true">Ita[]lic' ); expectPaste( editor, boldWithinText, '<$text italic="true">ItaSome text ' + '<$text bold="true">with bold.[]<$text italic="true">lic' ); } ); it( 'pastes inside another bold element', () => { setData( editor.model, '<$text bold="true">Ita[]lic' ); expectPaste( editor, boldWithinText, '<$text bold="true">ItaSome text ' + '<$text bold="true">with bold.[]<$text bold="true">lic' ); } ); } ); // Pastes: 'Italic text.' // Input same for: Chrome, Firefox and Edge. describe( 'italic starting text', () => { it( 'pastes in the empty editor', () => { expectPaste( editor, italicStartingText, '<$text italic="true">Italic text.[]' ); } ); it( 'pastes in the paragraph', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, italicStartingText, 'More <$text italic="true">Italic text.[] text' ); } ); it( 'pastes in the different block context', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, italicStartingText, 'More <$text italic="true">Italic text.[] text' ); } ); it( 'pastes in the inline styling context', () => { setData( editor.model, '<$text bold="true">Bol[]d' ); expectPaste( editor, italicStartingText, '<$text bold="true">Bol<$text italic="true">' + 'Italic text.[]<$text bold="true">d' ); } ); it( 'pastes inside another italic element', () => { setData( editor.model, '<$text italic="true">Italic[]' ); expectPaste( editor, italicStartingText, '<$text italic="true">ItalicItalic text.[]' ); } ); } ); // Pastes: 'Whole text underlined' // Input same for: Chrome, Firefox and Edge. describe( 'underlined text', () => { it( 'pastes in the empty editor', () => { expectPaste( editor, underlinedText, '<$text underline="true">Whole text underlined[]' ); } ); it( 'pastes in the paragraph', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, underlinedText, 'More <$text underline="true">Whole text underlined[]' + ' text' ); } ); it( 'pastes in the different block context', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, underlinedText, 'More <$text underline="true">Whole text underlined[] text' ); } ); it( 'pastes in the inline styling context', () => { setData( editor.model, '<$text bold="true">Bol[]d' ); expectPaste( editor, underlinedText, '<$text bold="true">Bol<$text underline="true">' + 'Whole text underlined[]<$text bold="true">d' ); } ); it( 'pastes inside another underlined element', () => { setData( editor.model, '<$text underline="true">Under []line' ); expectPaste( editor, underlinedText, '<$text underline="true">Under Whole text underlined[]' + 'line' ); } ); } ); // Pastes: 'Text incorrect' // Input same for: Chrome, Firefox and Edge. describe( 'strikethrough ending text', () => { it( 'pastes in the empty editor', () => { expectPaste( editor, strikethroughEndingText, 'Text <$text strikethrough="true">incorrect[]' ); } ); it( 'pastes in the paragraph', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, strikethroughEndingText, 'More Text <$text strikethrough="true">incorrect[]' + ' text' ); } ); it( 'pastes in the different block context', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, strikethroughEndingText, 'More Text <$text strikethrough="true">incorrect[]' + ' text' ); } ); it( 'pastes in the inline styling context', () => { setData( editor.model, '<$text bold="true">Bol[]d' ); expectPaste( editor, strikethroughEndingText, '<$text bold="true">Bol' + 'Text <$text strikethrough="true">incorrect[]<$text bold="true">d' ); } ); it( 'pastes inside another strikethrough element', () => { setData( editor.model, '<$text strikethrough="true">[]Foo' ); expectPaste( editor, strikethroughEndingText, 'Text <$text strikethrough="true">incorrect[]Foo' + '' ); } ); } ); // Pastes: 'Text containing multiplestyling.' // Input same for: Chrome, Firefox and Edge. describe( 'mulitple styles single line', () => { it( 'pastes in the empty editor', () => { expectPaste( editor, multipleStylesSingleLine, 'Text ' + '<$text bold="true" underline="true">containi' + '<$text bold="true" strikethrough="true" underline="true">ng' + '<$text strikethrough="true" underline="true"> multi' + '<$text strikethrough="true">ple ' + '<$text italic="true">styling.[]' ); } ); it( 'pastes in the paragraph', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, multipleStylesSingleLine, 'More Text ' + '<$text bold="true" underline="true">containi' + '<$text bold="true" strikethrough="true" underline="true">ng' + '<$text strikethrough="true" underline="true"> multi' + '<$text strikethrough="true">ple ' + '<$text italic="true">styling.[] text' ); } ); it( 'pastes in the different block context', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, multipleStylesSingleLine, 'More Text ' + '<$text bold="true" underline="true">containi' + '<$text bold="true" strikethrough="true" underline="true">ng' + '<$text strikethrough="true" underline="true"> multi' + '<$text strikethrough="true">ple ' + '<$text italic="true">styling.[] text' ); } ); it( 'pastes in the inline styling context', () => { setData( editor.model, '<$text bold="true">Bol[]d' ); expectPaste( editor, multipleStylesSingleLine, '<$text bold="true">BolText ' + '<$text bold="true" underline="true">containi' + '<$text bold="true" strikethrough="true" underline="true">ng' + '<$text strikethrough="true" underline="true"> multi' + '<$text strikethrough="true">ple ' + '<$text italic="true">styling.[]' + '<$text bold="true">d' ); } ); } ); // Pastes: //

Line bold and italics

//

Line foo bar

//

Third line styling, space on end

// Input same for: Chrome, Firefox and Edge. describe( 'mulitple styles multiline', () => { it( 'pastes in the empty editor', () => { expectPaste( editor, multipleStylesMultiline, 'Line ' + '<$text bold="true">bold and <$text italic="true">italics' + 'Line <$text bold="true" underline="true">foo<$text underline="true"> bar' + '<$text strikethrough="true">Third line <$text bold="true">styling, ' + '<$text bold="true" italic="true">space on e' + '<$text bold="true">nd []' ); // The last space '...nd

' goes missing. } ); it( 'pastes in the paragraph', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, multipleStylesMultiline, 'More Line ' + '<$text bold="true">bold and <$text italic="true">italics' + 'Line <$text bold="true" underline="true">foo<$text underline="true"> bar' + '<$text strikethrough="true">Third line <$text bold="true">styling, ' + '<$text bold="true" italic="true">space on e' + '<$text bold="true">nd [] text' ); // The last space '...nd

' goes missing. } ); it( 'pastes in the different block context', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, multipleStylesMultiline, 'More Line ' + '<$text bold="true">bold and <$text italic="true">italics' + 'Line <$text bold="true" underline="true">foo<$text underline="true"> bar' + '<$text strikethrough="true">Third line <$text bold="true">styling, ' + '<$text bold="true" italic="true">space on e' + '<$text bold="true">nd [] text' ); // The last space '...nd

' goes missing. } ); it( 'pastes in the inline styling context', () => { setData( editor.model, '<$text bold="true">Bol[]d' ); expectPaste( editor, multipleStylesMultiline, '<$text bold="true">BolLine ' + '<$text bold="true">bold and <$text italic="true">italics' + 'Line <$text bold="true" underline="true">foo<$text underline="true"> bar' + '<$text strikethrough="true">Third line <$text bold="true">styling, ' + '<$text bold="true" italic="true">space on e' + '<$text bold="true">nd []d' ); // The last space '...nd

' goes missing. } ); } ); } );