getSelectedRange.spec.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. describe('Core.getSelectedRange', () => {
  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(getSelectedRange().map(cellRange => cellRange.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(getSelectedRange().map(cellRange => cellRange.toObject())).toEqual([snapshot[0], snapshot[1]]);
  31. $(getCell(2, 4)).simulate('mousedown');
  32. $(getCell(2, 4)).simulate('mouseover');
  33. $(getCell(2, 4)).simulate('mouseup');
  34. expect(getSelectedRange().map(cellRange => cellRange.toObject())).toEqual([snapshot[0], snapshot[1], snapshot[2]]);
  35. $(getCell(7, 6)).simulate('mousedown');
  36. $(getCell(8, 7)).simulate('mouseover');
  37. $(getCell(8, 7)).simulate('mouseup');
  38. const selectedRange = getSelectedRange().map(cellRange => cellRange.toObject());
  39. expect(selectedRange).toEqual(snapshot);
  40. });
  41. });