on xenial help sign in
Added widget and tests
commitbcf7498fa315079d0c166d5d8b6052961305952c authorAndrea Cimitan <andrea.cimitan@canonical.com> dateFri 21 Feb 2014, 11:04 (13 years ago) parente070112
2 files changed+80−9
qml/Dash/Previews/PreviewRatingDisplay.qml+9−4 tests/qmltests/Dash/Previews/tst_PreviewRatingDisplay.qml+71−5
qml/Dash/Previews/PreviewRatingDisplay.qml+9−4
@@ -50,7 +50,7 @@ PreviewWidget {
5050 model: root.widgetData["reviews"]
5151
5252 delegate: Column {
53− id: reviewColumn
53+ id: reviewItem
5454 objectName: "reviewItem" + index
5555 anchors { left: parent.left; right: parent.right;}
5656 spacing: units.gu(1)
@@ -59,7 +59,8 @@ PreviewWidget {
5959 id: rating
6060 objectName: "rating"
6161 size: 5
62− value: modelData["rating"]
62+ value: modelData["rating"] || -1
63+ visible: value >= 0
6364
6465 property var urlIconEmpty: widgetData["rating-icon-empty"]
6566 property var urlIconFull: widgetData["rating-icon-full"]
@@ -72,7 +73,8 @@ PreviewWidget {
7273 anchors { left: parent.left; right: parent.right }
7374 color: Theme.palette.selected.backgroundText
7475 opacity: .8
75− text: modelData["author"]
76+ text: modelData["author"] || ""
77+ visible: text !== ""
7678 wrapMode: Text.Wrap
7779 }
7880
@@ -82,13 +84,16 @@ PreviewWidget {
8284 anchors { left: parent.left; right: parent.right }
8385 color: Theme.palette.selected.backgroundText
8486 opacity: .8
85− text: modelData["review"]
87+ text: modelData["review"] || ""
88+ visible: text !== ""
8689 wrapMode: Text.Wrap
8790 }
8891
8992 Item {
93+ id: spacing
9094 anchors { left: parent.left; right: parent.right }
9195 height: units.gu(2)
96+ visible: rating.visible || authorLabel.visible || reviewLabel.visible
9297 }
9398 }
9499 }
tests/qmltests/Dash/Previews/tst_PreviewRatingDisplay.qml+71−5
@@ -26,21 +26,87 @@ Rectangle {
2626 height: units.gu(80)
2727 color: Theme.palette.selected.background
2828
29− property var reviewsModel: {
30− "reviews": [ { author: "Some dude", rating: "4.5", review: "Very cool app" },
31− { author: "Another dude", rating: "3", review: "Average app. Lorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh." },
32− { author: "Yet Another dude", rating: "5", review: "Very cool app" }, ]
29+ property var reviewsModel0: {
30+ "reviews": [ ]
31+ }
32+
33+ property var reviewsModel1: {
34+ "reviews": [ { author: "Some dude", rating: 4.5, review: "Very cool app" },
35+ { author: "Yet Another dude", rating: 5, review: "Very cool app" }, ]
36+ }
37+
38+ property var reviewsModel2: {
39+ "reviews": [ { author: "Some dude", rating: 4.5, review: "Very cool app" },
40+ { author: "Another dude", rating: 3, review: "Average app. Lorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh." },
41+ { author: "Yet Another dude", rating: 5, review: "Very cool app" }, ]
42+ }
43+
44+ property var reviewsModelMixed: {
45+ "reviews": [ { author: "Some dude", review: "Very cool app" },
46+ { author: "" },
47+ { rating: 3, review: "Average app. Lorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh." },
48+ { author: "Yet Another dude", rating: 5 }, ]
3349 }
3450
3551 PreviewRatingDisplay {
3652 id: previewRatingDisplay
3753 anchors.left: parent.left
3854 anchors.right: parent.right
39− widgetData: reviewsModel
55+ widgetData: reviewsModelMixed
4056 }
4157
4258 UT.UnityTestCase {
4359 name: "PreviewRatingDisplayTest"
4460 when: windowShown
61+
62+ function test_reviews_data() {
63+ return [
64+ {tag: "0 reviews", reviewsModel: reviewsModel0},
65+ {tag: "1 review", reviewsModel: reviewsModel1},
66+ {tag: "3 reviews", reviewsModel: reviewsModel2},
67+ {tag: "3 mixed reviews", reviewsModel: reviewsModelMixed}
68+ ];
69+ }
70+
71+ function test_reviews(data) {
72+ previewRatingDisplay.widgetData = data.reviewsModel;
73+
74+ var reviewsRepeater = findChild(previewRatingDisplay, "reviewsRepeater");
75+ compare(reviewsRepeater.count, data.reviewsModel["reviews"].length);
76+
77+ for (var i = 0; i < data.reviewsModel["reviews"].length; ++i) {
78+ var reviewItem = findChild(previewRatingDisplay, "reviewItem" + i);
79+
80+ var rating = findChild(reviewItem, "rating");
81+ if (data.reviewsModel["reviews"][i]["rating"] >= 0) {
82+ compare(rating.visible, true);
83+ compare(rating.value, data.reviewsModel["reviews"][i]["rating"]);
84+ } else {
85+ compare(rating.visible, false);
86+ }
87+
88+ var authorLabel = findChild(reviewItem, "authorLabel");
89+ if (data.reviewsModel["reviews"][i]["author"] &&
90+ data.reviewsModel["reviews"][i]["author"] !== "") {
91+ compare(authorLabel.visible, true);
92+ compare(authorLabel.text, data.reviewsModel["reviews"][i]["author"]);
93+ } else {
94+ compare(authorLabel.visible, false);
95+ }
96+
97+ var reviewLabel = findChild(reviewItem, "reviewLabel");
98+ if (data.reviewsModel["reviews"][i]["review"] &&
99+ data.reviewsModel["reviews"][i]["review"] !== "") {
100+ compare(reviewLabel.visible, true);
101+ compare(reviewLabel.text, data.reviewsModel["reviews"][i]["review"]);
102+ } else {
103+ compare(reviewLabel.visible, false);
104+ }
105+
106+ if (!rating.visible && !authorLabel.visible && !reviewLabel.visible) {
107+ verify(reviewItem.height === 0);
108+ }
109+ }
110+ }
45111 }
46112}