-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
1,017 additions
and
167 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
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
117 changes: 117 additions & 0 deletions
117
packages/s2-core/__tests__/unit/facet/layout/layout-hooks-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,117 @@ | ||
import { createFakeSpreadSheet } from 'tests/util/helpers'; | ||
import { | ||
layoutArrange, | ||
layoutCoordinate, | ||
layoutHierarchy, | ||
} from '@/facet/layout/layout-hooks'; | ||
import { Hierarchy, Node } from '@/index'; | ||
|
||
describe('layout-hooks test', () => { | ||
const s2 = createFakeSpreadSheet({ | ||
width: 600, | ||
height: 480, | ||
}); | ||
|
||
const node = new Node({ | ||
id: '', | ||
key: '', | ||
value: '', | ||
}); | ||
|
||
const hierarchy = new Hierarchy(); | ||
|
||
test('#layoutArrange()', () => { | ||
const layoutArrangeFn = jest.fn(() => ['b']); | ||
|
||
expect(layoutArrange(s2, ['a'], node, '')).toEqual(['a']); | ||
|
||
expect( | ||
layoutArrange( | ||
{ options: { layoutArrange: layoutArrangeFn } }, | ||
['a'], | ||
node, | ||
'', | ||
), | ||
).toEqual(['b']); | ||
expect(layoutArrangeFn).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('#layoutHierarchy()', () => { | ||
const colNode = new Node({ | ||
id: 'test', | ||
key: 'test', | ||
value: 'test', | ||
}); | ||
|
||
const layoutHierarchyFn = jest.fn(() => { | ||
return { | ||
push: [node], | ||
unshift: [colNode], | ||
}; | ||
}); | ||
|
||
expect( | ||
layoutHierarchy( | ||
{ | ||
options: { | ||
layoutHierarchy: layoutHierarchyFn, | ||
}, | ||
facet: { | ||
getHiddenColumnsInfo: () => colNode, | ||
}, | ||
columns: [colNode.id], | ||
}, | ||
node, | ||
colNode, | ||
hierarchy, | ||
), | ||
).toEqual(true); | ||
|
||
expect( | ||
layoutHierarchy( | ||
{ | ||
options: { | ||
layoutHierarchy: layoutHierarchyFn, | ||
}, | ||
facet: { | ||
getHiddenColumnsInfo: () => {}, | ||
}, | ||
columns: [], | ||
}, | ||
node, | ||
colNode, | ||
hierarchy, | ||
), | ||
).toEqual(true); | ||
}); | ||
|
||
test('#layoutCoordinate()', () => { | ||
const layoutCoordinateFn = jest.fn(); | ||
const rowNode = new Node({ | ||
id: 'rowNode', | ||
key: 'rowNode', | ||
value: 'rowNode', | ||
}); | ||
const colNode = new Node({ | ||
id: 'colNode', | ||
key: 'colNode', | ||
value: 'colNode', | ||
}); | ||
|
||
layoutCoordinate( | ||
{ options: { layoutCoordinate: layoutCoordinateFn } }, | ||
rowNode, | ||
colNode, | ||
); | ||
|
||
expect(layoutCoordinateFn).toHaveBeenCalledTimes(0); | ||
|
||
layoutCoordinate( | ||
{ options: { layoutCoordinate: layoutCoordinateFn } }, | ||
{ ...rowNode, isLeaf: true }, | ||
{ ...colNode, isLeaf: true }, | ||
); | ||
|
||
expect(layoutCoordinateFn).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,19 +1,62 @@ | ||
/** | ||
* Node test. | ||
*/ | ||
|
||
import { SERIES_NUMBER_FIELD } from '../../../../src'; | ||
import { Node } from '@/facet/layout/node'; | ||
|
||
describe('Node Test', () => { | ||
const root = new Node({ id: `root`, field: '', value: '', children: [] }); | ||
const root = new Node({ | ||
id: 'root', | ||
key: 'root', | ||
value: 'root', | ||
children: [], | ||
}); | ||
const child = new Node({ | ||
id: 'child', | ||
key: 'child', | ||
value: 'child', | ||
isLeaf: true, | ||
children: [], | ||
}); | ||
const node = new Node({ | ||
id: `root[&]country`, | ||
id: 'root[&]country', | ||
key: '', | ||
value: '', | ||
field: 'country', | ||
parent: root, | ||
}); | ||
|
||
node.children = [child]; | ||
|
||
test('should get correct field path', () => { | ||
expect(Node.getFieldPath(node)).toEqual(['country']); | ||
}); | ||
|
||
test('#getAllLeaveNodes()', () => { | ||
expect(Node.getAllLeaveNodes(node)).toHaveLength(1); | ||
}); | ||
|
||
test('#getAllChildrenNodes()', () => { | ||
expect(Node.getAllChildrenNodes(node)).toHaveLength(1); | ||
}); | ||
|
||
test('#getAllBranch()', () => { | ||
expect(Node.getBranchNodes(node)).toHaveLength(1); | ||
}); | ||
|
||
test('#rootNode()', () => { | ||
expect(Node.rootNode().id).toEqual('root'); | ||
}); | ||
|
||
test('#getHeadLeafChild()', () => { | ||
expect(node.getHeadLeafChild().id).toEqual('child'); | ||
}); | ||
|
||
test('#getTotalHeightForTreeHierarchy()', () => { | ||
expect(node.getTotalHeightForTreeHierarchy()).toEqual(0); | ||
}); | ||
|
||
test('#isSeriesNumberNode()', () => { | ||
expect(node.isSeriesNumberNode()).toBeFalsy(); | ||
|
||
node.field = SERIES_NUMBER_FIELD; | ||
expect(node.isSeriesNumberNode()).toBeTruthy(); | ||
}); | ||
}); |
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.