position.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 Position from '/ckeditor5/core/treeview/position.js';
  8. describe( 'Position', () => {
  9. const parentMock = {};
  10. describe( 'constructor', () => {
  11. it( 'should create element without attributes', () => {
  12. const elem = new Position( parentMock, 5 );
  13. expect( elem ).to.have.property( 'parent' ).that.equals( parentMock );
  14. expect( elem ).to.have.property( 'offset' ).that.equals( 5 );
  15. } );
  16. } );
  17. describe( 'getShiftedBy', () => {
  18. it( 'returns new instance with shifted offset', () => {
  19. const position = new Position( parentMock, 10 );
  20. const shifted = position.getShiftedBy( 12 );
  21. expect( shifted.offset ).to.equal( 22 );
  22. } );
  23. it( 'accepts negative values', () => {
  24. const position = new Position( parentMock, 10 );
  25. const shifted = position.getShiftedBy( -5 );
  26. expect( shifted.offset ).to.equal( 5 );
  27. } );
  28. it( 'prevents offset to be a negative value', () => {
  29. const position = new Position( parentMock, 10 );
  30. const shifted = position.getShiftedBy( -20 );
  31. expect( shifted.offset ).to.equal( 0 );
  32. } );
  33. } );
  34. describe( 'createFromPosition', () => {
  35. it( 'creates new Position with same parent and offset', () => {
  36. const offset = 50;
  37. const position = new Position( parentMock, offset );
  38. const newPosition = Position.createFromPosition( position );
  39. expect( position ).to.not.equal( newPosition );
  40. expect( position.offset ).to.equal( offset );
  41. expect( position.parent ).to.equal( parentMock );
  42. } );
  43. } );
  44. } );