on xenial help sign in
Add tests.
14a5420Michał Karnicki
qml/Dash/CardHeader.qml+2
@@ -48,6 +48,8 @@ Item {
48
48
49 image: Image {
49 image: Image {
50 id: mascotImage
50 id: mascotImage
51+ objectName: "mascotImage"
52+
51 sourceSize {
53 sourceSize {
52 width: mascotShape.maxSize
54 width: mascotShape.maxSize
53 height: mascotShape.maxSize
55 height: mascotShape.maxSize
tests/qmltests/Dash/tst_CardHeader.qml+30−1
@@ -44,6 +44,7 @@ Rectangle {
44 when: windowShown
44 when: windowShown
45
45
46 property Item mascot: findChild(cardHeader, "mascotShape")
46 property Item mascot: findChild(cardHeader, "mascotShape")
47+ property Item mascotImage: findChild(cardHeader, "mascotImage")
47 property Item titleLabel: findChild(cardHeader, "titleLabel")
48 property Item titleLabel: findChild(cardHeader, "titleLabel")
48 property Item subtitleLabel: findChild(cardHeader, "subtitleLabel")
49 property Item subtitleLabel: findChild(cardHeader, "subtitleLabel")
49 property Item prices: findChild(cardHeader, "prices")
50 property Item prices: findChild(cardHeader, "prices")
@@ -81,6 +82,25 @@ Rectangle {
81 tryCompare(testCase.mascot, "visible", data.visible);
82 tryCompare(testCase.mascot, "visible", data.visible);
82 }
83 }
83
84
85+ function test_mascot_image_source_data() {
86+ return [
87+ { tag: "Mascot source width", width: Math.max(mascot.width, mascot.height) },
88+ { tag: "Mascot source height", height: Math.max(mascot.width, mascot.height) },
89+ ]
90+ }
91+
92+ function test_mascot_image_source(data) {
93+ cardHeader.mascot = Qt.resolvedUrl("artwork/avatar.png")
94+
95+ if (data.hasOwnProperty("width")) {
96+ tryCompare(testCase.mascotImage.sourceSize, "width", data.width)
97+ }
98+
99+ if (data.hasOwnProperty("height")) {
100+ tryCompare(testCase.mascotImage.sourceSize, "height", data.height)
101+ }
102+ }
103+
84 function test_labels_data() {
104 function test_labels_data() {
85 return [
105 return [
86 { tag: "Empty", visible: false },
106 { tag: "Empty", visible: false },
@@ -123,6 +143,11 @@ Rectangle {
123 { tag: "Column width", object: column, width: cardHeader.width - testCase.outerRow.spacing * 2 },
143 { 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" },
144 { 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 } },
145 { tag: "Header height", object: cardHeader, height: function() { return subtitleLabel.y + subtitleLabel.height + outerRow.spacing * 2 } },
146+ { tag: "Mascot width", object: mascot,
147+ "mascot": Qt.resolvedUrl("artwork/avatar.png"), width: units.gu(6), },
148+ { tag: "Mascot height", object: mascot,
149+ // mascot (icon) aspect-ratio is 8:7.5
150+ "mascot": Qt.resolvedUrl("artwork/avatar.png"), height: units.gu(6)*7.5/8.0 },
126 ]
151 ]
127 }
152 }
128
153
@@ -136,7 +161,11 @@ Rectangle {
136 }
161 }
137
162
138 if (data.hasOwnProperty("height")) {
163 if (data.hasOwnProperty("height")) {
164+ if (typeof data.height === "function") {
139− tryCompareFunction(function() { return data.object.height === data.height() }, true);
165+ tryCompareFunction(function() { return data.object.height === data.height() }, true)
166+ } else {
167+ tryCompare(data.object, "height", data.height)
168+ }
140 }
169 }
141 }
170 }
142 }
171 }