| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- /**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- 'use strict';
- import { getData } from '/tests/engine/_utils/view.js';
- import Element from '/ckeditor5/engine/treeview/element.js';
- import AttributeElement from '/ckeditor5/engine/treeview/attributeelement.js';
- import ContainerElement from '/ckeditor5/engine/treeview/containerelement.js';
- import Text from '/ckeditor5/engine/treeview/text.js';
- import Selection from '/ckeditor5/engine/treeview/selection.js';
- import Range from '/ckeditor5/engine/treeview/range.js';
- describe( 'view test utils', () => {
- describe( 'getData', () => {
- it( 'should write elements and texts', () => {
- const text = new Text( 'foobar' );
- const b = new Element( 'b', null, text );
- const p = new Element( 'p', null, b );
- expect( getData( p ) ).to.equal( '<p><b>foobar</b></p>' );
- } );
- it( 'should write elements with attributes', () => {
- const text = new Text( 'foobar' );
- const b = new Element( 'b', {
- foo: 'bar'
- }, text );
- const p = new Element( 'p', {
- baz: 'qux',
- bar: 'taz',
- class: 'short wide'
- }, b );
- expect( getData( p ) ).to.equal( '<p class="short wide" baz="qux" bar="taz"><b foo="bar">foobar</b></p>' );
- } );
- it( 'should write selection ranges inside elements', () => {
- const text1 = new Text( 'foobar' );
- const text2 = new Text( 'bazqux' );
- const b1 = new Element( 'b', null, text1 );
- const b2 = new Element( 'b', null, text2 );
- const p = new Element( 'p', null, [ b1, b2 ] );
- const range = Range.createFromParentsAndOffsets( p, 1, p, 2 );
- const selection = new Selection();
- selection.addRange( range );
- expect( getData( p, selection ) ).to.equal( '<p><b>foobar</b>[<b>bazqux</b>]</p>' );
- } );
- it( 'should write collapsed selection ranges inside elements', () => {
- const text = new Text( 'foobar' );
- const p = new Element( 'p', null, text );
- const range = Range.createFromParentsAndOffsets( p, 0, p, 0 );
- const selection = new Selection();
- selection.addRange( range );
- expect( getData( p, selection ) ).to.equal( '<p>[]foobar</p>' );
- } );
- it( 'should write selection ranges inside text', () => {
- const text1 = new Text( 'foobar' );
- const text2 = new Text( 'bazqux' );
- const b1 = new Element( 'b', null, text1 );
- const b2 = new Element( 'b', null, text2 );
- const p = new Element( 'p', null, [ b1, b2 ] );
- const range = Range.createFromParentsAndOffsets( text1, 1, text1, 5 );
- const selection = new Selection();
- selection.addRange( range );
- expect( getData( p, selection ) ).to.equal( '<p><b>f{ooba}r</b><b>bazqux</b></p>' );
- } );
- it( 'should write ranges that start inside text end ends between elements', () => {
- const text1 = new Text( 'foobar' );
- const text2 = new Text( 'bazqux' );
- const b1 = new Element( 'b', null, text1 );
- const b2 = new Element( 'b', null, text2 );
- const p = new Element( 'p', null, [ b1, b2 ] );
- const range = Range.createFromParentsAndOffsets( p, 0, text2, 5 );
- const selection = new Selection();
- selection.addRange( range );
- expect( getData( p, selection ) ).to.equal( '<p>[<b>foobar</b><b>bazqu}x</b></p>' );
- } );
- it( 'should write elements types as namespaces when needed', () => {
- const text = new Text( 'foobar' );
- const b = new AttributeElement( 'b', null, text );
- const p = new ContainerElement( 'p', null, b );
- expect( getData( p, null, { showTypes: true } ) )
- .to.equal( '<container:p><attribute:b>foobar</attribute:b></container:p>' );
- } );
- } );
- } );
|