getSelectedRangeLast.spec.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. describe('Core.getSelectedRangeLast', () => {
  2. beforeEach(function() {
  3. this.$container = $('<div id="testContainer"></div>').appendTo('body');
  4. });
  5. afterEach(function() {
  6. if (this.$container) {
  7. destroy();
  8. this.$container.remove();
  9. }
  10. });
  11. it('should return valid coordinates', () => {
  12. handsontable({
  13. data: Handsontable.helper.createSpreadsheetObjectData(10, 10),
  14. selectionMode: 'multiple',
  15. });
  16. const snapshot = [
  17. { from: { row: 5, col: 4 }, to: { row: 1, col: 1 } },
  18. { from: { row: 2, col: 2 }, to: { row: 7, col: 2 } },
  19. { from: { row: 2, col: 4 }, to: { row: 2, col: 4 } },
  20. { from: { row: 7, col: 6 }, to: { row: 8, col: 7 } },
  21. ];
  22. $(getCell(5, 4)).simulate('mousedown');
  23. $(getCell(1, 1)).simulate('mouseover');
  24. $(getCell(1, 1)).simulate('mouseup');
  25. expect(getSelectedRangeLast().toObject()).toEqual(snapshot[0]);
  26. keyDown('ctrl');
  27. $(getCell(2, 2)).simulate('mousedown');
  28. $(getCell(7, 2)).simulate('mouseover');
  29. $(getCell(7, 2)).simulate('mouseup');
  30. expect(getSelectedRangeLast().toObject()).toEqual(snapshot[1]);
  31. $(getCell(2, 4)).simulate('mousedown');
  32. $(getCell(2, 4)).simulate('mouseover');
  33. $(getCell(2, 4)).simulate('mouseup');
  34. expect(getSelectedRangeLast().toObject()).toEqual(snapshot[2]);
  35. $(getCell(7, 6)).simulate('mousedown');
  36. $(getCell(8, 7)).simulate('mouseover');
  37. $(getCell(8, 7)).simulate('mouseup');
  38. expect(getSelectedRangeLast().toObject()).toEqual(snapshot[3]);
  39. });
  40. });