on xenial help sign in
make testCard pass
caf23d8Albert Astals
tests/qmltests/Dash/tst_Card.qml+59−64
@@ -186,44 +186,45 @@ Rectangle {
186
186
187 when: windowShown
187 when: windowShown
188
188
189+ property Item title: findChild(card, "titleLabel")
190+ property Item subtitle: findChild(card, "subtitleLabel")
189 property var headerRow: findChild(card, "outerRow")
191 property var headerRow: findChild(card, "outerRow")
190 property var art: findChild(card, "artShape")
192 property var art: findChild(card, "artShape")
191 property Item artImage: findChild(card, "artImage")
193 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");
192
199
193 function cleanup() {
200 function cleanup() {
194 selector.selectedIndex = -1;
201 selector.selectedIndex = -1;
195 }
202 }
196
203
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−
210 function test_card_binding_data() {
204 function test_card_binding_data() {
211 return [
205 return [
212− { tag: "Art", object: artImage, property: "source", value: Qt.resolvedUrl("artwork/music-player-design.png"), index: 0 },
206+ { 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 },
207+ { tag: "Summary", object: "summary", property: "text", field: "summary", index: 0 },
214− { tag: "Fit", object: art, fill: Image.PreserveAspectFit, index: 4 },
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 },
215 ];
212 ];
216 }
213 }
217
214
218 function test_card_binding(data) {
215 function test_card_binding(data) {
219 selector.selectedIndex = data.index;
216 selector.selectedIndex = data.index;
217+ waitForRendering(card);
218+
219+ tryCompareFunction(function() { return testCase[data.object] !== null }, true);
220+ var object = testCase[data.object];
220
221
221 if (data.hasOwnProperty('value')) {
222 if (data.hasOwnProperty('value')) {
222− tryCompare(data.object, data.property, data.value);
223+ tryCompare(object, data.property, data.value);
223 }
224 }
224
225
225 if (data.hasOwnProperty('field')) {
226 if (data.hasOwnProperty('field')) {
226− tryCompare(data.object, data.property, card.cardData[data.field]);
227+ tryCompare(object, data.property, card.cardData[data.field]);
227 }
228 }
228 }
229 }
229
230
@@ -232,31 +233,21 @@ Rectangle {
232 { tag: "Medium", width: units.gu(18.5), index: 0 },
233 { tag: "Medium", width: units.gu(18.5), index: 0 },
233 { tag: "Small", width: units.gu(12), index: 1 },
234 { tag: "Small", width: units.gu(12), index: 1 },
234 { tag: "Large", width: units.gu(38), index: 2 },
235 { 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 },
236 { tag: "Horizontal", width: units.gu(38), index: 5 },
237 { tag: "Horizontal", width: units.gu(38), index: 5 },
237 // Make sure card ends with header when there's no summary
238 // 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: "NoSummary", height: function() { var cardToolRow = findChild(cardTool, "outerRow");
240+ return cardToolRow.y + cardToolRow.height + units.gu(1) }, index: 6 },
239− { tag: "HorizontalNoSummary", height: function() { return headerLoader.height }, card_layout: "horizontal", index: 6 },
241+ { tag: "HorizontalNoSummary", height: function() { return headerRow.height + units.gu(2) }, card_layout: "horizontal", index: 6 },
240 ]
242 ]
241 }
243 }
242
244
243 function test_card_size(data) {
245 function test_card_size(data) {
244− waitForRendering(card);
245 selector.selectedIndex = data.index;
246 selector.selectedIndex = data.index;
246
247
247− if (data.hasOwnProperty("size")) {
248− card.template['card-size'] = data.size;
249− card.templateChanged();
250− }
251−
252 if (data.hasOwnProperty("card_layout")) {
248 if (data.hasOwnProperty("card_layout")) {
253− card.template['card-layout'] = data.card_layout;
249+ cardTool.template['card-layout'] = data.card_layout;
254− card.templateChanged();
250+ cardTool.templateChanged();
255− }
256−
257− if (data.hasOwnProperty("aspect")) {
258− card.components['art']['aspect-ratio'] = data.aspect;
259− card.componentsChanged();
260 }
251 }
261
252
262 if (data.hasOwnProperty("width")) {
253 if (data.hasOwnProperty("width")) {
@@ -275,8 +266,8 @@ Rectangle {
275 { tag: "Medium", width: units.gu(18.5), fill: Image.PreserveAspectCrop, index: 0 },
266 { tag: "Medium", width: units.gu(18.5), fill: Image.PreserveAspectCrop, index: 0 },
276 { tag: "Small", width: units.gu(12), index: 1 },
267 { tag: "Small", width: units.gu(12), index: 1 },
277 { tag: "Large", width: units.gu(38), index: 2 },
268 { tag: "Large", width: units.gu(38), index: 2 },
278− { tag: "Wide", height: units.gu(18.5) / 2, size: "large", index: 3 },
269+ { tag: "Wide", height: units.gu(19), size: "large", index: 3 },
279− { tag: "Fit", height: units.gu(18.5), size: "large", width: units.gu(18.5) / 2, index: 4 },
270+ { tag: "Fit", height: units.gu(38), size: "large", width: units.gu(19), index: 4 },
280 { tag: "VerticalWidth", width: function() { return headerRow.width + units.gu(1) * 2 }, index: 0 },
271 { tag: "VerticalWidth", width: function() { return headerRow.width + units.gu(1) * 2 }, index: 0 },
281 { tag: "HorizontalHeight", height: function() { return headerRow.height + units.gu(1) * 2 }, index: 5 },
272 { tag: "HorizontalHeight", height: function() { return headerRow.height + units.gu(1) * 2 }, index: 5 },
282 { tag: "HorizontalWidth", width: function() { return headerRow.x - units.gu(1) }, index: 5 },
273 { tag: "HorizontalWidth", width: function() { return headerRow.x - units.gu(1) }, index: 5 },
@@ -285,18 +276,18 @@ Rectangle {
285
276
286 function test_art_size(data) {
277 function test_art_size(data) {
287 selector.selectedIndex = data.index;
278 selector.selectedIndex = data.index;
288− tryCompareFunction(function() { return art !== null }, true);
289−
290 if (data.hasOwnProperty("size")) {
279 if (data.hasOwnProperty("size")) {
291− card.template['card-size'] = data.size;
280+ cardTool.template['card-size'] = data.size;
292− card.templateChanged();
281+ cardTool.templateChanged();
293 }
282 }
294
283
295 if (data.hasOwnProperty("aspect")) {
284 if (data.hasOwnProperty("aspect")) {
296− card.components['art']['aspect-ratio'] = data.aspect;
285+ cardTool.components['art']['aspect-ratio'] = data.aspect;
297− card.componentsChanged();
286+ cardTool.componentsChanged();
298 }
287 }
299
288
289+ waitForRendering(card);
290+
300 if (data.hasOwnProperty("width")) {
291 if (data.hasOwnProperty("width")) {
301 if (typeof data.width === "function") {
292 if (typeof data.width === "function") {
302 tryCompareFunction(function() { return art.width === data.width() }, true);
293 tryCompareFunction(function() { return art.width === data.width() }, true);
@@ -323,32 +314,33 @@ Rectangle {
323
314
324 function test_art_layout(data) {
315 function test_art_layout(data) {
325 selector.selectedIndex = data.index;
316 selector.selectedIndex = data.index;
326− tryCompareFunction(function() { return art !== null }, true);
317+ waitForRendering(card);
327
318
328 tryCompare(headerRow, "x", data.left());
319 tryCompare(headerRow, "x", data.left());
329 }
320 }
330
321
331 function test_header_layout_data() {
322 function test_header_layout_data() {
332 return [
323 return [
333− { tag: "Vertical", top: function() { return art.y + art.height },
324+ { tag: "Vertical", top: function() { return art.y + art.height + units.gu(1) },
334− left: function() { return art.x }, index: 0 },
325+ left: function() { return art.x + units.gu(1) }, index: 0 },
335− { tag: "Horizontal", top: function() { return art.y },
326+ { tag: "Horizontal", top: function() { return art.y + units.gu(1) },
336− left: function() { return art.x + art.width }, index: 5 },
327+ left: function() { return art.x + art.width + units.gu(1) }, index: 5 },
337− { tag: "Overlay", top: function() { return art.y + art.height - header.height },
328+ { tag: "Overlay", top: function() { return art.y + art.height - headerRow.height - units.gu(1) },
338− left: function() { return art.x }, index: 9 },
329+ left: function() { return art.x + units.gu(1) }, index: 9 },
339 ]
330 ]
340 }
331 }
341
332
342 function test_header_layout(data) {
333 function test_header_layout(data) {
343 selector.selectedIndex = data.index;
334 selector.selectedIndex = data.index;
335+ waitForRendering(card);
344
336
345− tryCompareFunction(function() { return testCase.headerLoader.y === data.top() }, true);
337+ tryCompareFunction(function() { return testCase.headerRow.y === data.top() }, true);
346− tryCompareFunction(function() { return testCase.headerLoader.x === data.left() }, true);
338+ tryCompareFunction(function() { return testCase.headerRow.x === data.left() }, true);
347 }
339 }
348
340
349 function test_summary_layout_data() {
341 function test_summary_layout_data() {
350 return [
342 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 },
352 { tag: "Without header", top: function() { return art.y + art.height }, index: 7 },
344 { tag: "Without header", top: function() { return art.y + art.height }, index: 7 },
353 ]
345 ]
354 }
346 }
@@ -356,16 +348,16 @@ Rectangle {
356 function test_summary_layout(data) {
348 function test_summary_layout(data) {
357 selector.selectedIndex = data.index;
349 selector.selectedIndex = data.index;
358
350
351+ waitForRendering(card);
352+
359 tryCompareFunction(function() { return testCase.summary.y === data.top() }, true);
353 tryCompareFunction(function() { return testCase.summary.y === data.top() }, true);
360 }
354 }
361
355
362 function test_art_visibility() {
356 function test_art_visibility() {
363 selector.selectedIndex = 8;
357 selector.selectedIndex = 8;
364
358
365− tryCompare(testCase.artImage, "source", "");
359+ compare(testCase.artImage, null);
366− compare(testCase.art.visible, false);
360+ compare(testCase.art, null);
367− compare(testCase.art.height, 0);
368− compare(testCase.art.width, 0);
369 }
361 }
370
362
371 function test_background_data() {
363 function test_background_data() {
@@ -393,7 +385,11 @@ Rectangle {
393
385
394 waitForRendering(card);
386 waitForRendering(card);
395
387
396− tryCompare(backgroundLoader, "active", data.visible);
388+ if (data.visible) {
389+ tryCompare(backgroundLoader, "active", true);
390+ } else {
391+ compare(backgroundLoader, null);
392+ }
397
393
398 if (data.hasOwnProperty("color")) {
394 if (data.hasOwnProperty("color")) {
399 tryCompare(background, "color", data.color);
395 tryCompare(background, "color", data.color);
@@ -440,13 +436,15 @@ Rectangle {
440
436
441 function test_fontColor(data) {
437 function test_fontColor(data) {
442 selector.selectedIndex = 10;
438 selector.selectedIndex = 10;
439+ waitForRendering(card);
443
440
444 background.color = data.tag;
441 background.color = data.tag;
445
442
446 var fontColor = data.dark ? "grey" : "white";
443 var fontColor = data.dark ? "grey" : "white";
447
444
448 tryCompareFunction(function() { return Qt.colorEqual(summary.color, fontColor); }, true);
445 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);
450 }
448 }
451
449
452 function test_mascotShape_data() {
450 function test_mascotShape_data() {
@@ -459,15 +457,12 @@ Rectangle {
459
457
460 function test_mascotShape(data) {
458 function test_mascotShape(data) {
461 selector.selectedIndex = data.index;
459 selector.selectedIndex = data.index;
460+ waitForRendering(card);
462
461
463 var shape = findChild(card, "mascotShapeLoader");
462 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.");
468
463
469− tryCompare(shape, "active", data.shape);
464+ compare(shape !== null, data.shape);
470− tryCompare(image, "visible", !data.shape);
465+ tryCompare(mascotImage, "visible", !data.shape);
471 }
466 }
472 }
467 }
473}
468}