| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- describe('Core_onKeyDown', () => {
- var id = 'testContainer';
- beforeEach(function() {
- this.$container = $(`<div id="${id}"></div>`).appendTo('body');
- });
- afterEach(function() {
- if (this.$container) {
- destroy();
- this.$container.remove();
- }
- });
- it('should advance to next cell when TAB is pressed', () => {
- // https://github.com/handsontable/handsontable/issues/151
- handsontable();
- selectCell(0, 0);
- keyDownUp('tab');
- expect(getSelected()).toEqual([0, 1, 0, 1]);
- });
- it('should advance to previous cell when shift+TAB is pressed', () => {
- handsontable();
- selectCell(1, 1);
- keyDownUp('shift+tab');
- expect(getSelected()).toEqual([1, 0, 1, 0]);
- });
- describe('while editing (quick edit mode)', () => {
- it('should finish editing and advance to next cell when TAB is pressed', () => {
- // https://github.com/handsontable/handsontable/issues/215
- handsontable();
- selectCell(1, 1);
- keyDownUp('x'); // value to cell trigger quick edit mode
- keyProxy().val('Ted');
- keyDownUp('tab');
- expect(getData()[1][1]).toEqual('Ted');
- expect(getSelected()).toEqual([1, 2, 1, 2]);
- });
- it('should finish editing and advance to lower cell when enter is pressed', () => {
- // https://github.com/handsontable/handsontable/issues/215
- handsontable();
- selectCell(1, 1);
- keyDownUp('x'); // value to cell trigger quick edit mode
- keyProxy().val('Ted');
- keyDownUp('enter');
- expect(getData()[1][1]).toEqual('Ted');
- expect(getSelected()).toEqual([2, 1, 2, 1]);
- });
- it('should finish editing and advance to higher cell when shift+enter is pressed', () => {
- // https://github.com/handsontable/handsontable/issues/215
- handsontable();
- selectCell(1, 1);
- keyDownUp('x'); // trigger quick edit mode
- keyProxy().val('Ted');
- keyDownUp('shift+enter');
- expect(getData()[1][1]).toEqual('Ted');
- expect(getSelected()).toEqual([0, 1, 0, 1]);
- });
- it('should finish editing and advance to lower cell when down arrow is pressed', () => {
- handsontable();
- selectCell(1, 1);
- keyDownUp('x');
- keyProxy().val('Ted');
- keyDownUp('arrow_down');
- expect(getData()[1][1]).toEqual('Ted');
- expect(getSelected()).toEqual([2, 1, 2, 1]);
- });
- it('should finish editing and advance to higher cell when up arrow is pressed', () => {
- handsontable();
- selectCell(1, 1);
- keyDownUp('x');
- keyProxy().val('Ted');
- keyDownUp('arrow_up');
- expect(getData()[1][1]).toEqual('Ted');
- expect(getSelected()).toEqual([0, 1, 0, 1]);
- });
- it('should finish editing and advance to right cell when right arrow is pressed', () => {
- handsontable();
- selectCell(1, 1);
- keyDownUp('x');
- keyProxy().val('Ted');
- keyDownUp('arrow_right');
- keyDownUp('arrow_right');
- keyDownUp('arrow_right');
- keyDownUp('arrow_right');
- expect(getData()[1][1]).toEqual('Ted');
- expect(getSelected()).toEqual([1, 4, 1, 4]);
- });
- it('should finish editing and advance to left cell when left arrow is pressed', () => {
- handsontable();
- selectCell(1, 1);
- keyDownUp('x');
- keyProxy().val('Ted');
- Handsontable.dom.setCaretPosition(keyProxy()[0], 0, 0);
- keyDownUp('arrow_left');
- keyDownUp('arrow_left');
- keyDownUp('arrow_left');
- keyDownUp('arrow_left');
- keyDownUp('arrow_left');
- expect(getData()[1][1]).toEqual('Ted');
- expect(getSelected()).toEqual([1, 0, 1, 0]);
- });
- it('should finish editing and advance to lower cell when enter is pressed (with sync validator)', (done) => {
- var onAfterValidate = jasmine.createSpy('onAfterValidate');
- handsontable({
- validator(val, cb) {
- cb(true);
- },
- afterValidate: onAfterValidate
- });
- selectCell(1, 1);
- keyDownUp('x');
- keyProxy().val('Ted');
- onAfterValidate.calls.reset();
- keyDownUp('enter');
- setTimeout(() => {
- expect(onAfterValidate).toHaveBeenCalled();
- expect(getData()[1][1]).toEqual('Ted');
- expect(getSelected()).toEqual([2, 1, 2, 1]);
- done();
- }, 200);
- });
- it('should finish editing and advance to lower cell when enter is pressed (with async validator)', (done) => {
- var onAfterValidate = jasmine.createSpy('onAfterValidate');
- handsontable({
- validator(val, cb) {
- setTimeout(() => {
- cb(true);
- }, 10);
- },
- afterValidate: onAfterValidate
- });
- selectCell(1, 1);
- keyDownUp('x');
- keyProxy().val('Ted');
- onAfterValidate.calls.reset();
- keyDownUp('enter');
- setTimeout(() => {
- expect(onAfterValidate).toHaveBeenCalled();
- expect(getData()[1][1]).toEqual('Ted');
- expect(getSelected()).toEqual([2, 1, 2, 1]);
- done();
- }, 200);
- });
- });
- describe('while editing (full edit mode)', () => {
- it('should finish editing and advance to next cell when TAB is pressed', () => {
- // https://github.com/handsontable/handsontable/issues/215
- handsontable();
- selectCell(1, 1);
- keyDownUp('enter');
- keyProxy().val('Ted');
- keyDownUp('tab');
- expect(getData()[1][1]).toEqual('Ted');
- expect(getSelected()).toEqual([1, 2, 1, 2]);
- });
- it('should finish editing and advance to lower cell when enter is pressed', () => {
- // https://github.com/handsontable/handsontable/issues/215
- handsontable();
- selectCell(1, 1);
- keyDownUp('enter');
- keyProxy().val('Ted');
- keyDownUp('enter');
- expect(getData()[1][1]).toEqual('Ted');
- expect(getSelected()).toEqual([2, 1, 2, 1]);
- });
- it('should finish editing and advance to higher cell when shift+enter is pressed', () => {
- // https://github.com/handsontable/handsontable/issues/215
- handsontable();
- selectCell(1, 1);
- keyDownUp('enter');
- keyProxy().val('Ted');
- keyDownUp('shift+enter');
- expect(getData()[1][1]).toEqual('Ted');
- expect(getSelected()).toEqual([0, 1, 0, 1]);
- });
- it('shouldn\'t finish editing and advance to lower cell when down arrow is pressed', () => {
- handsontable();
- selectCell(1, 1);
- keyDownUp('enter');
- keyProxy().val('Ted');
- keyDownUp('arrow_down');
- expect(getData()[1][1]).toEqual(null);
- expect(getSelected()).toEqual([1, 1, 1, 1]);
- });
- it('shouldn\'t finish editing and advance to higher cell when up arrow is pressed', () => {
- handsontable();
- selectCell(1, 1);
- keyDownUp('enter');
- keyProxy().val('Ted');
- keyDownUp('arrow_up');
- expect(getData()[1][1]).toEqual(null);
- expect(getSelected()).toEqual([1, 1, 1, 1]);
- });
- it('shouldn\'t finish editing and advance to right cell when right arrow is pressed', () => {
- handsontable();
- selectCell(1, 1);
- keyDownUp('enter');
- keyProxy().val('Ted');
- keyDownUp('arrow_right');
- keyDownUp('arrow_right');
- keyDownUp('arrow_right');
- keyDownUp('arrow_right');
- expect(getData()[1][1]).toEqual(null);
- expect(getSelected()).toEqual([1, 1, 1, 1]);
- });
- it('shouldn\'t finish editing and advance to left cell when left arrow is pressed', () => {
- handsontable();
- selectCell(1, 1);
- keyDownUp('enter');
- keyProxy().val('Ted');
- keyDownUp('arrow_left');
- keyDownUp('arrow_left');
- keyDownUp('arrow_left');
- keyDownUp('arrow_left');
- expect(getData()[1][1]).toEqual(null);
- expect(getSelected()).toEqual([1, 1, 1, 1]);
- });
- it('should finish editing and advance to lower cell when enter is pressed (with sync validator)', (done) => {
- var onAfterValidate = jasmine.createSpy('onAfterValidate');
- handsontable({
- validator(val, cb) {
- cb(true);
- },
- afterValidate: onAfterValidate
- });
- selectCell(1, 1);
- keyDownUp('enter');
- keyProxy().val('Ted');
- onAfterValidate.calls.reset();
- keyDownUp('enter');
- setTimeout(() => {
- expect(onAfterValidate).toHaveBeenCalled();
- expect(getData()[1][1]).toEqual('Ted');
- expect(getSelected()).toEqual([2, 1, 2, 1]);
- done();
- }, 200);
- });
- it('should finish editing and advance to lower cell when enter is pressed (with async validator)', (done) => {
- var onAfterValidate = jasmine.createSpy('onAfterValidate');
- handsontable({
- validator(val, cb) {
- setTimeout(() => {
- cb(true);
- }, 10);
- },
- afterValidate: onAfterValidate
- });
- selectCell(1, 1);
- keyDownUp('enter');
- keyProxy().val('Ted');
- onAfterValidate.calls.reset();
- keyDownUp('enter');
- setTimeout(() => {
- expect(onAfterValidate).toHaveBeenCalled();
- expect(getData()[1][1]).toEqual('Ted');
- expect(getSelected()).toEqual([2, 1, 2, 1]);
- done();
- }, 200);
- });
- });
- });
|