-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
titleFormatter
to Tree Data
- this basically runs a Formatter into the Tree Formatter - also remove `indentedChildValuePrefix` that can easily be done in this new titleFormatter
- Loading branch information
1 parent
bb3d488
commit 8bf32ca
Showing
9 changed files
with
127 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ describe('Tree Formatter', () => { | |
{ id: 5, firstName: 'Sponge', lastName: 'Bob', fullName: 'Sponge Bob', email: '[email protected]', address: { zip: 888888 }, parentId: 2, indent: 3, __collapsed: true }, | ||
]; | ||
mockGridOptions = { | ||
treeDataOptions: { levelPropName: 'indent', indentedChildValuePrefix: '' } | ||
treeDataOptions: { levelPropName: 'indent' } | ||
} as GridOption; | ||
jest.spyOn(gridStub, 'getOptions').mockReturnValue(mockGridOptions); | ||
}); | ||
|
@@ -62,7 +62,10 @@ describe('Tree Formatter', () => { | |
jest.spyOn(dataViewStub, 'getItemByIdx').mockReturnValue(dataset[0]); | ||
|
||
const output = treeFormatter(1, 1, dataset[0]['firstName'], {} as Column, dataset[0], gridStub); | ||
expect(output).toBe(`<span style="display:inline-block; width:0px;"></span><span class="slick-group-toggle"></span>John`); | ||
expect(output).toEqual({ | ||
addClasses: 'slick-tree-level-0', | ||
text: `<span style="display:inline-block; width:0px;"></span><span class="slick-group-toggle"></span><span class="slick-tree-title" level="0">John</span>` | ||
}); | ||
}); | ||
|
||
it('should return a span without any icon and 15px indentation of a tree level 1', () => { | ||
|
@@ -71,7 +74,10 @@ describe('Tree Formatter', () => { | |
jest.spyOn(dataViewStub, 'getItemByIdx').mockReturnValue(dataset[1]); | ||
|
||
const output = treeFormatter(1, 1, dataset[1]['firstName'], {} as Column, dataset[1], gridStub); | ||
expect(output).toBe(`<span style="display:inline-block; width:15px;"></span><span class="slick-group-toggle"></span>Jane`); | ||
expect(output).toEqual({ | ||
addClasses: 'slick-tree-level-1', | ||
text: `<span style="display:inline-block; width:15px;"></span><span class="slick-group-toggle"></span><span class="slick-tree-title" level="1">Jane</span>` | ||
}); | ||
}); | ||
|
||
it('should return a span without any icon and 30px indentation of a tree level 2', () => { | ||
|
@@ -80,7 +86,10 @@ describe('Tree Formatter', () => { | |
jest.spyOn(dataViewStub, 'getItemByIdx').mockReturnValue(dataset[1]); | ||
|
||
const output = treeFormatter(1, 1, dataset[2]['firstName'], {} as Column, dataset[2], gridStub); | ||
expect(output).toBe(`<span style="display:inline-block; width:30px;"></span><span class="slick-group-toggle"></span>Bob`); | ||
expect(output).toEqual({ | ||
addClasses: 'slick-tree-level-2', | ||
text: `<span style="display:inline-block; width:30px;"></span><span class="slick-group-toggle"></span><span class="slick-tree-title" level="2">Bob</span>` | ||
}); | ||
}); | ||
|
||
it('should return a span with expanded icon and 15px indentation of a tree level 1 when current item is greater than next item', () => { | ||
|
@@ -89,7 +98,10 @@ describe('Tree Formatter', () => { | |
jest.spyOn(dataViewStub, 'getItemByIdx').mockReturnValue(dataset[2]); | ||
|
||
const output = treeFormatter(1, 1, dataset[1]['firstName'], {} as Column, dataset[1], gridStub); | ||
expect(output).toBe(`<span style="display:inline-block; width:15px;"></span><span class="slick-group-toggle expanded"></span>Jane`); | ||
expect(output).toEqual({ | ||
addClasses: 'slick-tree-level-1', | ||
text: `<span style="display:inline-block; width:15px;"></span><span class="slick-group-toggle expanded"></span><span class="slick-tree-title" level="1">Jane</span>` | ||
}); | ||
}); | ||
|
||
it('should return a span with collapsed icon and 0px indentation of a tree level 0 when current item is lower than next item', () => { | ||
|
@@ -98,27 +110,29 @@ describe('Tree Formatter', () => { | |
jest.spyOn(dataViewStub, 'getItemByIdx').mockReturnValue(dataset[1]); | ||
|
||
const output = treeFormatter(1, 1, dataset[3]['firstName'], {} as Column, dataset[3], gridStub); | ||
expect(output).toBe(`<span style="display:inline-block; width:0px;"></span><span class="slick-group-toggle collapsed"></span>Barbara`); | ||
expect(output).toEqual({ | ||
addClasses: 'slick-tree-level-0', | ||
text: `<span style="display:inline-block; width:0px;"></span><span class="slick-group-toggle collapsed"></span><span class="slick-tree-title" level="0">Barbara</span>` | ||
}); | ||
}); | ||
|
||
it('should return a span with expanded icon and 15px indentation of a tree level 1 with a value prefix when provided', () => { | ||
mockGridOptions.treeDataOptions.indentedChildValuePrefix = '<span class="mdi mdi-subdirectory-arrow-right"></span>'; | ||
mockGridOptions.treeDataOptions.levelPropName = 'indent'; | ||
mockGridOptions.treeDataOptions.titleFormatter = (_row, _cell, value, _def, dataContext) => { | ||
if (dataContext.indent > 0) { | ||
return `<span class="mdi mdi-subdirectory-arrow-right"></span>${value}`; | ||
} | ||
return value || ''; | ||
}; | ||
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'], {} as Column, dataset[1], gridStub); | ||
expect(output).toBe(`<span style="display:inline-block; width:15px;"></span><span class="slick-group-toggle expanded"></span><span class="mdi mdi-subdirectory-arrow-right"></span>Jane`); | ||
}); | ||
|
||
it('should return a span with collapsed icon and 30px indentation of a tree level 2 when current item is lower than next item', () => { | ||
mockGridOptions.treeDataOptions.indentedChildValuePrefix = '<span class="mdi mdi-subdirectory-arrow-right"></span>'; | ||
jest.spyOn(gridStub, 'getData').mockReturnValue(dataViewStub); | ||
jest.spyOn(dataViewStub, 'getIdxById').mockReturnValue(1); | ||
jest.spyOn(dataViewStub, 'getItemByIdx').mockReturnValue(dataset[5]); | ||
|
||
const output = treeFormatter(1, 1, dataset[2]['firstName'], {} as Column, dataset[2], gridStub); | ||
expect(output).toBe(`<span style="display:inline-block; width:30px;"></span><span class="slick-group-toggle collapsed"></span><span class="mdi mdi-subdirectory-arrow-right"></span>Bob`); | ||
const output = treeFormatter(1, 1, { ...dataset[1]['firstName'], indent: 1 }, { field: 'firstName' } as Column, dataset[1], gridStub); | ||
expect(output).toEqual({ | ||
addClasses: 'slick-tree-level-1', | ||
text: `<span style="display:inline-block; width:15px;"></span><span class="slick-group-toggle expanded"></span><span class="slick-tree-title" level="1"><span class="mdi mdi-subdirectory-arrow-right"></span>Jane</span>` | ||
}); | ||
}); | ||
|
||
it('should execute "queryFieldNameGetterFn" callback to get field name to use when it is defined', () => { | ||
|
@@ -128,7 +142,10 @@ describe('Tree Formatter', () => { | |
|
||
const mockColumn = { id: 'firstName', field: 'firstName', queryFieldNameGetterFn: () => 'fullName' } as Column; | ||
const output = treeFormatter(1, 1, null, mockColumn as Column, dataset[3], gridStub); | ||
expect(output).toBe(`<span style="display:inline-block; width:0px;"></span><span class="slick-group-toggle collapsed"></span>Barbara Cane`); | ||
expect(output).toEqual({ | ||
addClasses: 'slick-tree-level-0', | ||
text: `<span style="display:inline-block; width:0px;"></span><span class="slick-group-toggle collapsed"></span><span class="slick-tree-title" level="0">Barbara Cane</span>` | ||
}); | ||
}); | ||
|
||
it('should execute "queryFieldNameGetterFn" callback to get field name and also apply html encoding when output value includes a character that should be encoded', () => { | ||
|
@@ -138,7 +155,10 @@ describe('Tree Formatter', () => { | |
|
||
const mockColumn = { id: 'firstName', field: 'firstName', queryFieldNameGetterFn: () => 'fullName' } as Column; | ||
const output = treeFormatter(1, 1, null, mockColumn as Column, dataset[4], gridStub); | ||
expect(output).toBe(`<span style="display:inline-block; width:0px;"></span><span class="slick-group-toggle collapsed"></span>Anonymous < Doe`); | ||
expect(output).toEqual({ | ||
addClasses: 'slick-tree-level-0', | ||
text: `<span style="display:inline-block; width:0px;"></span><span class="slick-group-toggle collapsed"></span><span class="slick-tree-title" level="0">Anonymous < Doe</span>` | ||
}); | ||
}); | ||
|
||
it('should execute "queryFieldNameGetterFn" callback to get field name, which has (.) dot notation reprensenting complex object', () => { | ||
|
@@ -148,6 +168,9 @@ describe('Tree Formatter', () => { | |
|
||
const mockColumn = { id: 'zip', field: 'zip', queryFieldNameGetterFn: () => 'address.zip' } as Column; | ||
const output = treeFormatter(1, 1, null, mockColumn as Column, dataset[3], gridStub); | ||
expect(output).toBe(`<span style="display:inline-block; width:0px;"></span><span class="slick-group-toggle collapsed"></span>444444`); | ||
expect(output).toEqual({ | ||
addClasses: 'slick-tree-level-0', | ||
text: `<span style="display:inline-block; width:0px;"></span><span class="slick-group-toggle collapsed"></span><span class="slick-tree-title" level="0">444444</span>` | ||
}); | ||
}); | ||
}); |
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
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
Oops, something went wrong.