Skip to content

Commit

Permalink
Added row u-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsv2013 committed Apr 20, 2023
1 parent 4ae3696 commit ad316b8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sources/table/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class TableCell extends Base implements ITableCell {
return this.getCellTypeDescription("default").component;
}

public initialize(col: ITableColumn, back: boolean, rowData: any, color: string) {
public initialize(col: ITableColumn, rowData: any, back: boolean = false, color?: string) {
this.type = col.type;
this.name = col.name;
this.rowData = rowData;
Expand Down
2 changes: 1 addition & 1 deletion sources/table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export class Table extends Base implements IDataProviderOwner {
let colorCell = null, colorRow = null;
this.columns.reverse().forEach(col => {
let cell = new TableCell();
cell.initialize(col, back, data, colorCell);
cell.initialize(col, data, back, colorCell);
if (!!lastText) {
cell.text += ("/" + lastText);
}
Expand Down
44 changes: 44 additions & 0 deletions tests/row.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @jest-environment jsdom
*/

import { TableCell } from "../sources/table/cell";
import { TableColumn } from "../sources/table/column";
import { TableRow } from "../sources/table/row";

test("Row update", () => {
const row = new TableRow();
row.rowData = {
"f1": 0
};
const cell = new TableCell();
const column = new TableColumn(<any>{ name: "f1" }, null);
cell.initialize(column, row.rowData);
row.cells = [cell];
expect(cell.data).toBe(0);

row.rowData["f1"] = 1;
expect(cell.data).toBe(0);

row.update();
expect(cell.data).toBe(1);
expect(cell.isModified).toBeFalsy();

row.rowData["f1"] = 2;
expect(cell.data).toBe(1);

row.update(false);
expect(cell.data).toBe(2);
expect(cell.isModified).toBeTruthy();
});

test("Row css", () => {
const row = new TableRow();

expect(row.selected).toBeFalsy();
expect(row.mode).toBe("default");
expect(row.css).toBe("table4js__row table4js__row--default");

row.selected = true;
expect(row.css).toBe("table4js__row table4js__row--default table4js__row--selected");
});

0 comments on commit ad316b8

Please sign in to comment.