forked from Ajibaji/GradTechTest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgradTest.test.js
More file actions
54 lines (49 loc) · 1.38 KB
/
gradTest.test.js
File metadata and controls
54 lines (49 loc) · 1.38 KB
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
function createMenuData(data) {
var parents = [];
var answer = [];
for(i=0;i<data.length;i++){
if(data[i].includes("/")){
var slash = data[i].indexOf("/");
if(!(parents.includes(data[i].slice(0,slash)))){
parents.push(data[i].slice(0,slash));
}
}
}
for(j=0;j<parents.length;j++){
var parent = {title:parents[j]};
var childlist = [];
for(k=0;k<data.length;k++){
if(data[k].includes(parents[j]+"/")){
var stringlength = data[k].length;
childlist.push(data[k].slice((slash+1),stringlength));
}
}
parent.data = childlist;
answer.push(parent);
}
return answer;
}
describe("menu Data Generator", () => {
it("creates correct data structure ", () => {
const data = [
"parent1/parent1child",
"parent1/parent1child2",
"parent2/parent2child",
"parent2/parent2child2",
"parent1/parent1child3",
"parent3",
"parent3/parent3child1",
"parent4"
];
const expectedResult = [
{
title: "parent1",
data: ["parent1child", "parent1child2", "parent1child3"]
},
{ title: "parent2", data: ["parent2child", "parent2child2"] },
{ title: "parent3", data: ["parent3child1"] }
];
const actualResult = createMenuData(data);
expect(actualResult).toMatchObject(expectedResult);
});
});