Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/js/modules/ColumnCalcs/ColumnCalcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export default class ColumnCalcs extends Module{

if(hasDataTreeColumnCalcs && row.modules.dataTree?.open){
this.rowsToData(dataTree.getFilteredTreeChildren(row)).forEach(dataRow =>{
data.push(row);
data.push(dataRow);
});
}
});
Expand Down Expand Up @@ -583,4 +583,4 @@ export default class ColumnCalcs extends Module{
}
}
}
}
}
41 changes: 40 additions & 1 deletion test/unit/modules/ColumnCalcs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,45 @@ describe('ColumnCalcs', function(){
expect(data[1].name).toBe("Jane");
});

test('rowsToData includes data tree child row data when child calcs are enabled', function(){
const childRows = [
{getData: function() { return {id: 2, value: 20}; }, modules: {}},
{getData: function() { return {id: 3, value: 30}; }, modules: {}},
];
const parentRow = {
getData: function() { return {id: 1, value: 10}; },
modules: {
dataTree: {
open: true,
},
},
};

const mockThis = {
rowsToData: ColumnCalcs.prototype.rowsToData,
table: {
options: {
dataTree: true,
dataTreeChildColumnCalcs: true,
},
modules: {
dataTree: {
getFilteredTreeChildren: jest.fn(() => childRows),
},
},
},
};

const data = ColumnCalcs.prototype.rowsToData.call(mockThis, [parentRow]);

expect(data).toEqual([
{id: 1, value: 10},
{id: 2, value: 20},
{id: 3, value: 30},
]);
expect(mockThis.table.modules.dataTree.getFilteredTreeChildren).toHaveBeenCalledWith(parentRow);
});

test('generateRowData creates calculation results', function(){
// Create mock data
const data = [
Expand Down Expand Up @@ -266,4 +305,4 @@ describe('ColumnCalcs', function(){
afterAll(() => {
Module.prototype.registerTableOption = originalRegisterTableOption;
Module.prototype.registerColumnOption = originalRegisterColumnOption;
});
});
Loading