-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): add export abstract classes and add few more unit tests
- Loading branch information
1 parent
c588946
commit 13a1bca
Showing
11 changed files
with
256 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
packages/common/src/formatters/__tests__/treeFormatter.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { Column } from '../../interfaces/index'; | ||
import { treeFormatter } from '../treeFormatter'; | ||
|
||
const dataViewStub = { | ||
getIdxById: jest.fn(), | ||
getItemByIdx: jest.fn(), | ||
getIdPropertyName: jest.fn(), | ||
}; | ||
|
||
const gridStub = { | ||
getData: jest.fn(), | ||
}; | ||
|
||
describe('the Uppercase Formatter', () => { | ||
let dataset; | ||
|
||
beforeEach(() => { | ||
dataset = [ | ||
{ id: 0, firstName: 'John', lastName: 'Smith', email: 'john.smith@movie.com', parentId: null, indent: 0 }, | ||
{ id: 1, firstName: 'Jane', lastName: 'Doe', email: 'jane.doe@movie.com', parentId: 0, indent: 1 }, | ||
{ id: 2, firstName: 'Bob', lastName: 'Cane', email: 'bob.cane@movie.com', parentId: 1, indent: 2, __collapsed: true }, | ||
{ id: 2, firstName: 'Barbara', lastName: 'Cane', email: 'barbara.cane@movie.com', parentId: null, indent: 0, __collapsed: true }, | ||
]; | ||
}); | ||
|
||
it('should throw an error when oarams are mmissing', () => { | ||
expect(() => treeFormatter(1, 1, 'blah', {} as Column, {})) | ||
.toThrowError('You must provide a valid Tree Data column, it seems that there are no tree level found in this row'); | ||
}); | ||
|
||
it('should return empty string when DataView is not correctly formed', () => { | ||
const output = treeFormatter(1, 1, '', { treeData: { levelPropName: 'indent' } } as Column, dataset[1]); | ||
expect(output).toBe(''); | ||
}); | ||
|
||
it('should return empty string when value is null', () => { | ||
const output = treeFormatter(1, 1, null, { treeData: { levelPropName: 'indent' } } as Column, dataset[1]); | ||
expect(output).toBe(''); | ||
}); | ||
|
||
it('should return empty string when value is undefined', () => { | ||
const output = treeFormatter(1, 1, undefined, { treeData: { levelPropName: 'indent' } } as Column, dataset[1]); | ||
expect(output).toBe(''); | ||
}); | ||
|
||
it('should return empty string when item is undefined', () => { | ||
const output = treeFormatter(1, 1, 'blah', { treeData: { levelPropName: 'indent' } } as Column, undefined); | ||
expect(output).toBe(''); | ||
}); | ||
|
||
it('should return a span without any icon and ', () => { | ||
jest.spyOn(gridStub, 'getData').mockReturnValue(dataViewStub); | ||
jest.spyOn(dataViewStub, 'getIdxById').mockReturnValue(1); | ||
jest.spyOn(dataViewStub, 'getItemByIdx').mockReturnValue(dataset[0]); | ||
|
||
const output = treeFormatter(1, 1, dataset[0]['firstName'], { treeData: { levelPropName: 'indent' } } as Column, dataset[0], gridStub); | ||
expect(output).toBe(`<span style="display:inline-block; width:0px;"></span><span class="slick-group-toggle"></span> John`); | ||
}); | ||
|
||
it('should return a span without any icon and 15px indentation of a tree level 1', () => { | ||
jest.spyOn(gridStub, 'getData').mockReturnValue(dataViewStub); | ||
jest.spyOn(dataViewStub, 'getIdxById').mockReturnValue(1); | ||
jest.spyOn(dataViewStub, 'getItemByIdx').mockReturnValue(dataset[1]); | ||
|
||
const output = treeFormatter(1, 1, dataset[1]['firstName'], { treeData: { levelPropName: 'indent' } } as Column, dataset[1], gridStub); | ||
expect(output).toBe(`<span style="display:inline-block; width:15px;"></span><span class="slick-group-toggle"></span> Jane`); | ||
}); | ||
|
||
it('should return a span without any icon and 30px indentation of a tree level 2', () => { | ||
jest.spyOn(gridStub, 'getData').mockReturnValue(dataViewStub); | ||
jest.spyOn(dataViewStub, 'getIdxById').mockReturnValue(1); | ||
jest.spyOn(dataViewStub, 'getItemByIdx').mockReturnValue(dataset[1]); | ||
|
||
const output = treeFormatter(1, 1, dataset[2]['firstName'], { treeData: { levelPropName: 'indent' } } as Column, dataset[2], gridStub); | ||
expect(output).toBe(`<span style="display:inline-block; width:30px;"></span><span class="slick-group-toggle"></span> Bob`); | ||
}); | ||
|
||
it('should return a span with expanded icon and 15px indentation of a tree level 1 when current item is greater than next item', () => { | ||
jest.spyOn(gridStub, 'getData').mockReturnValue(dataViewStub); | ||
jest.spyOn(dataViewStub, 'getIdxById').mockReturnValue(1); | ||
jest.spyOn(dataViewStub, 'getItemByIdx').mockReturnValue(dataset[2]); | ||
|
||
const output = treeFormatter(1, 1, dataset[1]['firstName'], { treeData: { levelPropName: 'indent' } } as Column, dataset[1], gridStub); | ||
expect(output).toBe(`<span style="display:inline-block; width:15px;"></span><span class="slick-group-toggle expanded"></span> Jane`); | ||
}); | ||
|
||
it('should return a span with collapsed icon and 0px indentation of a tree level 0 when current item is lower than next item', () => { | ||
jest.spyOn(gridStub, 'getData').mockReturnValue(dataViewStub); | ||
jest.spyOn(dataViewStub, 'getIdxById').mockReturnValue(1); | ||
jest.spyOn(dataViewStub, 'getItemByIdx').mockReturnValue(dataset[1]); | ||
|
||
const output = treeFormatter(1, 1, dataset[3]['firstName'], { treeData: { levelPropName: 'indent' } } as Column, dataset[3], gridStub); | ||
expect(output).toBe(`<span style="display:inline-block; width:0px;"></span><span class="slick-group-toggle collapsed"></span> Barbara`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ExcelExportOption } from '../interfaces/index'; | ||
|
||
export abstract class ExcelExportService { | ||
/** | ||
* Initialize the Export Service | ||
* @param grid | ||
* @param dataView | ||
*/ | ||
init(grid: any, dataView: any): void { | ||
console.log('ExcelExportService the "init" method must be implemented'); | ||
} | ||
|
||
/** | ||
* Method to return the current locale used by the App | ||
* @return {string} current locale | ||
*/ | ||
exportToExcel(options: ExcelExportOption): Promise<boolean> { | ||
console.log('ExcelExportService the "exportToExcel" method must be implemented'); | ||
return new Promise((resolve) => resolve(true)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ExportOption } from '../interfaces/index'; | ||
|
||
export abstract class ExportService { | ||
/** | ||
* Initialize the Export Service | ||
* @param grid | ||
* @param dataView | ||
*/ | ||
init(grid: any, dataView: any): void { | ||
console.log('ExportService the "init" method must be implemented'); | ||
} | ||
|
||
/** | ||
* Method to return the current locale used by the App | ||
* @return {string} current locale | ||
*/ | ||
exportToFile(options: ExportOption): Promise<boolean> { | ||
console.log('ExportService the "exportToFile" method must be implemented'); | ||
return new Promise((resolve) => resolve(true)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/vanilla-bundle/src/services/excelExport.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ExcelExportService, ExcelExportOption } from '@slickgrid-universal/common'; | ||
|
||
|
||
export class ExcelExportServicer implements ExcelExportService { | ||
init(grid: any, dataView: any): void { | ||
} | ||
|
||
exportToExcel(options: ExcelExportOption): Promise<boolean> { | ||
return new Promise((resolve) => resolve(true)); | ||
} | ||
} |
Oops, something went wrong.