-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkSpec.js
More file actions
executable file
·36 lines (29 loc) · 1.18 KB
/
linkSpec.js
File metadata and controls
executable file
·36 lines (29 loc) · 1.18 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
describe("link()", function() {
var data = [
{ name: "Nick", age: 31 },
{ name: "Sirena", age: 26 },
{ name: "Cassie", age: 12 }
];
var orders = [
{ person: "Nick", product: 1, quantity: 10 },
{ person: "Nick", product: 2, quantity: 15 },
{ person: "Sirena", product: 1, quantity: 5 }
];
it("should join 1 parent to 2 children", function() {
var result = data.where("this.name === 'Nick'").link(orders, "this.name === other.person");
expect(result.length).toEqual(2);
expect(result[0].left.name).toEqual("Nick");
expect(result[0].right.quantity).toEqual(10);
expect(result[1].right.quantity).toEqual(15);
});
it("should link and then be able to sort", function() {
var result = data.link(orders, "this.name === other.person");
expect(result[0].left.name).toNotEqual("Sirena");
result.sort(function(a, b) {
return a.right.quantity > b.right.quantity ? 1 :
a.right.quantity < b.right.quantity ? -1 :
0;
});
expect(result[0].left.name).toEqual("Sirena");
});
});