1
|
|
|
/* |
2
|
|
|
backgrid |
3
|
|
|
http://github.com/wyuenho/backgrid |
4
|
|
|
|
5
|
|
|
Copyright (c) 2013 Jimmy Yuen Ho Wong and contributors |
6
|
|
|
Licensed under the MIT license. |
7
|
|
|
*/ |
8
|
|
|
describe("Backgrid#resolveNameToClass", function () { |
9
|
|
|
|
10
|
|
|
it("will return a reference to a Backgrid or a Backgrid.Extension object from a dasherized string and a suffix", function () { |
11
|
|
|
Backgrid.SelectRowCell = {}; |
12
|
|
|
expect(Backgrid.resolveNameToClass("select-row", "Cell")).toBeDefined(); |
13
|
|
|
expect(Backgrid.resolveNameToClass("select", "Cell")).toBeDefined(); |
14
|
|
|
delete Backgrid.SelectRowCell; |
15
|
|
|
}); |
16
|
|
|
|
17
|
|
|
it("will return the `name` object if it is not a string", function () { |
18
|
|
|
expect(Backgrid.resolveNameToClass({})).toEqual({}); |
19
|
|
|
}); |
20
|
|
|
|
21
|
|
|
it("throws ReferenceError if an object cannot be found in the Backgrid or Backgrid.Extension namespace", function () { |
22
|
|
|
expect(function () { |
23
|
|
|
Backgrid.resolveNameToClass("snoopy", "Cell"); |
24
|
|
|
}).toThrow(new ReferenceError("Class 'SnoopyCell' not found")); |
25
|
|
|
}); |
26
|
|
|
|
27
|
|
|
}); |
28
|
|
|
|
29
|
|
|
describe("Backgrid#callByNeed", function () { |
30
|
|
|
|
31
|
|
|
it("will return the first argument if it is not a function", function () { |
32
|
|
|
expect(Backgrid.callByNeed(1)).toBe(1); |
33
|
|
|
}); |
34
|
|
|
|
35
|
|
|
it("will return the value of the first argument after evaluating it as a function if it is a function", function () { |
36
|
|
|
expect(Backgrid.callByNeed(function () { |
37
|
|
|
return 1; |
38
|
|
|
})).toBe(1); |
39
|
|
|
}); |
40
|
|
|
|
41
|
|
|
it("will use the second parameter as the context when evaluating the first parameter as a function", function () { |
42
|
|
|
expect(Backgrid.callByNeed(function () { |
43
|
|
|
return this[0]; |
44
|
|
|
}, [1, 2, 3])).toBe(1); |
45
|
|
|
}); |
46
|
|
|
|
47
|
|
|
it("will use the third parameter and beyond as arguments to the first argument when evaluating it as a function", function () { |
48
|
|
|
expect(Backgrid.callByNeed(function (a) { |
49
|
|
|
return this[0] + a; |
50
|
|
|
}, [1, 2, 3], 1)).toBe(2); |
51
|
|
|
}); |
52
|
|
|
|
53
|
|
|
}); |
54
|
|
|
|
55
|
|
|
describe("Backgrid.Command", function () { |
56
|
|
|
|
57
|
|
|
it("can be initialized with a DOM Event instance", function () { |
58
|
|
|
var e = $.Event("keydown", { |
59
|
|
|
keyCode: 38 |
60
|
|
|
}); |
61
|
|
|
var keys = new Backgrid.Command(e); |
62
|
|
|
expect(keys.keyCode).toBe(38); |
63
|
|
|
}); |
64
|
|
|
|
65
|
|
|
it("#moveUp() returns true when the up key was pressed", function () { |
66
|
|
|
var e = $.Event("keydown", { |
67
|
|
|
keyCode: 38 |
68
|
|
|
}); |
69
|
|
|
var keys = new Backgrid.Command(e); |
70
|
|
|
expect(keys.moveUp()).toBe(true); |
71
|
|
|
}); |
72
|
|
|
|
73
|
|
|
it("#moveDown() returns true when the down key was pressed", function () { |
74
|
|
|
var e = $.Event("keydown", { |
75
|
|
|
keyCode: 40 |
76
|
|
|
}); |
77
|
|
|
var keys = new Backgrid.Command(e); |
78
|
|
|
expect(keys.moveDown()).toBe(true); |
79
|
|
|
}); |
80
|
|
|
|
81
|
|
|
it("#moveLeft() returns true when shift-tab were pressed", function () { |
82
|
|
|
var e = $.Event("keydown", { |
83
|
|
|
keyCode: 9, |
84
|
|
|
shiftKey: true |
85
|
|
|
}); |
86
|
|
|
var keys = new Backgrid.Command(e); |
87
|
|
|
expect(keys.moveLeft()).toBe(true); |
88
|
|
|
}); |
89
|
|
|
|
90
|
|
|
it("#moveRight() returns true when the tab key was pressed", function () { |
91
|
|
|
var e = $.Event("keydown", { |
92
|
|
|
keyCode: 9 |
93
|
|
|
}); |
94
|
|
|
var keys = new Backgrid.Command(e); |
95
|
|
|
expect(keys.moveRight()).toBe(true); |
96
|
|
|
}); |
97
|
|
|
|
98
|
|
|
it("#save() returns true when the enter key was pressed", function () { |
99
|
|
|
var e = $.Event("keydown", { |
100
|
|
|
keyCode: 13 |
101
|
|
|
}); |
102
|
|
|
var keys = new Backgrid.Command(e); |
103
|
|
|
expect(keys.save()).toBe(true); |
104
|
|
|
}); |
105
|
|
|
|
106
|
|
|
it("#cancel() returns true when the esc key was pressed", function () { |
107
|
|
|
var e = $.Event("keydown", { |
108
|
|
|
keyCode: 27 |
109
|
|
|
}); |
110
|
|
|
var keys = new Backgrid.Command(e); |
111
|
|
|
expect(keys.cancel()).toBe(true); |
112
|
|
|
}); |
113
|
|
|
|
114
|
|
|
it("#passThru() returns true when none of the above was true", function () { |
115
|
|
|
var e = $.Event("keydown", { |
116
|
|
|
keyCode: 32 |
117
|
|
|
}); |
118
|
|
|
var keys = new Backgrid.Command(e); |
119
|
|
|
expect(keys.passThru()).toBe(true); |
120
|
|
|
}); |
121
|
|
|
|
122
|
|
|
}); |
123
|
|
|
|