8
0

attributeelement.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: treeview */
  6. 'use strict';
  7. import AttributeElement from '/ckeditor5/engine/treeview/attributeelement.js';
  8. import Element from '/ckeditor5/engine/treeview/element.js';
  9. import { DEFAULT_PRIORITY } from '/ckeditor5/engine/treeview/attributeelement.js';
  10. import { parse } from '/tests/engine/_utils/view.js';
  11. describe( 'AttributeElement', () => {
  12. describe( 'constructor', () => {
  13. it( 'should create element with default priority', () => {
  14. const el = new AttributeElement( 'strong' );
  15. expect( el ).to.be.an.instanceof( AttributeElement );
  16. expect( el ).to.be.an.instanceof( Element );
  17. expect( el ).to.have.property( 'name' ).that.equals( 'strong' );
  18. expect( el ).to.have.property( 'priority' ).that.equals( DEFAULT_PRIORITY );
  19. } );
  20. } );
  21. describe( 'clone', () => {
  22. it( 'should clone element with priority', () => {
  23. const el = new AttributeElement( 'b' );
  24. el.priority = 7;
  25. const clone = el.clone();
  26. expect( clone ).to.not.equal( el );
  27. expect( clone.name ).to.equal( el.name );
  28. expect( clone.priority ).to.equal( el.priority );
  29. } );
  30. } );
  31. describe( 'isSimilar', () => {
  32. it( 'should return true if priorities are the same', () => {
  33. const b1 = new AttributeElement( 'b' );
  34. b1.priority = 7;
  35. const b2 = new AttributeElement( 'b' );
  36. b2.priority = 7;
  37. expect( b1.isSimilar( b2 ) ).to.be.true;
  38. } );
  39. it( 'should return false if priorities are different', () => {
  40. const b1 = new AttributeElement( 'b' );
  41. b1.priority = 7;
  42. const b2 = new AttributeElement( 'b' ); // default priority
  43. expect( b1.isSimilar( b2 ) ).to.be.false;
  44. } );
  45. } );
  46. describe( 'getBlockFillerOffset', () => {
  47. it( 'should return position 0 if it is the only element in the container', () => {
  48. const { selection } = parse( '<container:p><attribute:b>[]</attribute:b></container:p>' );
  49. const attribute = selection.getFirstPosition().parent;
  50. expect( attribute.getBlockFillerOffset() ).to.equals( 0 );
  51. } );
  52. it( 'should return position 0 if it is the only nested element in the container', () => {
  53. const { selection } = parse(
  54. '<container:p><attribute:b><attribute:i>[]</attribute:i></attribute:b></container:p>' );
  55. const attribute = selection.getFirstPosition().parent;
  56. expect( attribute.getBlockFillerOffset() ).to.equals( 0 );
  57. } );
  58. it( 'should return null if element contains another element', () => {
  59. const attribute = parse( '<attribute:b><attribute:i></attribute:i></attribute:b>' );
  60. expect( attribute.getBlockFillerOffset() ).to.be.null;
  61. } );
  62. it( 'should return null if element contains text', () => {
  63. const attribute = parse( '<attribute:b>text</attribute:b>' );
  64. expect( attribute.getBlockFillerOffset() ).to.be.null;
  65. } );
  66. it( 'should return null if container element contains text', () => {
  67. const { selection } = parse( '<container:p><attribute:b>[]</attribute:b>foo</container:p>' );
  68. const attribute = selection.getFirstPosition().parent;
  69. expect( attribute.getBlockFillerOffset() ).to.be.null;
  70. } );
  71. it( 'should return null if it is the parent contains text', () => {
  72. const { selection } = parse(
  73. '<container:p><attribute:b><attribute:i>[]</attribute:i>foo</attribute:b></container:p>' );
  74. const attribute = selection.getFirstPosition().parent;
  75. expect( attribute.getBlockFillerOffset() ).to.be.null;
  76. } );
  77. } );
  78. } );