/**
* @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 PasteFromWord from '../../../src/pastefromword';
import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import { expectPaste } 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;
before( () => {
element = document.createElement( 'div' );
document.body.appendChild( element );
return ClassicTestEditor
.create( element, { plugins: [ Clipboard, Paragraph, Heading, Bold, Italic, Underline, Link, List, PasteFromWord ] } )
.then( editorInstance => {
editor = editorInstance;
} );
} );
beforeEach( () => {
setData( editor.model, '[]' );
} );
after( () => {
editor.destroy();
element.remove();
} );
// Pastes (after cleaning up garbage markup):
//
//
1.Item1
// 2.>Item 2
//
// which should result in the same output as pasting:
//
// - Item1
- Item2
it( 'pastes simple list', () => {
const expectedModel = 'Item1' +
'Item 2[]';
expectPaste( editor, simple, expectedModel );
} );
// Pastes (after cleaning up garbage markup):
//
// List:
// ·Bold
// ·Link
// ·Multiple
//
// which should result in the same output as pasting:
//
// List:
//
// - Bold
// - Link
// - Multiple
//
it( 'pastes list with styled items prepended by a paragraph', () => {
const expectedModel = 'List:' +
'B<$text bold="true">old$text>' +
'<$text linkHref="https://cksource.com">Lin$text>k' +
'<$text italic="true">M$text><$text bold="true" italic="true">ul$text>' +
'<$text bold="true" italic="true" underline="true">tip$text>' +
'<$text italic="true" underline="true">le[]$text>';
expectPaste( editor, 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:
//
//
// - Item1
// - Item 2
//
// Some text
//
it( 'pastes multiple lists separated by the paragraph', () => {
const expectedModel = 'Item1' +
'Item 2' +
'Some text' +
'Bullet 1[]';
expectPaste( editor, 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:
//
//
// - Item1
// - Item 2
//
//
// - Item 1
// - Item2
//
//
// 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[]';
expectPaste( editor, 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:
//
// - A
// - B
// - C
// - D
// - E
// - F
// - G
//
//
//
//
//
//
//
// - 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[]';
expectPaste( editor, manyOneItem, expectedModel );
} );
// Pastes (after cleaning up garbage markup):
//
// 1.H1 1
// 2.H1 2
//
// which should result in the same output as pasting:
//
//
// - H1 1
// - H1 2
//
//
// 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[]';
expectPaste( editor, 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>' +
'<$text italic="true" underline="true">H$text>' +
'<$text underline="true">2$text> 2[]';
expectPaste( editor, heading3Styled, expectedModel );
} );
// Pastes (after cleaning up garbage markup):
//
// 1.H 7
//
// which should result in the same output as pasting:
//
//
// - H 7
//
//
// In Word `Heading 7` is represented as ``.
it( 'pastes list created from styled headings (h3)', () => {
const expectedModel = 'H 7[]';
expectPaste( editor, heading7, expectedModel );
} );
} );