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(sorting): add some unit tests that were previously commented out #290

Merged
merged 1 commit into from
Mar 18, 2021
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
67 changes: 35 additions & 32 deletions packages/common/src/services/__tests__/sort.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,51 +639,54 @@ describe('SortService', () => {
const mockColumns = [{ id: 'firstName', field: 'firstName' }, { id: 'lastName', field: 'lastName' }] as Column[];

beforeEach(() => {
// gridOptionMock.presets = {
// sorters: [{ columnId: 'firstName', direction: 'ASC' }, { columnId: 'lastName', direction: 'DESC' }],
// };
gridOptionMock.presets = {
sorters: [{ columnId: 'firstName', direction: 'ASC' }, { columnId: 'lastName', direction: 'DESC' }],
};
jest.spyOn(gridStub, 'getColumns').mockReturnValue(mockColumns);
});

// it('should load local grid presets', () => {
// const spySetCols = jest.spyOn(gridStub, 'setSortColumns');
// const spySortChanged = jest.spyOn(service, 'onLocalSortChanged');
// const expectation = [
// { columnId: 'firstName', sortAsc: true, sortCol: { id: 'firstName', field: 'firstName' } },
// { columnId: 'lastName', sortAsc: false, sortCol: { id: 'lastName', field: 'lastName' } },
// ];
it('should load local grid presets', () => {
const spySetCols = jest.spyOn(gridStub, 'setSortColumns');
const spySortChanged = jest.spyOn(service, 'onLocalSortChanged');
const expectation = [
{ columnId: 'firstName', sortAsc: true, sortCol: { id: 'firstName', field: 'firstName' } },
{ columnId: 'lastName', sortAsc: false, sortCol: { id: 'lastName', field: 'lastName' } },
];

// service.bindLocalOnSort(gridStub);
// service.loadGridSorters(gridOptionMock.presets.sorters);
service.bindLocalOnSort(gridStub);
service.loadGridSorters(gridOptionMock.presets.sorters);

// expect(spySetCols).toHaveBeenCalledWith(expectation);
// expect(spySortChanged).toHaveBeenCalledWith(gridStub, expectation);
// });
expect(spySetCols).toHaveBeenCalledWith([
{ columnId: 'firstName', sortAsc: true, },
{ columnId: 'lastName', sortAsc: false },
]);
expect(spySortChanged).toHaveBeenCalledWith(gridStub, expectation);
});
});

describe('undefined getColumns & getOptions', () => {
// it('should use an empty column definition when grid "getColumns" method is not available', () => {
// gridOptionMock.presets = {
// sorters: [{ columnId: 'firstName', direction: 'ASC' }, { columnId: 'lastName', direction: 'DESC' }],
// };
// const spySetCols = jest.spyOn(gridStub, 'setSortColumns');
// gridStub.getColumns = undefined;
it('should use an empty column definition when grid "getColumns" method is not available', () => {
gridOptionMock.presets = {
sorters: [{ columnId: 'firstName', direction: 'ASC' }, { columnId: 'lastName', direction: 'DESC' }],
};
const spySetCols = jest.spyOn(gridStub, 'setSortColumns');
gridStub.getColumns = undefined;

// service.bindLocalOnSort(gridStub);
// service.loadGridSorters(gridOptionMock.presets.sorters);
service.bindLocalOnSort(gridStub);
service.loadGridSorters(gridOptionMock.presets.sorters);

// expect(spySetCols).not.toHaveBeenCalled();
// });
expect(spySetCols).toHaveBeenCalledWith([]);
});

// it('should use an empty grid option object when grid "getOptions" method is not available', () => {
// const spySetCols = jest.spyOn(gridStub, 'setSortColumns');
// gridStub.getOptions = undefined;
it('should use an empty grid option object when grid "getOptions" method is not available', () => {
const spySetCols = jest.spyOn(gridStub, 'setSortColumns');
gridStub.getOptions = undefined;

// service.bindLocalOnSort(gridStub);
// service.loadGridSorters(gridOptionMock.presets.sorters);
service.bindLocalOnSort(gridStub);
service.loadGridSorters(gridOptionMock.presets.sorters);

// expect(spySetCols).not.toHaveBeenCalled();
// });
expect(spySetCols).toHaveBeenCalledWith([]);
});
});

describe('onLocalSortChanged method', () => {
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/services/sort.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ export class SortService {

this.onLocalSortChanged(this._grid, sortCols);
this._grid.setSortColumns(sortCols.map(col => ({ columnId: col.columnId, sortAsc: col.sortAsc }))); // use this to add sort icon(s) in UI

}
return sortCols;
}
Expand Down