Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.
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 @@ -4,6 +4,7 @@ import { GridService, ExtensionService, FilterService, GridStateService, SortSer
import { CellArgs, Column, OnEventArgs, GridOption } from './../../models';

declare const Slick: any;
jest.useFakeTimers();

const mockSelectionModel = {
init: jest.fn(),
Expand Down Expand Up @@ -39,6 +40,7 @@ const dataviewStub = {
deleteItem: jest.fn(),
deleteItems: jest.fn(),
getIdxById: jest.fn(),
getItemMetadata: jest.fn(),
getItem: jest.fn(),
getRowById: jest.fn(),
insertItem: jest.fn(),
Expand Down Expand Up @@ -1079,23 +1081,21 @@ describe('Grid Service', () => {
});

describe('highlightRowByMetadata method', () => {
it('should hightlight a row with a fading start & end delay', (done) => {
it('should hightlight a row with a fading start & end delay', () => {
const mockColumn = { id: 'field2', field: 'field2', width: 150, rowClass: 'red' } as Column;
const getItemSpy = jest.spyOn(dataviewStub, 'getItem').mockReturnValue(mockColumn);
const getIndexSpy = jest.spyOn(dataviewStub, 'getIdxById').mockReturnValue(0);
const updateSpy = jest.spyOn(dataviewStub, 'updateItem');
const renderSpy = jest.spyOn(service, 'renderGrid');

service.highlightRowByMetadata(2, 1, 1);
jest.runAllTimers(); // fast-forward timer

setTimeout(() => {
expect(getItemSpy).toHaveBeenCalledWith(2);
expect(updateSpy).toHaveBeenCalledTimes(3);
expect(updateSpy).toHaveBeenCalledWith(mockColumn.id, mockColumn);
expect(renderSpy).toHaveBeenCalled();
expect(getIndexSpy).toHaveBeenCalled();
done();
}, 5);
expect(getItemSpy).toHaveBeenCalledWith(2);
expect(updateSpy).toHaveBeenCalledTimes(3);
expect(updateSpy).toHaveBeenCalledWith(mockColumn.id, mockColumn);
expect(renderSpy).toHaveBeenCalled();
expect(getIndexSpy).toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -1492,6 +1492,28 @@ describe('Grid Service', () => {
});
});

describe('highlightRow method', () => {
afterEach(() => {
jest.clearAllMocks();
});

it('should be able to highlight first row at zero index', () => {
const mockRowMetadata = (rowNumber) => ({ cssClasses: `row-${rowNumber}` });
const mockItem = { id: 0, firstName: 'John', lastName: 'Doe' };
jest.spyOn(service, 'getItemRowMetadataToHighlight').mockReturnValue(mockRowMetadata);
jest.spyOn(dataviewStub, 'getItem').mockReturnValue(mockItem);
jest.spyOn(dataviewStub, 'getIdxById').mockReturnValue(0);
const updateSpy = jest.spyOn(dataviewStub, 'updateItem');
const renderSpy = jest.spyOn(service, 'renderGrid');

service.highlightRow(0, 10, 15);
jest.runAllTimers(); // fast-forward timer

expect(updateSpy).toHaveBeenCalledWith(0, mockItem)
expect(renderSpy).toHaveBeenCalledTimes(3);
});
});

// --
// DEPRECATED methods, to be removed eventually
// ----------------------
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/angular-slickgrid/services/grid.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export class GridService {
const item = this._dataView.getItem(rowNumber);
const idPropName = this._gridOptions.datasetIdPropertyName || 'id';

if (item && item[idPropName]) {
if (item && item[idPropName] !== undefined) {
item.rowClass = 'highlight';
this._dataView.updateItem(item[idPropName], item);
this.renderGrid();
Expand All @@ -281,7 +281,7 @@ export class GridService {

// delete the row's CSS highlight classes once the delay is passed
setTimeout(() => {
if (item && item[idPropName]) {
if (item && item[idPropName] !== undefined) {
delete item.rowClass;
if (this._dataView.getIdxById(item[idPropName]) !== undefined) {
this._dataView.updateItem(item[idPropName], item);
Expand Down