on xenial help sign in
Fix CardHeader and Card heights (empty Label does have non-zero height apparently).

Also improve test robustness and reduce future diffs. Approved by PS Jenkins bot, Michał Karnicki.

commitbe2d485445f4df9ca9efd408c0ca06def5b9dfc6 authorMichał Sawicz <michal.sawicz@canonical.com> dateTue 28 Jan 2014, 10:56 (13 years ago) parent1b4cec46e2fe79
4 files changed+40−13
qml/Dash/Card.qml+1 qml/Dash/CardHeader.qml+5−1 tests/qmltests/Dash/tst_Card.qml+21−4 tests/qmltests/Dash/tst_CardHeader.qml+13−8
qml/Dash/Card.qml+1
@@ -79,5 +79,6 @@ Item {
7979 maximumLineCount: 5
8080 elide: Text.ElideRight
8181 text: cardData && cardData["summary"] || ""
82+ height: text ? implicitHeight : 0
8283 }
8384}
qml/Dash/CardHeader.qml+5−1
@@ -56,9 +56,9 @@ Item {
5656
5757 Label {
5858 id: titleLabel
59+ objectName: "titleLabel"
5960 anchors { left: parent.left; right: parent.right }
6061 elide: Text.ElideRight
61− objectName: "titleLabel"
6262 font.weight: Font.DemiBold
6363 wrapMode: Text.Wrap
6464 maximumLineCount: 2
@@ -66,6 +66,7 @@ Item {
6666
6767 Label {
6868 id: subtitleLabel
69+ objectName: "subtitleLabel"
6970 anchors { left: parent.left; right: parent.right }
7071 elide: Text.ElideRight
7172 visible: titleLabel.text && text
@@ -90,6 +91,7 @@ Item {
9091 elide: Text.ElideRight
9192 font.weight: Font.DemiBold
9293 color: Theme.palette.selected.foreground
94+ visible: text
9395 }
9496
9597 Label {
@@ -98,6 +100,7 @@ Item {
98100 width: parent.labelWidth
99101 elide: Text.ElideRight
100102 horizontalAlignment: parent.labels === 3 ? Text.AlignHCenter : Text.AlignRight
103+ visible: text
101104 }
102105
103106 Label {
@@ -105,6 +108,7 @@ Item {
105108 width: parent.labelWidth
106109 elide: Text.ElideRight
107110 horizontalAlignment: Text.AlignRight
111+ visible: text
108112 }
109113 }
110114 }
tests/qmltests/Dash/tst_Card.qml+21−4
@@ -106,6 +106,10 @@ Rectangle {
106106 "layout": { "template": { "card-layout": "horizontal" },
107107 "components": JSON.parse(fullMapping) }
108108 },
109+ {
110+ "name": "Art, header - vertical",
111+ "layout": { "components": Helpers.update(JSON.parse(root.fullMapping), { "summary": undefined }) }
112+ },
109113 ]
110114
111115 Card {
@@ -189,7 +193,10 @@ Rectangle {
189193 property Item summary: findChild(card, "summaryLabel")
190194
191195 function initTestCase() {
192− verify(testCase.header !== undefined, "Couldn't find header object.");
196+ verify(typeof testCase.header === "object", "Couldn't find header object.");
197+ verify(typeof testCase.art === "object", "Couldn't find art object.");
198+ verify(typeof testCase.artImage === "object", "Couldn't find artImage object.");
199+ verify(typeof testCase.summary === "object", "Couldn't find summary object.");
193200 }
194201
195202 function cleanup() {
@@ -237,6 +244,9 @@ Rectangle {
237244 { tag: "Large", width: units.gu(38), size: "large", index: 0 },
238245 { tag: "Wide", width: units.gu(18.5), aspect: 0.5, index: 0 },
239246 { tag: "Horizontal", width: units.gu(38), index: 5 },
247+ // Make sure card ends with header when there's no summary
248+ { tag: "NoSummary", height: function() { return header.y + header.height }, index: 6 },
249+ { tag: "HorizontalNoSummary", height: function() { return header.height }, card_layout: "horizontal", index: 6 },
240250 ]
241251 }
242252
@@ -248,6 +258,11 @@ Rectangle {
248258 card.templateChanged();
249259 }
250260
261+ if (data.hasOwnProperty("card_layout")) {
262+ card.template['card-layout'] = data.card_layout;
263+ card.templateChanged();
264+ }
265+
251266 if (data.hasOwnProperty("aspect")) {
252267 card.components['art']['aspect-ratio'] = data.aspect;
253268 card.componentsChanged();
@@ -257,7 +272,9 @@ Rectangle {
257272 tryCompare(card, "width", data.width);
258273 }
259274
260− if (data.hasOwnProperty("height")) {
275+ if (typeof data.height === "function") {
276+ tryCompareFunction(function() { return card.height === data.height() }, true);
277+ } else if (data.hasOwnProperty("height")) {
261278 tryCompare(card, "height", data.height);
262279 }
263280 }
@@ -308,7 +325,7 @@ Rectangle {
308325 function test_art_layout_data() {
309326 return [
310327 { tag: "Vertical", left: function() { return 0 }, index: 0},
311− { tag: "Horizontal", left: function() { return art.width }, index: 5 }
328+ { tag: "Horizontal", left: function() { return art.width }, index: 5 },
312329 ];
313330 }
314331
@@ -323,7 +340,7 @@ Rectangle {
323340 { tag: "Vertical", top: function() { return art.y + art.height },
324341 left: function() { return art.x }, index: 0 },
325342 { tag: "Horizontal", top: function() { return art.y },
326− left: function() { return art.x + art.width }, index: 5 }
343+ left: function() { return art.x + art.width }, index: 5 },
327344 ]
328345 }
329346
tests/qmltests/Dash/tst_CardHeader.qml+13−8
@@ -52,11 +52,11 @@ Rectangle {
5252 property Item column: findChild(cardHeader, "column")
5353
5454 function initTestCase() {
55− verify(testCase.mascot !== undefined, "Couldn't find mascot object.");
56− verify(testCase.titleLabel !== undefined, "Couldn't find titleLabel object.");
57− verify(testCase.subtitleLabel !== undefined, "Couldn't find subtitleLabel object.");
58− verify(testCase.prices !== undefined, "Couldn't find prices object.");
59− verify(testCase.oldPriceLabel !== undefined, "Couldn't find oldPriceLabel object.");
55+ verify(typeof testCase.mascot === "object", "Couldn't find mascot object.");
56+ verify(typeof testCase.titleLabel === "object", "Couldn't find titleLabel object.");
57+ verify(typeof testCase.subtitleLabel === "object", "Couldn't find subtitleLabel object.");
58+ verify(typeof testCase.prices === "object", "Couldn't find prices object.");
59+ verify(typeof testCase.oldPriceLabel === "object", "Couldn't find oldPriceLabel object.");
6060 }
6161
6262 function cleanup() {
@@ -86,7 +86,7 @@ Rectangle {
8686 { tag: "Empty", visible: false },
8787 { tag: "Title only", title: "Foo", visible: true },
8888 { tag: "Subtitle only", subtitle: "Bar", visible: false },
89− { tag: "Both", title: "Foo", subtitle: "Bar", visible: true }
89+ { tag: "Both", title: "Foo", subtitle: "Bar", visible: true },
9090 ]
9191 }
9292
@@ -104,7 +104,7 @@ Rectangle {
104104 { tag: "Main and Alt", main: "$1.25", alt: "€1.00", visible: true },
105105 { tag: "Main and Old", main: "$1.25", old: "$2.00", visible: true, oldAlign: Text.AlignRight },
106106 { tag: "Alt and Old", alt: "€1.00", old: "$2.00", visible: false },
107− { tag: "All", main: "$1.25", alt: "€1.00", old: "$2.00", visible: true, oldAlign: Text.AlignHCenter }
107+ { tag: "All", main: "$1.25", alt: "€1.00", old: "$2.00", visible: true, oldAlign: Text.AlignHCenter },
108108 ]
109109 }
110110
@@ -121,7 +121,8 @@ Rectangle {
121121 function test_dimensions_data() {
122122 return [
123123 { tag: "Column width", object: column, width: cardHeader.width - testCase.outerRow.spacing * 2 },
124− { tag: "Column width", object: column, width: cardHeader.width - mascot.width - testCase.outerRow.spacing * 3, mascot: "artwork/avatar.png" }
124+ { tag: "Column width", object: column, width: cardHeader.width - mascot.width - testCase.outerRow.spacing * 3, mascot: "artwork/avatar.png" },
125+ { tag: "Header height", object: cardHeader, height: function() { return subtitleLabel.y + subtitleLabel.height + outerRow.spacing * 2 } },
125126 ]
126127 }
127128
@@ -133,6 +134,10 @@ Rectangle {
133134 if (data.hasOwnProperty("width")) {
134135 tryCompare(data.object, "width", data.width);
135136 }
137+
138+ if (data.hasOwnProperty("height")) {
139+ tryCompareFunction(function() { return data.object.height === data.height() }, true);
140+ }
136141 }
137142 }
138143}