Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix COMPONENT ERROR: e.cells[o] is undefined #1951

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export default function isWholeTableSelected(vTable: VTable, selection: TableSel
}
const { firstCell, lastCell } = selection;
const rowsLength = vTable.cells.length - 1;
const colIndex = vTable.cells[rowsLength].length - 1;
const rowCells = vTable.cells[rowsLength];
if (!rowCells) {
return false;
}
const colIndex = rowCells.length - 1;
const firstX = firstCell.x;
const firstY = firstCell.y;
const lastX = lastCell.x;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import * as isWholeTableSelectedFile from '../../lib/table/isWholeTableSelected';
import VTable from '../../lib/table/VTable';

describe('isWholeTableSelectedTest', () => {
it('Table without rows', () => {
const table = document.createElement('table');
spyOn(isWholeTableSelectedFile, 'default').and.callThrough();

const vTable = new VTable(table);
const result = isWholeTableSelectedFile.default(vTable, {
firstCell: {
x: 0,
y: 0,
},
lastCell: {
x: 0,
y: 0,
},
});

expect(result).toBeFalse();
expect(isWholeTableSelectedFile.default).not.toThrow();
});

it('Table with single row and no cells', () => {
const table = document.createElement('table');
table.appendChild(document.createElement('tr'));
spyOn(isWholeTableSelectedFile, 'default').and.callThrough();

const vTable = new VTable(table);
const result = isWholeTableSelectedFile.default(vTable, {
firstCell: {
x: 0,
y: 0,
},
lastCell: {
x: 0,
y: 0,
},
});

expect(result).toBeFalse();
expect(isWholeTableSelectedFile.default).not.toThrow();
});

it('Table 1x2 is whole selected', () => {
const table = document.createElement('table');
const tr = document.createElement('tr');
tr.append(document.createElement('td'), document.createElement('td'));
table.appendChild(tr);
spyOn(isWholeTableSelectedFile, 'default').and.callThrough();

const vTable = new VTable(table);
const result = isWholeTableSelectedFile.default(vTable, {
firstCell: {
x: 0,
y: 0,
},
lastCell: {
x: 1,
y: 0,
},
});

expect(result).toBeTrue();
expect(isWholeTableSelectedFile.default).not.toThrow();
});

it('Table 1x2 is not whole selected', () => {
const table = document.createElement('table');
const tr = document.createElement('tr');
tr.append(document.createElement('td'), document.createElement('td'));
table.appendChild(tr);
spyOn(isWholeTableSelectedFile, 'default').and.callThrough();

const vTable = new VTable(table);
const result = isWholeTableSelectedFile.default(vTable, {
firstCell: {
x: 0,
y: 0,
},
lastCell: {
x: 0,
y: 0,
},
});

expect(result).toBeFalse();
expect(isWholeTableSelectedFile.default).not.toThrow();
});
});