Skip to content

Commit 08d124d

Browse files
committed
Add listView async tests
1 parent 0518936 commit 08d124d

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

‎ui/tests/test.widget.listView.js‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,92 @@
8686
equal($field.html(), v.label, k + '-> Has correct label');
8787
});
8888
});
89+
90+
test('Data loading state', function() {
91+
var $listView = listView();
92+
93+
equal($listView.find('table.body tr.loading').size(), 1, 'Row has loading state');
94+
equal($listView.find('table.body tr.loading td.loading.icon').size(), 1, 'Row cell has loading icon');
95+
});
96+
97+
asyncTest('Data provider: basic', function() {
98+
expect(3);
99+
var $listView = listView({
100+
listView: {
101+
fields: {
102+
fieldA: { label: 'TestFieldA' },
103+
fieldB: { label: 'TestFieldB' }
104+
},
105+
dataProvider: function(args) {
106+
args.response.success({ data: [] });
107+
108+
ok(true, 'Data provider called');
109+
start();
110+
}
111+
}
112+
});
113+
114+
equal($listView.find('.data-table table.body tbody tr.empty td').size(), 1, 'Body table has empty table row');
115+
equal($listView.find('.data-table table.body tbody tr.empty td').html(), 'label.no.data', 'Empty contents notice displayed');
116+
});
117+
118+
asyncTest('Data provider: load data', function() {
119+
var $listView = listView({
120+
listView: {
121+
fields: {
122+
fieldA: { label: 'TestFieldA' },
123+
fieldB: { label: 'TestFieldB' }
124+
},
125+
dataProvider: function(args) {
126+
args.response.success({
127+
data: [
128+
{ fieldA: 'FieldDataA', fieldB: 'FieldDataB' }
129+
]
130+
});
131+
132+
start();
133+
}
134+
}
135+
});
136+
137+
equal($listView.find('table.body tbody tr').size(), 1, 'Body table has table row');
138+
equal($listView.find('table.body tbody tr td').size(), 2, 'Body table has table cells');
139+
equal($listView.find('table.body tbody tr td.fieldA > span').html(), 'FieldDataA', 'FieldDataA content present');
140+
equal($listView.find('table.body tbody tr td.fieldB > span').html(), 'FieldDataB', 'FieldDataB content present');
141+
});
142+
143+
asyncTest('Data provider: multiple rows of data', function() {
144+
var testData = [
145+
{ fieldA: 'FieldDataA1', fieldB: 'FieldDataB1' },
146+
{ fieldA: 'FieldDataA2', fieldB: 'FieldDataB2' },
147+
{ fieldA: 'FieldDataA3', fieldB: 'FieldDataB3' }
148+
];
149+
150+
var $listView = listView({
151+
listView: {
152+
fields: {
153+
fieldA: { label: 'TestFieldA' },
154+
fieldB: { label: 'TestFieldB' }
155+
},
156+
dataProvider: function(args) {
157+
args.response.success({
158+
data: testData
159+
});
160+
161+
start();
162+
}
163+
}
164+
});
165+
166+
equal($listView.find('table.body tbody tr').size(), 3, 'Body table has correct # of table rows');
167+
168+
$(testData).map(function(index, data) {
169+
var $tr = $listView.find('table.body tbody tr').filter(function() {
170+
return $(this).index() === index;
171+
});
172+
173+
equal($tr.find('td.fieldA > span').html(), 'FieldDataA' + (index + 1), 'FieldDataA' + (index + 1) + ' present');
174+
equal($tr.find('td.fieldB > span').html(), 'FieldDataB' + (index + 1), 'FieldDataB' + (index + 1) + ' present');
175+
});
176+
});
89177
}());

0 commit comments

Comments
 (0)