@/utils#createIndexGetter TypeScript Examples
The following examples show how to use
@/utils#createIndexGetter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: flatten.spec.ts From treemate with MIT License | 5 votes |
describe('# flatten', () => {
it('works', () => {
const tm = createTreeMate(basicTree)
const flattenedNodes = tm.getFlattenedNodes()
expect(flattenedNodes.map((node) => node.key)).toEqual(
flattenedBasicTreeKeys
)
const getIndex = createIndexGetter(flattenedNodes)
expect(flattenedNodes.map((node) => getIndex(node.key))).toEqual(
flattenedBasicTreeKeys.map((_, i) => i)
)
})
it('works with ignored & group', () => {
const tm = createTreeMate(tree2)
const flattenedNodes = tm.getFlattenedNodes()
expect(flattenedNodes.map((node) => node.key)).toEqual(tree2Keys)
const getIndex = createIndexGetter(flattenedNodes)
expect(flattenedNodes.map((node) => getIndex(node.key))).toEqual(
tree2Keys.map((_, i) => i)
)
})
describe('# expanded keys', () => {
const tm = createTreeMate(expandedableTree)
it('case 1', () => {
const fn = tm.getFlattenedNodes([])
const fn1 = tm.getFlattenedNodes(['2-0'])
const fk = ['0', '1', '2', '3', '3-0', '3-1']
expect(fn.map((node) => node.key)).toEqual(fk)
expect(fn1.map((node) => node.key)).toEqual(fk)
const getIndex = createIndexGetter(fn)
expect(fn.map((node) => getIndex(node.key))).toEqual(fk.map((_, i) => i))
const getIndex1 = createIndexGetter(fn1)
expect(fn.map((node) => getIndex1(node.key))).toEqual(fk.map((_, i) => i))
})
it('case 2', () => {
const fn = tm.getFlattenedNodes(['1'])
const fk = ['0', '1', '1-0', '2', '3', '3-0', '3-1']
expect(fn.map((node) => node.key)).toEqual(fk)
const getIndex = createIndexGetter(fn)
expect(fn.map((node) => getIndex(node.key))).toEqual(fk.map((_, i) => i))
})
it('case 3', () => {
const fn = tm.getFlattenedNodes(['1', '2'])
const fk = ['0', '1', '1-0', '2', '2-0', '2-1', '3', '3-0', '3-1']
expect(fn.map((node) => node.key)).toEqual(fk)
const getIndex = createIndexGetter(fn)
expect(fn.map((node) => getIndex(node.key))).toEqual(fk.map((_, i) => i))
})
it('case 4', () => {
const fn = tm.getFlattenedNodes(['1', '2', '2-0'])
const fk = [
'0',
'1',
'1-0',
'2',
'2-0',
'2-0-0',
'2-0-1',
'2-1',
'3',
'3-0',
'3-1'
]
expect(fn.map((node) => node.key)).toEqual(fk)
const getIndex = createIndexGetter(fn)
expect(fn.map((node) => getIndex(node.key))).toEqual(fk.map((_, i) => i))
})
})
})