This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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
9 changed files
with
891 additions
and
582 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { hierarchy } from 'd3'; | ||
import { filterTree } from '../render'; | ||
|
||
const nodes = { | ||
id: '1', | ||
elemNo: 1, | ||
children: [ | ||
{ | ||
id: '2', | ||
elemNo: 2, | ||
children: [ | ||
{ | ||
id: '3', | ||
elemNo: 3, | ||
parent: { | ||
data: { | ||
id: '2', | ||
}, | ||
}, | ||
children: [ | ||
{ | ||
id: '5', | ||
elemNo: 798, | ||
parent: { | ||
id: '3', | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
id: '4', | ||
elemNo: 88, | ||
children: [], | ||
}, | ||
], | ||
}; | ||
|
||
describe('render', () => { | ||
describe('filterTree', () => { | ||
let topId; | ||
let isExpanded; | ||
let expandedChildren; | ||
let nodeTree; | ||
beforeEach(() => { | ||
topId = '1'; | ||
isExpanded = false; | ||
expandedChildren = []; | ||
nodeTree = hierarchy(nodes); | ||
}); | ||
|
||
it('should return the only top node', () => { | ||
const result = filterTree({ topId, isExpanded, expandedChildren }, nodeTree); | ||
expect(result.length).to.equal(1); | ||
expect(result[0].data.id).to.equal('1'); | ||
}); | ||
|
||
it('should return only the top node when topId not found', () => { | ||
topId = 'someInsaneId'; | ||
const result = filterTree({ topId, isExpanded, expandedChildren }, nodeTree); | ||
expect(result.length).to.equal(1); | ||
expect(result[0].data.id).to.equal('1'); | ||
}); | ||
|
||
it('should return the top node and children', () => { | ||
isExpanded = true; | ||
const result = filterTree({ topId, isExpanded, expandedChildren }, nodeTree); | ||
expect(result.length).to.equal(3); | ||
expect(result.map(node => node.data.id)).to.deep.equal(['1', '2', '4']); | ||
}); | ||
|
||
it('should return the top node and children and grandchildren of expanded', () => { | ||
isExpanded = true; | ||
expandedChildren = ['2']; | ||
const result = filterTree({ topId, isExpanded, expandedChildren }, nodeTree); | ||
expect(result.length).to.equal(4); | ||
expect(result.map(node => node.data.id)).to.deep.equal(['1', '2', '3', '4']); | ||
}); | ||
|
||
it('should return the top node and children with navigation mode free', () => { | ||
nodeTree.data.navigationMode = 'free'; | ||
isExpanded = true; | ||
topId = '2'; | ||
const result = filterTree({ topId, isExpanded, expandedChildren }, nodeTree); | ||
expect(result.length).to.equal(4); | ||
expect(result.map(node => node.data.id)).to.deep.equal(['1', '2', '4', '3']); | ||
}); | ||
|
||
it('should return the top node and parents children with navigation mode free', () => { | ||
nodeTree.data.navigationMode = 'free'; | ||
isExpanded = true; | ||
topId = '5'; | ||
const result = filterTree({ topId, isExpanded, expandedChildren }, nodeTree); | ||
expect(result.length).to.equal(5); | ||
expect(result.map(node => node.data.id)).to.deep.equal(['1', '2', '4', '3', '5']); | ||
}); | ||
}); | ||
}); |
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.