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("A Column", function () { |
9
|
|
|
|
10
|
|
|
it("must be initialized with at least name and cell", function () { |
11
|
|
|
expect(function () { |
12
|
|
|
new Backgrid.Column({ |
13
|
|
|
name: "name", |
14
|
|
|
cell: 1 |
15
|
|
|
}); |
16
|
|
|
}).not.toThrow(); |
17
|
|
|
}); |
18
|
|
|
|
19
|
|
|
it("has a label the same as name if no label given", function () { |
20
|
|
|
var col = new Backgrid.Column({ |
21
|
|
|
name: "name", |
22
|
|
|
cell: 1 |
23
|
|
|
}); |
24
|
|
|
|
25
|
|
|
expect(col.get("label")).toBe("name"); |
26
|
|
|
}); |
27
|
|
|
|
28
|
|
|
it("sortValue can be a string or a function", function () { |
29
|
|
|
var Col = Backgrid.Column.extend({ |
30
|
|
|
mySortValue: function () {} |
31
|
|
|
}); |
32
|
|
|
|
33
|
|
|
var col = new Col({ |
34
|
|
|
name: "name", |
35
|
|
|
cell: "string", |
36
|
|
|
sortValue: "mySortValue" |
37
|
|
|
}); |
38
|
|
|
|
39
|
|
|
expect(col.sortValue()).toBe(Col.prototype.mySortValue); |
40
|
|
|
|
41
|
|
|
var mySortValue = function () {}; |
42
|
|
|
col = new Col({ |
43
|
|
|
name: "name", |
44
|
|
|
cell: "string", |
45
|
|
|
sortValue: mySortValue |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
expect(col.sortValue()).toBe(mySortValue); |
49
|
|
|
}); |
50
|
|
|
|
51
|
|
|
it("sortable can be a string or a boolean or a function", function () { |
52
|
|
|
var Col = Backgrid.Column.extend({ |
53
|
|
|
mySortable: function () {} |
54
|
|
|
}); |
55
|
|
|
|
56
|
|
|
var col = new Col({ |
57
|
|
|
name: "name", |
58
|
|
|
cell: "string", |
59
|
|
|
sortable: "mySortable" |
60
|
|
|
}); |
61
|
|
|
|
62
|
|
|
expect(col.sortable()).toBe(Col.prototype.mySortable); |
63
|
|
|
|
64
|
|
|
col = new Col({ |
65
|
|
|
name: "name", |
66
|
|
|
cell: "string", |
67
|
|
|
sortable: false |
68
|
|
|
}); |
69
|
|
|
|
70
|
|
|
expect(col.sortable()).toBe(false); |
71
|
|
|
|
72
|
|
|
col = new Col({ |
73
|
|
|
name: "name", |
74
|
|
|
cell: "string", |
75
|
|
|
sortable: function () { |
76
|
|
|
return false; |
77
|
|
|
} |
78
|
|
|
}); |
79
|
|
|
|
80
|
|
|
expect(col.sortable()).toBe(col.get("sortable")); |
81
|
|
|
}); |
82
|
|
|
|
83
|
|
|
it("editable can be a string or a boolean or a function", function () { |
84
|
|
|
var Col = Backgrid.Column.extend({ |
85
|
|
|
myEditable: function () {} |
86
|
|
|
}); |
87
|
|
|
|
88
|
|
|
var col = new Col({ |
89
|
|
|
name: "name", |
90
|
|
|
cell: "string", |
91
|
|
|
editable: "myEditable" |
92
|
|
|
}); |
93
|
|
|
|
94
|
|
|
expect(col.editable()).toBe(Col.prototype.myEditable); |
95
|
|
|
|
96
|
|
|
col = new Col({ |
97
|
|
|
name: "name", |
98
|
|
|
cell: "string", |
99
|
|
|
editable: false |
100
|
|
|
}); |
101
|
|
|
|
102
|
|
|
expect(col.editable()).toBe(false); |
103
|
|
|
|
104
|
|
|
col = new Col({ |
105
|
|
|
name: "name", |
106
|
|
|
cell: "string", |
107
|
|
|
editable: function () { |
108
|
|
|
return false; |
109
|
|
|
} |
110
|
|
|
}); |
111
|
|
|
|
112
|
|
|
expect(col.editable()).toBe(col.get("editable")); |
113
|
|
|
}); |
114
|
|
|
|
115
|
|
|
it("renderable can be a string or a boolean or a function", function () { |
116
|
|
|
var Col = Backgrid.Column.extend({ |
117
|
|
|
myRenderable: function () {} |
118
|
|
|
}); |
119
|
|
|
|
120
|
|
|
var col = new Col({ |
121
|
|
|
name: "name", |
122
|
|
|
cell: "string", |
123
|
|
|
renderable: "myRenderable" |
124
|
|
|
}); |
125
|
|
|
|
126
|
|
|
expect(col.renderable()).toBe(Col.prototype.myRenderable); |
127
|
|
|
|
128
|
|
|
col = new Col({ |
129
|
|
|
name: "name", |
130
|
|
|
cell: "string", |
131
|
|
|
renderable: false |
132
|
|
|
}); |
133
|
|
|
|
134
|
|
|
expect(col.renderable()).toBe(false); |
135
|
|
|
|
136
|
|
|
col = new Col({ |
137
|
|
|
name: "name", |
138
|
|
|
cell: "string", |
139
|
|
|
renderable: function () { |
140
|
|
|
return false; |
141
|
|
|
} |
142
|
|
|
}); |
143
|
|
|
|
144
|
|
|
expect(col.renderable()).toBe(col.get("renderable")); |
145
|
|
|
}); |
146
|
|
|
|
147
|
|
|
}); |
148
|
|
|
|
149
|
|
|
describe("A Columns", function () { |
150
|
|
|
|
151
|
|
|
it("is a Backbone.Collection of Column objects", function () { |
152
|
|
|
expect(new Backgrid.Columns().model).toBe(Backgrid.Column); |
153
|
|
|
}); |
154
|
|
|
|
155
|
|
|
it("has access to Backbone.PageableCollection", function () { |
156
|
|
|
expect(typeof Backbone.PageableCollection).toBe('function'); |
157
|
|
|
}); |
158
|
|
|
|
159
|
|
|
}); |
160
|
|
|
|