9385b6391453946db18915926b397d412e2befb88a64f7713ecf87aab8d40f7e04e87ecacb99fb09556c5f7969026052aa62be28a50da2d4c282e6e5021e6f 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. describe('Core_listen', () => {
  2. var id = 'testContainer';
  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 listen to changes when cell is selected', () => {
  13. var hot = handsontable();
  14. hot.selectCell(0, 0);
  15. expect(hot.isListening()).toEqual(true);
  16. });
  17. it('should\'t listen to changes when cell is selected via `selectCell` when `changeListener` argument is `false`', () => {
  18. var hot = handsontable();
  19. hot.unlisten();
  20. expect(hot.isListening()).toEqual(false);
  21. hot.selectCell(0, 0, undefined, undefined, true, false);
  22. expect(hot.isListening()).toEqual(false);
  23. });
  24. it('should unlisten changes', () => {
  25. var hot = handsontable();
  26. hot.selectCell(0, 0);
  27. expect(hot.isListening()).toEqual(true);
  28. hot.unlisten();
  29. expect(hot.isListening()).toEqual(false);
  30. });
  31. it('should listen to changes, when called after unlisten', () => {
  32. var hot = handsontable();
  33. hot.selectCell(0, 0);
  34. hot.unlisten();
  35. hot.listen();
  36. expect(hot.isListening()).toEqual(true);
  37. });
  38. it('when second instance is created, first should unlisten automatically', () => {
  39. var $container1 = $('<div id="hot1"></div>').appendTo('body').handsontable();
  40. $container1.handsontable('selectCell', 0, 0);
  41. var $container2 = $('<div id="hot2"></div>').appendTo('body').handsontable();
  42. $container2.handsontable('selectCell', 0, 0);
  43. expect($container1.handsontable('isListening')).toEqual(false);
  44. expect($container2.handsontable('isListening')).toEqual(true);
  45. $container1.handsontable('destroy');
  46. $container1.remove();
  47. $container2.handsontable('destroy');
  48. $container2.remove();
  49. });
  50. it('when listen is called on first instance, second should unlisten automatically', () => {
  51. var $container1 = $('<div id="hot1"></div>').appendTo('body').handsontable();
  52. $container1.handsontable('selectCell', 0, 0);
  53. var $container2 = $('<div id="hot2"></div>').appendTo('body').handsontable();
  54. $container2.handsontable('selectCell', 0, 0);
  55. $container1.handsontable('listen');
  56. expect($container1.handsontable('isListening')).toEqual(true);
  57. expect($container2.handsontable('isListening')).toEqual(false);
  58. $container1.handsontable('destroy');
  59. $container1.remove();
  60. $container2.handsontable('destroy');
  61. $container2.remove();
  62. });
  63. });