Total Complexity | 2 |
Complexity/F | 1 |
Lines of Code | 66 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | /* eslint-enable describe it sinon */ |
||
3 | import expect from 'expect'; |
||
4 | |||
5 | import { |
||
6 | getTreePathFromId |
||
7 | } from './../../src/util/getTreePathFromId'; |
||
8 | |||
9 | import { |
||
10 | treeToFlatList |
||
11 | } from './../../src/util/treeToFlatList'; |
||
12 | |||
13 | describe('the treeFlatList utility', () => { |
||
14 | |||
15 | it('Should turn a tree into a flat list with no identifier', () => { |
||
16 | |||
17 | const data = { |
||
18 | root: { |
||
19 | id: -1, |
||
20 | children: [ |
||
21 | { |
||
22 | id: 1, |
||
23 | parentId: -1, |
||
24 | children: [ |
||
25 | { |
||
26 | id: 11, |
||
27 | parentId: 1 |
||
28 | }, |
||
29 | { |
||
30 | id: 12, |
||
31 | parentId: 1, |
||
32 | children: [ |
||
33 | { |
||
34 | id: 121, |
||
35 | parentId: 12, |
||
36 | children: [ |
||
37 | { |
||
38 | id: 1211, |
||
39 | parentId: 121 |
||
40 | } |
||
41 | ] |
||
42 | } |
||
43 | ] |
||
44 | } |
||
45 | ] |
||
46 | }, |
||
47 | { |
||
48 | id: 2, |
||
49 | parentId: -1, |
||
50 | children: [ |
||
51 | { |
||
52 | id: 21, |
||
53 | parentId: 2 |
||
54 | } |
||
55 | ] |
||
56 | } |
||
57 | ] |
||
58 | } |
||
59 | }; |
||
60 | |||
61 | const flat = treeToFlatList(data); |
||
62 | |||
63 | expect( |
||
64 | getTreePathFromId(flat, 121) |
||
65 | ).toEqual([-1, 1, 12, 121]); |
||
66 | }); |
||
67 | |||
68 | }); |
||
69 |