events.spec.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. const id = 'testContainer';
  2. describe('Events', () => {
  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 translate tap (`touchstart`) to `mousedown`', async() => {
  13. const afterOnCellMouseDown = jasmine.createSpy('onAfterOnCellMouseDown');
  14. const hot = handsontable({
  15. width: 400,
  16. height: 400,
  17. afterOnCellMouseDown
  18. });
  19. const cell = hot.getCell(1, 1);
  20. expect(getSelected()).toBeUndefined();
  21. triggerTouchEvent('touchstart', cell);
  22. await sleep(100);
  23. expect(getSelected()).toBeDefined();
  24. expect(afterOnCellMouseDown).toHaveBeenCalled();
  25. });
  26. // Currently, this test is skipped. There is a problem for test canceling events from simulated events.
  27. xit('should block default action related to link touch and translate from the touch to click on a cell', async() => {
  28. const hot = handsontable({
  29. data: [['<a href="#justForTest">click me!</a>'], []],
  30. rowHeaders: true,
  31. colHeaders: true,
  32. width: 600,
  33. height: 400,
  34. columns: [
  35. {
  36. renderer: 'html'
  37. }
  38. ]
  39. });
  40. const linkElement = hot.getCell(0, 0).firstChild;
  41. hot.selectCell(0, 0);
  42. location.hash = '';
  43. await sleep(100);
  44. triggerTouchEvent('touchstart', linkElement);
  45. triggerTouchEvent('touchend', linkElement);
  46. expect(location.hash).toBe('#justForTest');
  47. await sleep(400); // To prevents double-click detection (emulation)
  48. location.hash = '';
  49. // selecting cell other than the one with link
  50. hot.selectCell(1, 0);
  51. await sleep(100);
  52. triggerTouchEvent('touchstart', linkElement);
  53. triggerTouchEvent('touchend', linkElement);
  54. expect(location.hash).toBe('');
  55. });
  56. });