123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- describe('HandsontableEditor', () => {
- var id = 'testContainer';
- beforeEach(function() {
- this.$container = $(`<div id="${id}"></div>`).appendTo('body');
- });
- afterEach(function() {
- if (this.$container) {
- destroy();
- this.$container.remove();
- }
- });
- function getManufacturerData() {
- return [
- {name: 'BMW', country: 'Germany', owner: 'Bayerische Motoren Werke AG'},
- {name: 'Chrysler', country: 'USA', owner: 'Chrysler Group LLC'},
- {name: 'Nissan', country: 'Japan', owner: 'Nissan Motor Company Ltd'},
- {name: 'Suzuki', country: 'Japan', owner: 'Suzuki Motor Corporation'},
- {name: 'Toyota', country: 'Japan', owner: 'Toyota Motor Corporation'},
- {name: 'Volvo', country: 'Sweden', owner: 'Zhejiang Geely Holding Group'}
- ];
- }
- it('should create an editor that is a Handsontable instance', function() {
- handsontable({
- columns: [
- {
- type: 'handsontable',
- handsontable: {
- colHeaders: ['Marque', 'Country', 'Parent company'],
- data: getManufacturerData()
- }
- }
- ]
- });
- selectCell(2, 0);
- keyDownUp('enter');
- expect(this.$container.find('.handsontableEditor:visible').length).toEqual(1);
- });
- it('should destroy the editor when Esc is pressed', function() {
- handsontable({
- columns: [
- {
- type: 'handsontable',
- handsontable: {
- colHeaders: ['Marque', 'Country', 'Parent company'],
- data: getManufacturerData()
- }
- }
- ]
- });
- selectCell(2, 0);
- keyDownUp('enter');
- keyDownUp('esc');
- expect(this.$container.find('.handsontableEditor:visible').length).toEqual(0);
- });
- // see https://github.com/handsontable/handsontable/issues/3380
- it('should not throw error while selecting the next cell by hitting enter key', () => {
- var spy = jasmine.createSpyObj('error', ['test']);
- var prevError = window.onerror;
- window.onerror = function(messageOrEvent, source, lineno, colno, error) {
- spy.test();
- };
- handsontable({
- columns: [{
- type: 'handsontable',
- handsontable: {
- data: [['Marque'], ['Country'], ['Parent company']]
- }
- }]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- keyDownUp('enter');
- keyDownUp('enter');
- expect(spy.test.calls.count()).toBe(0);
- window.onerror = prevError;
- });
- it('Enter pressed in nested HT should set the value and hide the editor', function() {
- handsontable({
- columns: [
- {
- type: 'handsontable',
- handsontable: {
- colHeaders: ['Marque', 'Country', 'Parent company'],
- data: getManufacturerData()
- }
- }
- ]
- });
- selectCell(2, 0);
- keyDownUp('enter');
- keyDownUp('arrow_down');
- keyDownUp('enter');
- expect(this.$container.find('.handsontableEditor:visible').length).toEqual(0);
- expect(getDataAtCell(2, 0)).toEqual('BMW');
- });
- it('should keep focus on textarea after arrow is pressed', () => {
- var hot = handsontable({
- columns: [
- {
- type: 'handsontable',
- handsontable: {
- colHeaders: ['Marque', 'Country', 'Parent company'],
- data: getManufacturerData()
- }
- }
- ]
- });
- selectCell(2, 0);
- keyDownUp('enter');
- keyDownUp('arrow_down');
- expect(document.activeElement).toEqual(hot.getActiveEditor().TEXTAREA);
- });
- it('should focus the TD after HT editor is prepared and destroyed', () => {
- handsontable({
- columns: [
- {
- type: 'handsontable',
- handsontable: {
- colHeaders: ['Marque', 'Country', 'Parent company'],
- data: getManufacturerData()
- }
- }
- ]
- });
- selectCell(2, 0);
- keyDownUp('arrow_down');
- keyDownUp('arrow_down');
- expect(getSelected()).toEqual([4, 0, 4, 0]);
- });
- it('should focus the TD after HT editor is prepared, finished (by keyboard) and destroyed', () => {
- var selections = [];
- handsontable({
- columns: [
- {
- type: 'handsontable',
- handsontable: {
- colHeaders: ['Marque', 'Country', 'Parent company'],
- data: getManufacturerData(),
- afterSelection() {
- selections.push(['inner', arguments[0]]); // arguments[0] is selection start row
- }
- }
- }
- ],
- afterSelection() {
- selections.push(['outer', arguments[0]]); // arguments[0] is selection start row
- }
- });
- expect(selections.length).toBe(0);
- selectCell(1, 0);
- expect(selections[0]).toEqual(['outer', 1]);
- keyDownUp('arrow_down');
- expect(selections[1]).toEqual(['outer', 2]);
- keyDownUp('enter');
- keyDownUp('arrow_down');
- expect(selections[2]).toEqual(['inner', 0]);
- keyDownUp('esc');
- keyDownUp('arrow_down');
- expect(selections[3]).toEqual(['outer', 3]);
- expect(selections.length).toBe(4);
- });
- describe('strict mode', () => {
- it('should open editor and select cell (0, 0) in inner HOT', () => {
- var hot = handsontable({
- columns: [
- {
- type: 'handsontable',
- handsontable: {
- colHeaders: ['Marque', 'Country', 'Parent company'],
- data: getManufacturerData()
- },
- strict: true
- }
- ]
- });
- selectCell(2, 0);
- keyDownUp('enter');
- var ht = hot.getActiveEditor();
- var innerHot = ht.htEditor;
- expect(innerHot.getSelected()).toEqual([0, 0, 0, 0]);
- });
- it('should hide textarea', () => {
- var hot = handsontable({
- columns: [
- {
- type: 'handsontable',
- handsontable: {
- colHeaders: ['Marque', 'Country', 'Parent company'],
- data: getManufacturerData()
- },
- strict: true
- }
- ]
- });
- selectCell(2, 0);
- keyDownUp('enter');
- expect(hot.getActiveEditor().TEXTAREA.style.visibility).toEqual('hidden');
- });
- });
- describe('non strict mode', () => {
- it('should open editor and DO NOT select any cell in inner HOT', () => {
- var hot = handsontable({
- columns: [
- {
- type: 'handsontable',
- handsontable: {
- colHeaders: ['Marque', 'Country', 'Parent company'],
- data: getManufacturerData()
- }
- }
- ]
- });
- selectCell(2, 0);
- keyDownUp('enter');
- var ht = hot.getActiveEditor();
- var innerHot = ht.htEditor;
- expect(innerHot.getSelected()).toBeUndefined();
- });
- it('should show textarea', () => {
- var hot = handsontable({
- columns: [
- {
- type: 'handsontable',
- handsontable: {
- colHeaders: ['Marque', 'Country', 'Parent company'],
- data: getManufacturerData()
- }
- }
- ]
- });
- selectCell(2, 0);
- keyDownUp('enter');
- expect(hot.getActiveEditor().TEXTAREA.style.visibility).toEqual('visible');
- });
- });
- });
|