selection.spec.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const id = 'testContainer';
  2. describe('Selection', () => {
  3. beforeEach(function() {
  4. this.$container = $(`<div id="${id}"></div>`).appendTo('body');
  5. });
  6. afterEach(function() {
  7. if (this.$container) {
  8. destroy();
  9. this.$container.remove();
  10. }
  11. });
  12. it('should show selection handles', () => {
  13. const hot = handsontable({
  14. width: 400,
  15. height: 400
  16. });
  17. hot.selectCell(1, 1);
  18. const topLeftSelectionHandle = spec().$container.find('.ht_master .htBorders div:first-child .topLeftSelectionHandle')[0];
  19. const bottomRightSelectionHandle = spec().$container.find('.ht_master .htBorders div:first-child .bottomRightSelectionHandle')[0];
  20. expect(topLeftSelectionHandle.style.display).toEqual('block');
  21. expect(bottomRightSelectionHandle.style.display).toEqual('block');
  22. });
  23. it('should show both selection handles after drag & drop', async() => {
  24. const hot = handsontable({
  25. width: 400,
  26. height: 400
  27. });
  28. hot.selectCell(1, 1);
  29. await sleep(100);
  30. triggerTouchEvent('touchstart', spec().$container.find('.htBorders .bottomRightSelectionHandle-HitArea')[0]);
  31. triggerTouchEvent('touchmove', spec().$container.find('tbody tr:eq(1) td:eq(2)')[0]);
  32. triggerTouchEvent('touchmove', spec().$container.find('tbody tr:eq(1) td:eq(3)')[0]);
  33. triggerTouchEvent('touchend', spec().$container.find('tbody tr:eq(1) td:eq(3)')[0]);
  34. await sleep(100);
  35. const topLeftSelectionHandle = spec().$container.find('.ht_master .htBorders div:last-child .topLeftSelectionHandle')[0];
  36. const bottomRightSelectionHandle = spec().$container.find('.ht_master .htBorders div:last-child .bottomRightSelectionHandle')[0];
  37. expect(topLeftSelectionHandle.style.display).toBe('block');
  38. expect(bottomRightSelectionHandle.style.display).toBe('block');
  39. expect(hot.getSelected()).toEqual([[1, 1, 1, 2]]);
  40. });
  41. it('should not call the `select` method on the "focusable" textarea when selecting a cell', async() => {
  42. const hot = handsontable({
  43. data: [['test']],
  44. width: 400,
  45. height: 400
  46. });
  47. hot.selectCell(0, 0);
  48. const copyPastePlugin = hot.getPlugin('copyPaste');
  49. const focusableElement = copyPastePlugin.focusableElement.getFocusableElement();
  50. spyOn(focusableElement, 'select');
  51. hot.selectCell(0, 0);
  52. expect(focusableElement.select).not.toHaveBeenCalled();
  53. });
  54. });