-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathgrid_test.js
87 lines (79 loc) · 2.76 KB
/
grid_test.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
steal("jquery", "canui/grid", 'funcunit/qunit').then(function ($) {
module("can.ui.Grid");
var columns = [
{
content : "name",
header : "Name"
},
{
content : "age",
header : "Age"
}
];
test("Initialize empty, live binding columns", function () {
var container = $('<table>').appendTo('#qunit-test-area');
container.grid({
columns : columns
});
equal(container.find('th').length, 2, 'Both columns rendered as table headings');
ok(container.find('td:contains("No data")').length, 'Empty text columns exists');
equal(container.grid('list').length, 0, 'Grid item list is empty');
container.grid('columns').pop();
equal(container.find('th').length, 1, 'Column removed, only one left');
container.grid('columns').attr('0.header', 'Live binding');
equal($.trim(container.find('th:first').html()), 'Live binding', 'Live updated column content');
});
test("Initialize content", function() {
var container = $('<table>').appendTo('#qunit-test-area');
container.grid({
columns : columns,
loading : 'Loading...',
empty : 'Nothing found'
});
var dfd = can.Deferred();
container.grid('list', dfd);
equal(can.$.trim(container.find('td:first').html()), 'Loading...', 'Showing loading content');
dfd.resolve([]);
equal(can.$.trim(container.find('td:first').html()), 'Nothing found', 'Showing empty content');
var compute = can.compute([{ name : 'Compute', age : 23 }]);
container.grid('list', compute);
equal(can.$.trim(container.find('td:first').html()), 'Compute', 'Got compute array');
dfd = can.Deferred();
compute(dfd);
equal(can.$.trim(container.find('td:first').html()), 'Loading...', 'Showing loading content');
dfd.resolve([{ name : 'Updated', age : 230 }]);
equal(can.$.trim(container.find('td:first').html()), 'Updated', 'Got compute array');
});
test("Computed columns", function() {
var container = $('<table>').appendTo('#qunit-test-area');
container.grid({
columns : [{
name : "Person",
content : function(observe) {
return observe.attr('name') + ' (' + observe.attr('age') + ')';
}
}],
list : [{
name : 'John',
age : 23
}]
});
equal(can.$.trim(container.find('td:first').html()), 'John (23)', 'Rendering computed property');
var list = container.grid('list');
ok(list instanceof can.Observe.List, 'List passed through properly');
list[0].attr('age', 50);
equal(can.$.trim(container.find('td:first').html()), 'John (50)', 'Live binding compute');
});
/* TODO how to test this best?
test("tableScroll", function() {
var container = $('<table>').appendTo('#qunit-test-area');
container.grid({
columns : columns,
loading : function() { return 'Loading...'; },
empty : function() { return 'Nothing found' },
scrollable : true,
list : []
});
});
*/
});