Skip to content

Commit

Permalink
chore: add missing test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Jan 25, 2025
1 parent 26838d9 commit 683b716
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ Object.defineProperty(paginationServiceStub, 'totalItems', {
});

const resizerServiceStub = {
isAutoHeightEnabled: true,
autoHeightRecalcRow: 100,
init: jest.fn(),
dispose: jest.fn(),
bindAutoResizeDataGrid: jest.fn(),
Expand Down Expand Up @@ -2272,6 +2274,32 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
expect(footerSpy).toHaveBeenCalledWith(expectation);
});

it('should call a grid resize when the DataView "onRowCountChanged" event is triggered with a low dataset length and autoResize.autoHeight is enabled', () => {
const mockData = [
{ firstName: 'John', lastName: 'Doe' },
{ firstName: 'Jane', lastName: 'Smith' },
];
const invalidateSpy = jest.spyOn(mockGrid, 'invalidate');
const expectation = {
startTime: expect.any(Date),
endTime: expect.any(Date),
itemCount: 2,
totalItemCount: 2,
};
jest.spyOn(mockDataView, 'getItemCount').mockReturnValue(mockData.length);
jest.spyOn(mockDataView, 'getFilteredItemCount').mockReturnValue(mockData.length);
jest.spyOn(mockDataView, 'getLength').mockReturnValue(mockData.length);
const resizerSpy = jest.spyOn(resizerServiceStub, 'resizeGrid');

component.gridOptions = { enableAutoResize: true, autoResize: { autoHeight: true } };
component.initialization(slickEventHandler);
mockDataView.onRowCountChanged.notify({ current: 2, previous: 0, dataView: mockDataView, itemCount: 0, callingOnRowsChanged: false });

expect(invalidateSpy).toHaveBeenCalled();
expect(component.metrics).toEqual(expectation);
expect(resizerSpy).toHaveBeenCalled();
});

it('should have custom footer with metrics when the DataView "onSetItemsCalled" event is triggered', () => {
const expectation = {
startTime: expect.toBeDate(),
Expand Down

0 comments on commit 683b716

Please sign in to comment.