forked from Netflix/falcor-path-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoTree.spec.js
89 lines (70 loc) · 2.45 KB
/
toTree.spec.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
var toTree = require('../lib/toTree');
var toPaths = require('../lib/toPaths');
var expect = require('chai').expect;
describe('toTree', function() {
it('should explode a simplePath.', function() {
var input = ['one', 'two'];
var out = {one: {two: null}};
expect(toTree([input])).to.deep.equals(out);
});
it('should explode an empty path.', function() {
var input = [];
var out = {};
expect(toTree([input])).to.deep.equals(out);
});
it('should explode a simplePath with reserved keyword.', function() {
var input = ['one', 'hasOwnProperty'];
var out = {one: {hasOwnProperty: null}};
expect(toTree([input])).to.deep.equals(out);
});
it('should explode a complex.', function() {
var input = ['one', ['two', 'three']];
var out = {one: {three: null, two: null}};
expect(toTree([input])).to.deep.equals(out);
});
it('should explode an empty path array.', function() {
var input = ['one', []];
var out = {one: {}};
expect(toTree([input])).to.deep.equals(out);
});
it('should explode an empty path range.', function() {
var input = ['one', { from: 0, to: -1 }];
var out = {one: {}};
expect(toTree([input])).to.deep.equals(out);
});
it('should explode an empty path range in array.', function() {
var input = ['one', [{ from: 0, to: -1 }]];
var out = {one: {}};
expect(toTree([input])).to.deep.equals(out);
});
it('should explode a set of complex and simple paths.', function() {
var input = [
['one', ['two', 'three']],
['one', {from: 0, to: 3}, 'summary']
];
var out = {
one: {
three: null,
two: null,
0: { summary: null },
1: { summary: null },
2: { summary: null },
3: { summary: null }
}
};
expect(toTree(input)).to.deep.equals(out);
});
it('should translate between toPaths and toTrees', function() {
var input = [
['one', ['two', 'three']],
['one', {from: 0, to: 3}, 'summary']
];
var treeMap = {
2: toTree([input[0]]),
3: toTree([input[1]])
};
var output = toPaths(treeMap);
output[0][1] = output[0][1].sort().reverse();
expect(output).to.deep.equals(input);
});
});