on xenial help sign in
Add tests.
commitc1362017b8a29d6341ea20ff80097c264fb7dbd7 authorMichał Karnicki <michal.karnicki@canonical.com> dateTue 4 Feb 2014, 16:01 (13 years ago) parent1c38901
2 files changed+49−6
qml/Dash/CardTool.qml+8−6 tests/qmltests/Dash/tst_CardTool.qml+41
qml/Dash/CardTool.qml+8−6
@@ -113,14 +113,16 @@ Item {
113113 height: cardTool.cardHeight || implicitHeight
114114
115115 property var titleHorizontalAlignment: {
116− // TODO karni: attribute-1 instead of price?
117116 var subtitle = components["subtitle"];
118117 var price = components["price"];
119− var isOnlyItem = (subtitle === undefined || subtitle === "") && (price === undefined || price === "");
120− var hasImage = (components["art"]["image"] && components["art"]["image"] !== "") ||
121− (components["mascot"] && components["mascot"] !== "");
122− if (!isOnlyItem) return Text.AlignLeft;
123− return hasImage ? Text.AlignLeft : Text.AlignHCenter;
118+
119+ var hasSubtitle = subtitle && (typeof subtitle === "string" || subtitle["field"])
120+ var hasPrice = price && (typeof price === "string" || subtitle["field"]);
121+
122+ var isOnlyTextComponent = !hasSubtitle && !hasPrice;
123+ if (!isOnlyTextComponent) return Text.AlignLeft;
124+
125+ return (template["card-layout"] === "horizontal") ? Text.AlignHCenter : Text.AlignLeft;
124126 }
125127
126128 property var fields: ["art", "mascot", "title", "subtitle", "summary"]
tests/qmltests/Dash/tst_CardTool.qml+41
@@ -72,6 +72,22 @@ Rectangle {
7272 "name": "Art, header - portrait",
7373 "layout": { "components": Helpers.update(JSON.parse(Helpers.fullMapping), { "art": {"aspect-ratio": 0.5, "summary": undefined }}) }
7474 },
75+ {
76+ "name": "Title - vertical",
77+ "layout": { "template": { "card-layout": "vertical" }, "components": { "title": "title" } }
78+ },
79+ {
80+ "name": "Title - horizontal",
81+ "layout": { "template": { "card-layout": "horizontal" }, "components": { "title": "title" } }
82+ },
83+ {
84+ "name": "Title, subtitle - vertical",
85+ "layout": { "template": { "card-layout": "vertical" }, "components": { "title": "title", "subtitle": "subtitle" } }
86+ },
87+ {
88+ "name": "Title, price - horizontal",
89+ "layout": { "template": { "card-layout": "horizontal" }, "components": { "title": "title", "price": "price" } }
90+ },
7591 ]
7692
7793 CardTool {
@@ -121,6 +137,7 @@ Rectangle {
121137 height: cardTool.cardHeight || implicitHeight
122138
123139 clip: true
140+ titleHorizontalAlignment: cardTool.titleHorizontalAlignment
124141
125142 Rectangle {
126143 anchors.fill: parent
@@ -296,5 +313,29 @@ Rectangle {
296313 } else tryCompare(cardTool, "cardHeight", data.height);
297314 }
298315 }
316+
317+ function test_card_header_component_alignment_data() {
318+ return [
319+ { tag: "Title - vertical", component: "titleLabel", property: "titleHorizontalAlignment",
320+ value: Text.AlignLeft, index: 11, layout_index: 0 },
321+ { tag: "Title - horizontal", component: "titleLabel", property: "titleHorizontalAlignment",
322+ value: Text.AlignHCenter, index: 12, layout_index: 0},
323+ { tag: "Title, subtitle - vertical", component: "titleLabel", property: "titleHorizontalAlignment",
324+ value: Text.AlignLeft, index: 13, layout_index: 0},
325+ { tag: "Title, price - horizontal", component: "titleLabel", property: "titleHorizontalAlignment",
326+ value: Text.AlignLeft, index: 14, layout_index: 0},
327+ ]
328+ }
329+
330+ function test_card_header_component_alignment(data) {
331+ selector.selectedIndex = data.index;
332+ if (data.hasOwnProperty("layout_index")) {
333+ layoutSelector.selectedIndex = data.layout_index;
334+ }
335+
336+ if (data.hasOwnProperty("property")) {
337+ tryCompare(cardTool, data.property, data.value);
338+ }
339+ }
299340 }
300341}