-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
90 lines (81 loc) · 2.12 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import test from 'ava';
import converter from './index';
const exampleNestedSetOfCategoriesWithOneRoot = [
{name: 'Catalog', lft: 1, rgt: 11},
{name: 'Cars', lft: 2, rgt: 7},
{name: 'Volvo', lft: 3, rgt: 4},
{name: 'BMW', lft: 5, rgt: 6},
{name: 'Mobile phones', lft: 8, rgt: 11},
{name: 'Sony', lft: 9, rgt: 10}
];
const exampleResultWithOneRoot = [{
name: 'Catalog',
lft: 1,
rgt: 11,
children: [
{
name: 'Cars',
lft: 2,
rgt: 7,
children: [
{name: 'Volvo', lft: 3, rgt: 4},
{name: 'BMW', lft: 5, rgt: 6}
]
},
{
name: 'Mobile phones',
lft: 8,
rgt: 11,
children: [
{name: 'Sony', lft: 9, rgt: 10}
]
}
]
}];
const exampleNestedSetOfCategoriesWithMultipleRoots = [
{name: 'Cars', lft: 1, rgt: 6},
{name: 'Volvo', lft: 2, rgt: 3},
{name: 'BMW', lft: 4, rgt: 5},
{name: 'Mobile phones', lft: 7, rgt: 10},
{name: 'Sony', lft: 8, rgt: 9}
];
const exampleResultWithMultipleRoots = [
{
name: 'Cars',
lft: 1,
rgt: 6,
children: [
{name: 'Volvo', lft: 2, rgt: 3},
{name: 'BMW', lft: 4, rgt: 5}
]
},
{
name: 'Mobile phones',
lft: 7,
rgt: 10,
children: [
{name: 'Sony', lft: 8, rgt: 9}
]
}
];
// lgt and rgt are strings
const example2NestedSetOfCategoriesWithMultipleRoots = [
{name: 'Cars', lft: '1', rgt: '2'},
{name: 'Mobile phones', lft: '3', rgt: '4'}
];
const example2ResultWithMultipleRoots = [
{name: 'Cars', lft: '1', rgt: '2'},
{name: 'Mobile phones', lft: '3', rgt: '4'}
];
test('Nested Set with one root converts correctly', t => {
let result = converter(exampleNestedSetOfCategoriesWithOneRoot);
t.deepEqual(result, exampleResultWithOneRoot);
});
test('First Nested Set with multiple roots converts correctly', t => {
let result = converter(exampleNestedSetOfCategoriesWithMultipleRoots);
t.deepEqual(result, exampleResultWithMultipleRoots);
});
test('Second Nested Set with multiple roots converts correctly', t => {
let result = converter(example2NestedSetOfCategoriesWithMultipleRoots);
t.deepEqual(result, example2ResultWithMultipleRoots);
});