| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- describe('Core_keepEmptyRows', () => {
- var id = 'testContainer';
- beforeEach(function() {
- this.$container = $(`<div id="${id}"></div>`).appendTo('body');
- });
- afterEach(function() {
- if (this.$container) {
- destroy();
- this.$container.remove();
- }
- });
- var arrayOfNestedObjects = function() {
- return [
- {id: 1,
- name: {
- first: 'Ted',
- last: 'Right'
- },
- address: 'Street Name',
- zip: '80410',
- city: 'City Name'},
- {id: 2,
- name: {
- first: 'Frank',
- last: 'Honest'
- },
- address: 'Street Name',
- zip: '80410',
- city: 'City Name'},
- {id: 3,
- name: {
- first: 'Joan',
- last: 'Well'
- },
- address: 'Street Name',
- zip: '80410',
- city: 'City Name'}
- ];
- };
- it('should remove columns if needed', function() {
- handsontable({
- data: arrayOfNestedObjects(),
- columns: [
- {data: 'id'},
- {data: 'name.first'}
- ]
- });
- expect(this.$container.find('tbody tr:first td').length).toEqual(2);
- });
- it('should remove columns if needed when columns is a function', function() {
- handsontable({
- data: arrayOfNestedObjects(),
- columns(column) {
- var colMeta = {};
- if (column === 0) {
- colMeta.data = 'id';
- } else if (column === 1) {
- colMeta.data = 'name.first';
- } else {
- colMeta = null;
- }
- return colMeta;
- }
- });
- expect(this.$container.find('tbody tr:first td').length).toEqual(2);
- });
- it('should create columns if needed', function() {
- handsontable({
- data: arrayOfNestedObjects(),
- columns: [
- {data: 'id'},
- {data: 'name.first'},
- {data: 'name.last'},
- {data: 'address'},
- {data: 'zip'},
- {data: 'city'}
- ]
- });
- expect(this.$container.find('tbody tr:first td').length).toEqual(6);
- });
- it('should create columns if needed when columns is a function', function() {
- handsontable({
- data: arrayOfNestedObjects(),
- columns(column) {
- var colMeta = {};
- if (column === 0) {
- colMeta.data = 'id';
- } else if (column === 1) {
- colMeta.data = 'name.first';
- } else if (column === 2) {
- colMeta.data = 'name.last';
- } else if (column === 3) {
- colMeta.data = 'address';
- } else if (column === 4) {
- colMeta.data = 'zip';
- } else if (column === 5) {
- colMeta.data = 'city';
- } else {
- colMeta = null;
- }
- return colMeta;
- }
- });
- expect(this.$container.find('tbody tr:first td').length).toEqual(6);
- });
- it('should create spare cols and rows on init (array data source)', () => {
- handsontable({
- data: [
- ['one', 'two'],
- ['three', 'four']
- ],
- minCols: 4,
- minRows: 4,
- minSpareRows: 4,
- minSpareCols: 4
- });
- expect(countCells()).toEqual(36);
- });
- it('should create spare cols and rows on init (object data source)', function() {
- handsontable({
- data: arrayOfNestedObjects(),
- minRows: 4,
- minSpareRows: 1
- });
- expect(countRows()).toEqual(4);
- expect(countCols()).toEqual(6); // because arrayOfNestedObjects has 6 nested properites and they should be figured out if dataSchema/columns is not given
- expect(this.$container.find('tbody tr:first td:last').text()).toEqual('City Name');
- });
- it('should create new row when last cell in last row is edited', () => {
- var data = [
- ['one', 'two'],
- ['three', 'four']
- ];
- handsontable({
- data,
- minRows: 4,
- minCols: 4,
- minSpareRows: 1
- });
- setDataAtCell(3, 3, 'test');
- expect(data.length).toEqual(5);
- });
- it('should create new col when last cell in last row is edited', () => {
- var data = [
- ['one', 'two'],
- ['three', 'four']
- ];
- handsontable({
- data,
- minRows: 4,
- minCols: 4,
- minSpareCols: 1
- });
- setDataAtCell(3, 3, 'test');
- expect(countCols()).toEqual(5);
- });
- it('should create new row when last cell in last row is edited by autocomplete', (done) => {
- var data = [
- {id: 1, color: 'orange' }
- ];
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(['red', 'dark-yellow', 'yellow', 'light-yellow', 'black']);
- });
- handsontable({
- data,
- startRows: 5,
- colHeaders: true,
- minSpareRows: 1,
- columns: [
- {data: 'id', type: 'text'},
- {
- data: 'color',
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- selectCell(1, 1);
- keyDownUp('enter');
- setTimeout(() => {
- keyDown('arrow_down');
- keyDownUp('enter');
- expect(data.length).toEqual(3);
- done();
- }, 200);
- });
- it('should create new row when last cell in last row is edited by autocomplete when columns is a function', (done) => {
- var data = [
- {id: 1, color: 'orange' }
- ];
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(['red', 'dark-yellow', 'yellow', 'light-yellow', 'black']);
- });
- handsontable({
- data,
- startRows: 5,
- colHeaders: true,
- minSpareRows: 1,
- columns(column) {
- var colMeta = {};
- if (column === 0) {
- colMeta.data = 'id';
- colMeta.type = 'text';
- } else if (column === 1) {
- colMeta.data = 'color';
- colMeta.editor = 'autocomplete';
- colMeta.source = syncSources;
- } else {
- colMeta = null;
- }
- return colMeta;
- }
- });
- selectCell(1, 1);
- keyDownUp('enter');
- setTimeout(() => {
- keyDown('arrow_down');
- keyDownUp('enter');
- expect(data.length).toEqual(3);
- done();
- }, 200);
- });
- it('should not create more rows that maxRows', () => {
- handsontable({
- startRows: 4,
- maxRows: 6,
- minSpareRows: 1
- });
- setDataAtCell(3, 0, 'test');
- setDataAtCell(4, 0, 'test');
- setDataAtCell(5, 0, 'test');
- expect(countRows()).toEqual(6);
- });
- it('should not create more cols that maxCols', () => {
- handsontable({
- startCols: 4,
- maxCols: 6,
- minSpareCols: 1
- });
- setDataAtCell(0, 3, 'test');
- setDataAtCell(0, 4, 'test');
- setDataAtCell(0, 5, 'test');
- expect(countCols()).toEqual(6);
- });
- it('should ignore minCols if columns is set', () => {
- handsontable({
- startCols: 1,
- minCols: 6,
- columns: [
- {},
- {}
- ]
- });
- expect(countCols()).toEqual(2);
- });
- it('should ignore minCols if columns is set when columns is a function', () => {
- handsontable({
- startCols: 1,
- minCols: 6,
- columns(column) {
- var colMeta = {};
- if ([0, 1].indexOf(column) < 0) {
- colMeta = null;
- }
- return colMeta;
- }
- });
- expect(countCols()).toEqual(1);
- });
- it('columns should have priority over startCols', () => {
- handsontable({
- startCols: 3,
- minCols: 6,
- columns: [
- {},
- {}
- ]
- });
- expect(countCols()).toEqual(2);
- });
- it('columns should have priority over startCols when columns is a function', () => {
- handsontable({
- startCols: 3,
- minCols: 6,
- columns(column) {
- var colMeta = {};
- if ([0, 1].indexOf(column) < 0) {
- colMeta = null;
- }
- return colMeta;
- }
- });
- expect(countCols()).toEqual(2);
- });
- });
|