on xenial help sign in
make testCard pass
commitcaf23d81931b78aec780e650b5397ae91bedd5bf authorAlbert Astals <albert.astals@canonical.com> dateMon 5 May 2014, 13:30 (12 years ago) parent30c9fc6
1 file changed+59−64
tests/qmltests/Dash/tst_Card.qml+59−64
tests/qmltests/Dash/tst_Card.qml+59−64
@@ -186,44 +186,45 @@ Rectangle {
186186
187187 when: windowShown
188188
189+ property Item title: findChild(card, "titleLabel")
190+ property Item subtitle: findChild(card, "subtitleLabel")
189191 property var headerRow: findChild(card, "outerRow")
190192 property var art: findChild(card, "artShape")
191193 property Item artImage: findChild(card, "artImage")
194+ property Item summary: findChild(card, "summaryLabel")
195+ property Item background: findChild(card, "background")
196+ property Item backgroundLoader: findChild(card, "backgroundLoader")
197+ property Item backgroundImage: findChild(card, "backgroundImage")
198+ property Item mascotImage: findChild(card, "mascotImage");
192199
193200 function cleanup() {
194201 selector.selectedIndex = -1;
195202 }
196203
197− function test_header_binding_data() {
198− return [
199− { tag: "Mascot", property: "mascot", value: Qt.resolvedUrl("artwork/avatar.png"), index: 0 },
200− { tag: "Title", property: "title", value: "foo", index: 0 },
201− { tag: "Subtitle", property: "subtitle", value: "bar", index: 0 },
202− ];
203− }
204−
205− function test_header_binding(data) {
206− selector.selectedIndex = data.index;
207− tryCompare(testCase.header, data.property, data.value);
208− }
209−
210204 function test_card_binding_data() {
211205 return [
212− { tag: "Art", object: artImage, property: "source", value: Qt.resolvedUrl("artwork/music-player-design.png"), index: 0 },
213− { tag: "Summary", object: summary, property: "text", field: "summary", index: 0 },
214− { tag: "Fit", object: art, fill: Image.PreserveAspectFit, index: 4 },
206+ { tag: "Art", object: "artImage", property: "source", value: Qt.resolvedUrl("artwork/music-player-design.png"), index: 0 },
207+ { tag: "Summary", object: "summary", property: "text", field: "summary", index: 0 },
208+ { tag: "Fit", object: "art", fill: Image.PreserveAspectFit, index: 4 },
209+ { tag: "Mascot", object: "mascotImage", property: "source", value: Qt.resolvedUrl("artwork/avatar.png"), index: 0 },
210+ { tag: "Title", object: "title", property: "text", value: "foo", index: 0 },
211+ { tag: "Subtitle", object: "subtitle", property: "text", value: "bar", index: 0 },
215212 ];
216213 }
217214
218215 function test_card_binding(data) {
219216 selector.selectedIndex = data.index;
217+ waitForRendering(card);
218+
219+ tryCompareFunction(function() { return testCase[data.object] !== null }, true);
220+ var object = testCase[data.object];
220221
221222 if (data.hasOwnProperty('value')) {
222− tryCompare(data.object, data.property, data.value);
223+ tryCompare(object, data.property, data.value);
223224 }
224225
225226 if (data.hasOwnProperty('field')) {
226− tryCompare(data.object, data.property, card.cardData[data.field]);
227+ tryCompare(object, data.property, card.cardData[data.field]);
227228 }
228229 }
229230
@@ -232,31 +233,21 @@ Rectangle {
232233 { tag: "Medium", width: units.gu(18.5), index: 0 },
233234 { tag: "Small", width: units.gu(12), index: 1 },
234235 { tag: "Large", width: units.gu(38), index: 2 },
235− { tag: "Wide", width: units.gu(18.5), aspect: 0.5, index: 0 },
236+ { tag: "Wide", width: units.gu(18.5), index: 0 },
236237 { tag: "Horizontal", width: units.gu(38), index: 5 },
237238 // Make sure card ends with header when there's no summary
238− { tag: "NoSummary", height: function() { return headerLoader.y + headerLoader.height }, index: 6 },
239− { tag: "HorizontalNoSummary", height: function() { return headerLoader.height }, card_layout: "horizontal", index: 6 },
239+ { tag: "NoSummary", height: function() { var cardToolRow = findChild(cardTool, "outerRow");
240+ return cardToolRow.y + cardToolRow.height + units.gu(1) }, index: 6 },
241+ { tag: "HorizontalNoSummary", height: function() { return headerRow.height + units.gu(2) }, card_layout: "horizontal", index: 6 },
240242 ]
241243 }
242244
243245 function test_card_size(data) {
244− waitForRendering(card);
245246 selector.selectedIndex = data.index;
246247
247− if (data.hasOwnProperty("size")) {
248− card.template['card-size'] = data.size;
249− card.templateChanged();
250− }
251−
252248 if (data.hasOwnProperty("card_layout")) {
253− card.template['card-layout'] = data.card_layout;
254− card.templateChanged();
255− }
256−
257− if (data.hasOwnProperty("aspect")) {
258− card.components['art']['aspect-ratio'] = data.aspect;
259− card.componentsChanged();
249+ cardTool.template['card-layout'] = data.card_layout;
250+ cardTool.templateChanged();
260251 }
261252
262253 if (data.hasOwnProperty("width")) {
@@ -275,8 +266,8 @@ Rectangle {
275266 { tag: "Medium", width: units.gu(18.5), fill: Image.PreserveAspectCrop, index: 0 },
276267 { tag: "Small", width: units.gu(12), index: 1 },
277268 { tag: "Large", width: units.gu(38), index: 2 },
278− { tag: "Wide", height: units.gu(18.5) / 2, size: "large", index: 3 },
279− { tag: "Fit", height: units.gu(18.5), size: "large", width: units.gu(18.5) / 2, index: 4 },
269+ { tag: "Wide", height: units.gu(19), size: "large", index: 3 },
270+ { tag: "Fit", height: units.gu(38), size: "large", width: units.gu(19), index: 4 },
280271 { tag: "VerticalWidth", width: function() { return headerRow.width + units.gu(1) * 2 }, index: 0 },
281272 { tag: "HorizontalHeight", height: function() { return headerRow.height + units.gu(1) * 2 }, index: 5 },
282273 { tag: "HorizontalWidth", width: function() { return headerRow.x - units.gu(1) }, index: 5 },
@@ -285,18 +276,18 @@ Rectangle {
285276
286277 function test_art_size(data) {
287278 selector.selectedIndex = data.index;
288− tryCompareFunction(function() { return art !== null }, true);
289−
290279 if (data.hasOwnProperty("size")) {
291− card.template['card-size'] = data.size;
292− card.templateChanged();
280+ cardTool.template['card-size'] = data.size;
281+ cardTool.templateChanged();
293282 }
294283
295284 if (data.hasOwnProperty("aspect")) {
296− card.components['art']['aspect-ratio'] = data.aspect;
297− card.componentsChanged();
285+ cardTool.components['art']['aspect-ratio'] = data.aspect;
286+ cardTool.componentsChanged();
298287 }
299288
289+ waitForRendering(card);
290+
300291 if (data.hasOwnProperty("width")) {
301292 if (typeof data.width === "function") {
302293 tryCompareFunction(function() { return art.width === data.width() }, true);
@@ -323,32 +314,33 @@ Rectangle {
323314
324315 function test_art_layout(data) {
325316 selector.selectedIndex = data.index;
326− tryCompareFunction(function() { return art !== null }, true);
317+ waitForRendering(card);
327318
328319 tryCompare(headerRow, "x", data.left());
329320 }
330321
331322 function test_header_layout_data() {
332323 return [
333− { tag: "Vertical", top: function() { return art.y + art.height },
334− left: function() { return art.x }, index: 0 },
335− { tag: "Horizontal", top: function() { return art.y },
336− left: function() { return art.x + art.width }, index: 5 },
337− { tag: "Overlay", top: function() { return art.y + art.height - header.height },
338− left: function() { return art.x }, index: 9 },
324+ { tag: "Vertical", top: function() { return art.y + art.height + units.gu(1) },
325+ left: function() { return art.x + units.gu(1) }, index: 0 },
326+ { tag: "Horizontal", top: function() { return art.y + units.gu(1) },
327+ left: function() { return art.x + art.width + units.gu(1) }, index: 5 },
328+ { tag: "Overlay", top: function() { return art.y + art.height - headerRow.height - units.gu(1) },
329+ left: function() { return art.x + units.gu(1) }, index: 9 },
339330 ]
340331 }
341332
342333 function test_header_layout(data) {
343334 selector.selectedIndex = data.index;
335+ waitForRendering(card);
344336
345− tryCompareFunction(function() { return testCase.headerLoader.y === data.top() }, true);
346− tryCompareFunction(function() { return testCase.headerLoader.x === data.left() }, true);
337+ tryCompareFunction(function() { return testCase.headerRow.y === data.top() }, true);
338+ tryCompareFunction(function() { return testCase.headerRow.x === data.left() }, true);
347339 }
348340
349341 function test_summary_layout_data() {
350342 return [
351− { tag: "With header", top: function() { return headerLoader.y + headerLoader.height }, index: 0 },
343+ { tag: "With header", top: function() { return headerRow.y + headerRow.height + units.gu(1); }, index: 0 },
352344 { tag: "Without header", top: function() { return art.y + art.height }, index: 7 },
353345 ]
354346 }
@@ -356,16 +348,16 @@ Rectangle {
356348 function test_summary_layout(data) {
357349 selector.selectedIndex = data.index;
358350
351+ waitForRendering(card);
352+
359353 tryCompareFunction(function() { return testCase.summary.y === data.top() }, true);
360354 }
361355
362356 function test_art_visibility() {
363357 selector.selectedIndex = 8;
364358
365− tryCompare(testCase.artImage, "source", "");
366− compare(testCase.art.visible, false);
367− compare(testCase.art.height, 0);
368− compare(testCase.art.width, 0);
359+ compare(testCase.artImage, null);
360+ compare(testCase.art, null);
369361 }
370362
371363 function test_background_data() {
@@ -393,7 +385,11 @@ Rectangle {
393385
394386 waitForRendering(card);
395387
396− tryCompare(backgroundLoader, "active", data.visible);
388+ if (data.visible) {
389+ tryCompare(backgroundLoader, "active", true);
390+ } else {
391+ compare(backgroundLoader, null);
392+ }
397393
398394 if (data.hasOwnProperty("color")) {
399395 tryCompare(background, "color", data.color);
@@ -440,13 +436,15 @@ Rectangle {
440436
441437 function test_fontColor(data) {
442438 selector.selectedIndex = 10;
439+ waitForRendering(card);
443440
444441 background.color = data.tag;
445442
446443 var fontColor = data.dark ? "grey" : "white";
447444
448445 tryCompareFunction(function() { return Qt.colorEqual(summary.color, fontColor); }, true);
449− tryCompareFunction(function() { return Qt.colorEqual(header.fontColor, fontColor); }, true);
446+ tryCompareFunction(function() { return Qt.colorEqual(title.color, fontColor); }, true);
447+ tryCompareFunction(function() { return Qt.colorEqual(subtitle.color, fontColor); }, true);
450448 }
451449
452450 function test_mascotShape_data() {
@@ -459,15 +457,12 @@ Rectangle {
459457
460458 function test_mascotShape(data) {
461459 selector.selectedIndex = data.index;
460+ waitForRendering(card);
462461
463462 var shape = findChild(card, "mascotShapeLoader");
464− var image = findChild(card, "mascotImage");
465−
466− verify(shape, "Could not find shape.");
467− verify(image, "Could not find image.");
468463
469− tryCompare(shape, "active", data.shape);
470− tryCompare(image, "visible", !data.shape);
464+ compare(shape !== null, data.shape);
465+ tryCompare(mascotImage, "visible", !data.shape);
471466 }
472467 }
473468}