Skip to content

Commit ab42946

Browse files
committed
List view: tests for field rendering
1 parent 0bff705 commit ab42946

1 file changed

Lines changed: 71 additions & 24 deletions

File tree

ui/tests/test.widget.listView.js

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,75 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
module('List view', {
19-
setup: function() {
20-
window.pageSize = 20;
21-
},
22-
teardown: function() {
23-
delete window.pageSize;
24-
}
25-
});
26-
27-
test('Basic', function() {
28-
var $listView = $('<div>').listView({
29-
listView: {
30-
fields: {},
31-
dataProvider: function() {}
18+
(function() {
19+
var listView = function(args) {
20+
var basicArgs = {
21+
listView: {
22+
fields: {},
23+
dataProvider: function() {}
24+
}
25+
};
26+
27+
return $('<div>').listView(
28+
$.extend(true, {}, basicArgs, args)
29+
).find('.list-view');
30+
};
31+
32+
module('List view', {
33+
setup: function() {
34+
window.pageSize = 20;
35+
},
36+
teardown: function() {
37+
delete window.pageSize;
3238
}
33-
}).find('.list-view');
34-
var $toolbar = $listView.find('> .toolbar');
35-
var $table = $listView.find('> .data-table');
36-
37-
equal($listView.size(), 1, 'List view present');
38-
equal($toolbar.size(), 1, 'Toolbar present');
39-
equal($table.size(), 1, 'Data table div present');
40-
equal($table.find('> .fixed-header table thead tr').size(), 1, 'Fixed header present');
41-
equal($table.find('> table.body tbody').size(), 1, 'Body table present');
42-
});
39+
});
40+
41+
test('Basic', function() {
42+
var $listView = listView();
43+
var $toolbar = $listView.find('> .toolbar');
44+
var $table = $listView.find('> .data-table');
45+
46+
equal($listView.size(), 1, 'List view present');
47+
equal($toolbar.size(), 1, 'Toolbar present');
48+
equal($table.size(), 1, 'Data table div present');
49+
equal($table.find('> .fixed-header table thead tr').size(), 1, 'Fixed header present');
50+
equal($table.find('> table.body tbody').size(), 1, 'Body table present');
51+
});
52+
53+
test('Fields: basic', function() {
54+
var $listView = listView({
55+
listView: {
56+
fields: {
57+
fieldA: { label: 'TestFieldA' }
58+
}
59+
}
60+
});
61+
var $fields = $listView.find('.fixed-header table thead tr th');
62+
63+
equal($fields.size(), 1, 'Column present');
64+
ok($fields.hasClass('fieldA'), 'Has ID as classname');
65+
equal($fields.html(), 'TestFieldA', 'Has correct label');
66+
});
67+
68+
test('Fields: n columns', function() {
69+
var testFields = {
70+
fieldA: { label: 'TestFieldA' },
71+
fieldB: { label: 'TestFieldB' },
72+
fieldC: { label: 'TestFieldC' }
73+
};
74+
75+
var $listView = listView({
76+
listView: {
77+
fields: testFields
78+
}
79+
});
80+
var $fields = $listView.find('.fixed-header table thead tr th');
81+
82+
$.each(testFields, function(k, v) {
83+
var $field = $fields.filter('.' + k);
84+
85+
equal($field.size(), 1, k + '-> Column present');
86+
equal($field.html(), v.label, k + '-> Has correct label');
87+
});
88+
});
89+
}());

0 commit comments

Comments
 (0)