/** * @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 Link from '@ckeditor/ckeditor5-link/src/link'; import List from '@ckeditor/ckeditor5-list/src/list'; import PasteFromOffice from '../../../src/pastefromoffice'; import { setData, stringify } from '@ckeditor/ckeditor5-engine/src/dev-utils/model'; import { pasteHtml } from '../../_utils/utils'; import simple from '../../_data/list/simple/input.word2016.html'; import styled from '../../_data/list/styled/input.word2016.html'; import multiple from '../../_data/list/multiple/input.word2016.html'; import multipleCombined from '../../_data/list/multiple-combined/input.word2016.html'; import manyOneItem from '../../_data/list/many-one-item/input.word2016.html'; import heading1 from '../../_data/list/heading1/input.word2016.html'; import heading3Styled from '../../_data/list/heading3-styled/input.word2016.html'; import heading7 from '../../_data/list/heading7/input.word2016.html'; describe( 'List – integration', () => { let element, editor, insertedModel; before( () => { element = document.createElement( 'div' ); document.body.appendChild( element ); return ClassicTestEditor .create( element, { plugins: [ Clipboard, Paragraph, Heading, Bold, Italic, Underline, Link, List, PasteFromOffice ] } ) .then( editorInstance => { editor = editorInstance; const model = editor.model; const insertContent = model.insertContent; sinon.stub( editor.model, 'insertContent' ).callsFake( ( content, selection ) => { // Save model string representation now as it may change after `insertContent()` function call // so accessing it later may not work as it may have empty/changed structure. insertedModel = stringify( content ); insertContent.call( model, content, selection ); } ); } ); } ); beforeEach( () => { setData( editor.model, '[]' ); } ); afterEach( () => { insertedModel = null; } ); after( () => { sinon.restore(); editor.destroy(); element.remove(); } ); // Pastes (after cleaning up garbage markup): // //

1.Item1

//

2.>Item 2

// // which should result in the same output as pasting: // //
  1. Item1
  2. Item2
it( 'pastes simple list', () => { const expectedModel = 'Item1' + 'Item 2'; expectContent( simple, expectedModel ); } ); // Pastes (after cleaning up garbage markup): // //

List:

//

·Bold

//

·Link

//

·Multiple

// // which should result in the same output as pasting: // //

List:

// it( 'pastes list with styled items prepended by a paragraph', () => { const expectedModel = 'List:' + 'B<$text bold="true">old' + '<$text linkHref="https://cksource.com">Link' + '<$text italic="true">M<$text bold="true" italic="true">ul' + '<$text bold="true" italic="true" underline="true">tip' + '<$text italic="true" underline="true">le'; expectContent( styled, expectedModel ); } ); // Pastes (after cleaning up garbage markup): // //

1.Item1

//

2.Item 2

//

Some text

//

·Bullet 1

// // which should result in the same output as pasting: // //
    //
  1. Item1
  2. //
  3. Item 2
  4. //
//

Some text

// it( 'pastes multiple lists separated by the paragraph', () => { const expectedModel = 'Item1' + 'Item 2' + 'Some text' + 'Bullet 1'; expectContent( multiple, expectedModel ); } ); // Pastes (after cleaning up garbage markup): // //

1.Item1

//

2.Item 2

//

1.Item 1

//

2.Item2

// // which should result in the same output as pasting: // //
    //
  1. Item1
  2. //
  3. Item 2
  4. //
//
    //
  1. Item 1
  2. //
  3. Item2
  4. //
// // It will create one list, see https://github.com/ckeditor/ckeditor5-list/issues/99. it( 'pastes multiple lists one right after another', () => { const expectedModel = 'Item1' + 'Item 2' + 'Item 1' + 'Item2'; expectContent( multipleCombined, expectedModel ); } ); // Pastes (after cleaning up garbage markup): // //

1.A

//

1)B

//

I.C

//

A.D

//

a)E

//

a.F

//

i.G

//

//

·H

//

oI

//

//

§J

//

k

//

//

1.h1

// // which should result in the same output as pasting: // //
  1. A
//
  1. B
//
  1. C
//
  1. D
//
  1. E
//
  1. F
//
  1. G
//

// // //

// // //

//
  1. h1
// // It will create one list, for all lists not separated by any element - see https://github.com/ckeditor/ckeditor5-list/issues/99. it( 'pastes many one item lists', () => { const expectedModel = 'A' + 'B' + 'C' + 'D' + 'E' + 'F' + 'G' + '' + 'H' + 'I' + '' + 'J' + 'k' + '' + 'h1'; expectContent( manyOneItem, expectedModel ); } ); // Pastes (after cleaning up garbage markup): // //

1.H1 1

//

2.H1 2

// // which should result in the same output as pasting: // //
    //
  1. H1 1
  2. //
  3. H1 2
  4. //
// // Since headings cannot be used inside lists, they should be transformed to a regular text. it( 'pastes list created from headings (h1)', () => { const expectedModel = 'H1 1' + 'H1 2'; expectContent( heading1, expectedModel ); } ); // Pastes (after cleaning up garbage markup): // //

·H2 1

//

·H2 2

// // which should result in the same output as pasting: // // // // Since headings cannot be used inside lists, they should be transformed to a regular text. it( 'pastes list created from styled headings (h3)', () => { const expectedModel = 'H<$text bold="true">2 1' + '<$text italic="true" underline="true">H' + '<$text underline="true">2 2'; expectContent( heading3Styled, expectedModel ); } ); // Pastes (after cleaning up garbage markup): // //

1.H 7

// // which should result in the same output as pasting: // //
    //
  1. H 7
  2. //
// // In Word `Heading 7` is represented as `

`. it( 'pastes list created from styled headings (h3)', () => { const expectedModel = 'H 7'; expectContent( heading7, expectedModel ); } ); function expectContent( input, expectedModel ) { pasteHtml( editor, input ); expect( insertedModel ).to.equal( expectedModel ); } } );