Skip to content

Commit

Permalink
feat(tests): rename to slick-vanilla-grid-bundle and add unit tests (#12
Browse files Browse the repository at this point in the history
)

* feat(tests): rename to slick-vanilla-grid-bundle and add unit tests suite
  • Loading branch information
ghiscoding authored Jul 15, 2020
1 parent e0a729c commit 006c302
Show file tree
Hide file tree
Showing 18 changed files with 2,012 additions and 168 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ and it is also used to test with the UI portion. The Vanilla bundle is also used
| [@slickgrid-universal/common](https://github.com/ghiscoding/slickgrid-universal/tree/master/packages/common) | commonly used Formatters/Editors/Filters/Services/... |
| [@slickgrid-universal/excel-export](https://github.com/ghiscoding/slickgrid-universal/tree/master/packages/excel-export) | Export to Excel Service (xls/xlsx) |
| [@slickgrid-universal/file-export](https://github.com/ghiscoding/slickgrid-universal/tree/master/packages/file-export) | Export to Text File Service (csv/txt) |
| [@slickgrid-universal/graphql](https://github.com/ghiscoding/slickgrid-universal/tree/master/packages/graphql) | GraphQL Query Service (support Filter/Sort/Pagination with a GraphQL backend Server) |
| [@slickgrid-universal/odata](https://github.com/ghiscoding/slickgrid-universal/tree/master/packages/odata) | OData Query Service (support Filter/Sort/Pagination with an OData backend Server) |
| [@slickgrid-universal/graphql](https://github.com/ghiscoding/slickgrid-universal/tree/master/packages/graphql) | GraphQL Query Service (support Filter/Sort/Pagination) |
| [@slickgrid-universal/odata](https://github.com/ghiscoding/slickgrid-universal/tree/master/packages/odata) | OData Query Service (support Filter/Sort/Pagination) |
| [@slickgrid-universal/vanilla-bundle](https://github.com/ghiscoding/slickgrid-universal/tree/master/packages/vanilla-bundle) | a vanilla TypeScript/JavaScript implementation |

### Available Demos
Expand Down Expand Up @@ -76,7 +76,7 @@ npm run build

There is a Vanilla flavour implementation of this monorepo, vanilla means that it is not associated to any framework
and is written in plain TypeScript without being bound to any framework. The implementation is very similar to Angular and Aurelia.
It could be used as a guideline to implement it in with other frameworks.
It could be used as a guideline to implement it with other frameworks.

```bash
npm run dev:watch
Expand Down Expand Up @@ -151,5 +151,5 @@ npm run test:watch
- [x] Add possibility to use SVG instead of Font Family
- [x] Add Typings (interfaces) for Slick Grid & DataView objects
- [x] Add interfaces to all SlickGrid core lib classes & plugins (basically add Types to everything)
- [x] Copy text from cell doesn't work in SF
- [x] Copy cell text (context menu) doesn't work in SF
- [x] Remove all Services init method 2nd argument (we can get DataView directly from the Grid object)
5 changes: 3 additions & 2 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ export * from './grouping-formatters/index';
export * from './sortComparers/index';

import * as Enums from './enums/index';
import * as BackendUtilities from './services/backend-utilities';
import * as ServiceUtilities from './services/utilities';
import * as sortUtilities from './sortComparers/sortUtilities';
import * as SortUtilities from './sortComparers/sortUtilities';

const Utilities = { ...ServiceUtilities, ...sortUtilities };
const Utilities = { ...BackendUtilities, ...ServiceUtilities, ...SortUtilities };
export { Enums };
export { Utilities };
export { SlickgridConfig } from './slickgrid-config';
2 changes: 1 addition & 1 deletion packages/common/src/interfaces/slickResizer.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface SlickResizer {
* @param {object} event that triggered the resize, defaults to null
* @return If the browser supports it, we can return a Promise that would resolve with the new dimensions
*/
resizeGrid(delay?: number, newSizes?: GridSize, event?: SlickEventData): void;
resizeGrid(delay?: number, newSizes?: GridSize, event?: SlickEventData): Promise<GridSize>;

// --
// Events
Expand Down
6 changes: 4 additions & 2 deletions packages/common/src/services/__tests__/sort.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const gridStub = {
getColumnIndex: jest.fn(),
getOptions: () => gridOptionMock,
getColumns: jest.fn(),
getData: () => dataViewStub,
getData: () => dataViewStub as SlickDataView,
getSortColumns: jest.fn(),
invalidate: jest.fn(),
onLocalSortChanged: jest.fn(),
Expand Down Expand Up @@ -170,14 +170,16 @@ describe('SortService', () => {
const setSortSpy = jest.spyOn(gridStub, 'setSortColumns');
const gridSortSpy = jest.spyOn(gridStub.onSort, 'notify');

sharedService.dataView = null; // fake a custom dataview by removing the dataView in shared
gridStub.getData = () => null; // fake a custom dataview by removing the dataView in shared
const mockMouseEvent = new Event('mouseup');
service.bindLocalOnSort(gridStub);
service.clearSortByColumnId(mockMouseEvent, 'firstName');

expect(previousSortSpy).toHaveBeenCalled();
expect(setSortSpy).toHaveBeenCalled();
expect(gridSortSpy).toHaveBeenCalledWith(mockSortedCols[1]);
// @ts-ignore
gridStub.getData = () => dataViewStub as SlickDataView; // put back regular dataview mock
});

it('should expect Sort Service to call "onLocalSortChanged" with empty array then also "sortLocalGridByDefaultSortFieldId" when there is no more columns left to sort', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/services/sort.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class SortService {
if (Array.isArray(allSortedCols) && Array.isArray(sortedColsWithoutCurrent) && allSortedCols.length !== sortedColsWithoutCurrent.length) {
if (this._gridOptions.backendServiceApi) {
this.onBackendSortChanged(event, { multiColumnSort: true, sortCols: sortedColsWithoutCurrent, grid: this._grid });
} else if (this.sharedService.dataView) {
} else if (this._dataView) {
this.onLocalSortChanged(this._grid, sortedColsWithoutCurrent, true, true);
} else {
// when using customDataView, we will simply send it as a onSort event with notify
Expand Down
Binary file not shown.
Loading

0 comments on commit 006c302

Please sign in to comment.