| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- /**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* bender-tags: view, browser-only */
- 'use strict';
- import { breakAttributes } from '/ckeditor5/engine/view/writer.js';
- import DocumentFragment from '/ckeditor5/engine/view/documentfragment.js';
- import AttributeElement from '/ckeditor5/engine/view/attributeelement.js';
- import Text from '/ckeditor5/engine/view/text.js';
- import { stringify, parse } from '/tests/engine/_utils/view.js';
- describe( 'writer', () => {
- /**
- * Executes test using `parse` and `stringify` utils functions. Uses range delimiters `[]{}` to create and
- * test break position.
- *
- * @param {String} input
- * @param {String} expected
- */
- function test( input, expected ) {
- let { view, selection } = parse( input );
- // Wrap attributes and text into DocumentFragment.
- if ( view instanceof AttributeElement || view instanceof Text ) {
- view = new DocumentFragment( view );
- }
- const newPosition = breakAttributes( selection.getFirstPosition() );
- expect( stringify( view, newPosition, { showType: true, showPriority: true } ) ).to.equal( expected );
- }
- describe( 'breakAttributes', () => {
- it( 'should not break text nodes if they are not in attribute elements - middle', () => {
- test(
- '<container:p>foo{}bar</container:p>',
- '<container:p>foo{}bar</container:p>'
- );
- } );
- it( 'should not break text nodes if they are not in attribute elements - beginning', () => {
- test(
- '<container:p>{}foobar</container:p>',
- '<container:p>{}foobar</container:p>'
- );
- } );
- it( 'should not break text nodes if they are not in attribute elements #2 - end', () => {
- test(
- '<container:p>foobar{}</container:p>',
- '<container:p>foobar{}</container:p>'
- );
- } );
- it( 'should split attribute element', () => {
- test(
- '<container:p><attribute:b:1>foo{}bar</attribute:b:1></container:p>',
- '<container:p><attribute:b:1>foo</attribute:b:1>[]<attribute:b:1>bar</attribute:b:1></container:p>'
- );
- } );
- it( 'should move from beginning of the nested text node to the container', () => {
- test(
- '<container:p><attribute:b:1><attribute:u:1>{}foobar</attribute:u:1></attribute:b:1></container:p>',
- '<container:p>[]<attribute:b:1><attribute:u:1>foobar</attribute:u:1></attribute:b:1></container:p>'
- );
- } );
- it( 'should stick selection in text node if it is in container', () => {
- test(
- '<container:p>foo{}<attribute:b:1>bar</attribute:b:1></container:p>',
- '<container:p>foo{}<attribute:b:1>bar</attribute:b:1></container:p>'
- );
- } );
- it( 'should split nested attributes', () => {
- test(
- '<container:p><attribute:b:1><attribute:u:1>foo{}bar</attribute:u:1></attribute:b:1></container:p>',
- '<container:p>' +
- '<attribute:b:1>' +
- '<attribute:u:1>' +
- 'foo' +
- '</attribute:u:1>' +
- '</attribute:b:1>' +
- '[]' +
- '<attribute:b:1>' +
- '<attribute:u:1>' +
- 'bar' +
- '</attribute:u:1>' +
- '</attribute:b:1>' +
- '</container:p>'
- );
- } );
- it( 'should move from end of the nested text node to the container', () => {
- test(
- '<container:p><attribute:b:1><attribute:u:1>foobar{}</attribute:u:1></attribute:b:1></container:p>',
- '<container:p><attribute:b:1><attribute:u:1>foobar</attribute:u:1></attribute:b:1>[]</container:p>'
- );
- } );
- it( 'should split attribute element directly in document fragment', () => {
- test(
- '<attribute:b:1>foo{}bar</attribute:b:1>',
- '<attribute:b:1>foo</attribute:b:1>[]<attribute:b:1>bar</attribute:b:1>'
- );
- } );
- it( 'should not split text directly in document fragment', () => {
- test(
- 'foo{}bar',
- 'foo{}bar'
- );
- } );
- } );
- } );
|