| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- /**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* bender-tags: treeview */
- 'use strict';
- import Writer from '/ckeditor5/engine/treeview/writer.js';
- import { stringify, parse } from '/tests/engine/_utils/view.js';
- describe( 'Writer', () => {
- let writer;
- /**
- * Executes test using `parse` and `stringify` utils functions.
- *
- * @param {String} input
- * @param {Array.<String>} nodesToInsert
- * @param {String} expected
- */
- function test( input, nodesToInsert, expected ) {
- nodesToInsert = nodesToInsert.map( node => parse( node ) );
- const { view, selection } = parse( input );
- const newRange = writer.insert( selection.getFirstPosition(), nodesToInsert );
- expect( stringify( view, newRange, { showType: true, showPriority: true } ) ).to.equal( expected );
- }
- beforeEach( () => {
- writer = new Writer();
- } );
- describe( 'insert', () => {
- it( 'should return collapsed range in insertion position when using empty array', () => {
- test(
- '<container:p>foo{}bar</container:p>',
- [],
- '<container:p>foo{}bar</container:p>'
- );
- } );
- it( 'should insert text into another text node #1', () => {
- test(
- '<container:p>foo{}bar</container:p>',
- [ 'baz' ],
- '<container:p>foo{baz}bar</container:p>'
- );
- } );
- it( 'should insert text into another text node #2', () => {
- test(
- '<container:p>foobar{}</container:p>',
- [ 'baz' ],
- '<container:p>foobar{baz]</container:p>'
- );
- } );
- it( 'should insert text into another text node #3', () => {
- test(
- '<container:p>{}foobar</container:p>',
- [ 'baz' ],
- '<container:p>[baz}foobar</container:p>'
- );
- } );
- it( 'should break attributes when inserting into text node', () => {
- test(
- '<container:p>foo{}bar</container:p>',
- [ '<attribute:b:1>baz</attribute:b:1>' ],
- '<container:p>foo[<attribute:b:1>baz</attribute:b:1>]bar</container:p>'
- );
- } );
- it( 'should merge text nodes', () => {
- test(
- '<container:p>[]foobar</container:p>',
- [ 'baz' ],
- '<container:p>[baz}foobar</container:p>'
- );
- } );
- it( 'should merge same attribute nodes', () => {
- test(
- '<container:p><attribute:b:1>foo{}bar</attribute:b:1></container:p>',
- [ '<attribute:b:1>baz</attribute:b:1>' ],
- '<container:p><attribute:b:1>foo{baz}bar</attribute:b:1></container:p>'
- );
- } );
- it( 'should not merge different attributes', () => {
- test(
- '<container:p><attribute:b:1>foo{}bar</attribute:b:1></container:p>',
- [ '<attribute:b:2>baz</attribute:b:2>' ],
- '<container:p>' +
- '<attribute:b:1>' +
- 'foo' +
- '</attribute:b:1>' +
- '[' +
- '<attribute:b:2>' +
- 'baz' +
- '</attribute:b:2>' +
- ']' +
- '<attribute:b:1>' +
- 'bar' +
- '</attribute:b:1>' +
- '</container:p>'
- );
- } );
- it( 'should allow to insert multiple nodes', () => {
- test(
- '<container:p>[]</container:p>',
- [ '<attribute:b:1>foo</attribute:b:1>', 'bar' ],
- '<container:p>[<attribute:b:1>foo</attribute:b:1>bar]</container:p>'
- );
- } );
- it( 'should merge after inserting multiple nodes', () => {
- test(
- '<container:p><attribute:b:1>qux</attribute:b:1>[]baz</container:p>',
- [ '<attribute:b:1>foo</attribute:b:1>', 'bar' ],
- '<container:p><attribute:b:1>qux{foo</attribute:b:1>bar}baz</container:p>'
- );
- } );
- } );
- } );
|