cellspans.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import CellSpans from '../src/cellspans';
  6. describe( 'CellSpans', () => {
  7. let cellSpans;
  8. beforeEach( () => {
  9. cellSpans = new CellSpans();
  10. } );
  11. describe( 'recordSpans()', () => {
  12. it( 'should record spans relatively to a provided cell index with proper cellspan value', () => {
  13. cellSpans.recordSpans( 0, 0, 2, 2 );
  14. expect( cellSpans._spans.size ).to.equal( 1 );
  15. expect( cellSpans._spans.has( 1 ) ).to.be.true;
  16. expect( cellSpans._spans.get( 1 ).size ).to.equal( 1 );
  17. expect( cellSpans._spans.get( 1 ).get( 0 ) ).to.equal( 2 );
  18. } );
  19. it( 'should record spans for the same row in the same map', () => {
  20. cellSpans.recordSpans( 0, 0, 2, 2 );
  21. cellSpans.recordSpans( 0, 3, 2, 7 );
  22. expect( cellSpans._spans.has( 1 ) ).to.be.true;
  23. expect( cellSpans._spans.get( 1 ).size ).to.equal( 2 );
  24. expect( cellSpans._spans.get( 1 ).get( 3 ) ).to.equal( 7 );
  25. } );
  26. } );
  27. describe( 'drop()', () => {
  28. it( 'should remove rows', () => {
  29. cellSpans.recordSpans( 0, 0, 4, 1 );
  30. expect( cellSpans._spans.size ).to.equal( 3 );
  31. expect( cellSpans._spans.has( 0 ) ).to.be.false;
  32. expect( cellSpans._spans.has( 1 ) ).to.be.true;
  33. expect( cellSpans._spans.has( 2 ) ).to.be.true;
  34. expect( cellSpans._spans.has( 3 ) ).to.be.true;
  35. expect( cellSpans._spans.has( 4 ) ).to.be.false;
  36. cellSpans.drop( 2 );
  37. expect( cellSpans._spans.size ).to.equal( 2 );
  38. expect( cellSpans._spans.has( 0 ) ).to.be.false;
  39. expect( cellSpans._spans.has( 1 ) ).to.be.true;
  40. expect( cellSpans._spans.has( 2 ) ).to.be.false;
  41. expect( cellSpans._spans.has( 3 ) ).to.be.true;
  42. } );
  43. it( 'should do nothing if there was no spans recoreder', () => {
  44. cellSpans.recordSpans( 0, 0, 3, 1 );
  45. expect( cellSpans._spans.size ).to.equal( 2 );
  46. cellSpans.drop( 1 );
  47. expect( cellSpans._spans.size ).to.equal( 1 );
  48. cellSpans.drop( 1 );
  49. expect( cellSpans._spans.size ).to.equal( 1 );
  50. } );
  51. } );
  52. describe( 'getNextFreeColumnIndex()', () => {
  53. it( 'should return the same column index as provided when no spans recorded', () => {
  54. expect( cellSpans.getAdjustedColumnIndex( 1, 1 ) ).to.equal( 1 );
  55. } );
  56. it( 'should return adjusted column index by the size of overlaping rowspan', () => {
  57. cellSpans.recordSpans( 0, 1, 2, 8 );
  58. expect( cellSpans.getAdjustedColumnIndex( 1, 1 ) ).to.equal( 9 );
  59. } );
  60. } );
  61. } );