| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- describe('Core_listen', () => {
- var id = 'testContainer';
- beforeEach(function() {
- this.$container = $(`<div id="${id}"></div>`).appendTo('body');
- });
- afterEach(function() {
- if (this.$container) {
- destroy();
- this.$container.remove();
- }
- });
- it('should listen to changes when cell is selected', () => {
- var hot = handsontable();
- hot.selectCell(0, 0);
- expect(hot.isListening()).toEqual(true);
- });
- it('should\'t listen to changes when cell is selected via `selectCell` when `changeListener` argument is `false`', () => {
- var hot = handsontable();
- hot.unlisten();
- expect(hot.isListening()).toEqual(false);
- hot.selectCell(0, 0, undefined, undefined, true, false);
- expect(hot.isListening()).toEqual(false);
- });
- it('should unlisten changes', () => {
- var hot = handsontable();
- hot.selectCell(0, 0);
- expect(hot.isListening()).toEqual(true);
- hot.unlisten();
- expect(hot.isListening()).toEqual(false);
- });
- it('should listen to changes, when called after unlisten', () => {
- var hot = handsontable();
- hot.selectCell(0, 0);
- hot.unlisten();
- hot.listen();
- expect(hot.isListening()).toEqual(true);
- });
- it('when second instance is created, first should unlisten automatically', () => {
- var $container1 = $('<div id="hot1"></div>').appendTo('body').handsontable();
- $container1.handsontable('selectCell', 0, 0);
- var $container2 = $('<div id="hot2"></div>').appendTo('body').handsontable();
- $container2.handsontable('selectCell', 0, 0);
- expect($container1.handsontable('isListening')).toEqual(false);
- expect($container2.handsontable('isListening')).toEqual(true);
- $container1.handsontable('destroy');
- $container1.remove();
- $container2.handsontable('destroy');
- $container2.remove();
- });
- it('when listen is called on first instance, second should unlisten automatically', () => {
- var $container1 = $('<div id="hot1"></div>').appendTo('body').handsontable();
- $container1.handsontable('selectCell', 0, 0);
- var $container2 = $('<div id="hot2"></div>').appendTo('body').handsontable();
- $container2.handsontable('selectCell', 0, 0);
- $container1.handsontable('listen');
- expect($container1.handsontable('isListening')).toEqual(true);
- expect($container2.handsontable('isListening')).toEqual(false);
- $container1.handsontable('destroy');
- $container1.remove();
- $container2.handsontable('destroy');
- $container2.remove();
- });
- });
|