| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- /**
- * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* bender-tags: treeview */
- /* bender-include: ../_tools/tools.js */
- 'use strict';
- const modules = bender.amd.require(
- 'core/treeview/element',
- 'core/treeview/rootelement',
- 'core/treeview/node',
- 'core/treeview/text',
- 'core/ckeditorerror'
- );
- describe( 'Node', () => {
- let Element, Text, Node, RootElement, CKEditorError;
- let root;
- let one, two, three;
- let charB, charA, charR, img;
- before( () => {
- Element = modules[ 'core/treeview/element' ];
- Node = modules[ 'core/treeview/node' ];
- Text = modules[ 'core/treeview/text' ];
- CKEditorError = modules[ 'ckeditorerror ' ];
- RootElement = modules[ 'core/treeview/rootelement' ];
- charB = new Text( 'b' );
- charA = new Text( 'a' );
- img = new Element( 'img' );
- charR = new Text( 'r' );
- one = new Element( 'one' );
- two = new Element( 'two', null, [ charB, charA, img, charR ] );
- three = new Element( 'three' );
- root = new Element( null, null, [ one, two, three ] );
- } );
- describe( 'getNextSibling/getPreviousSibling', () => {
- it( 'should return next sibling', () => {
- expect( root.getNextSibling() ).to.be.null;
- expect( one.getNextSibling() ).to.equal( two );
- expect( two.getNextSibling() ).to.equal( three );
- expect( three.getNextSibling() ).to.be.null;
- expect( charB.getNextSibling() ).to.equal( charA );
- expect( charA.getNextSibling() ).to.equal( img );
- expect( img.getNextSibling() ).to.equal( charR );
- expect( charR.getNextSibling() ).to.be.null;
- } );
- it( 'should return previous sibling', () => {
- expect( root.getPreviousSibling() ).to.be.null;
- expect( one.getPreviousSibling() ).to.be.null;
- expect( two.getPreviousSibling() ).to.equal( one );
- expect( three.getPreviousSibling() ).to.equal( two );
- expect( charB.getPreviousSibling() ).to.be.null;
- expect( charA.getPreviousSibling() ).to.equal( charB );
- expect( img.getPreviousSibling() ).to.equal( charA );
- expect( charR.getPreviousSibling() ).to.equal( img );
- } );
- } );
- describe( 'getIndex', () => {
- it( 'should return null if the parent is null', () => {
- expect( root.getIndex() ).to.be.null;
- } );
- it( 'should return index in the parent', () => {
- expect( one.getIndex() ).to.equal( 0 );
- expect( two.getIndex() ).to.equal( 1 );
- expect( three.getIndex() ).to.equal( 2 );
- expect( charB.getIndex() ).to.equal( 0 );
- expect( charA.getIndex() ).to.equal( 1 );
- expect( img.getIndex() ).to.equal( 2 );
- expect( charR.getIndex() ).to.equal( 3 );
- } );
- it( 'should throw an error if parent does not contains element', () => {
- let f = new Text( 'f' );
- let bar = new Element( 'bar', [], [] );
- f.parent = bar;
- expect(
- () => {
- f.getIndex();
- }
- ).to.throw( CKEditorError, /treeview-node-not-found-in-parent/ );
- } );
- } );
- describe( 'getTreeView', () => {
- it( 'should return null if root is not a RootElement', () => {
- expect( charA.getTreeView() ).to.be.null;
- } );
- it( 'should return TreeView attached to the RootElement', () => {
- const tvMock = {};
- const parent = new RootElement( 'div', tvMock );
- const child = new Element( 'p' );
- child.parent = parent;
- expect( parent.getTreeView() ).to.equal( tvMock );
- expect( child.getTreeView() ).to.equal( tvMock );
- } );
- } );
- } );
|