on xenial help sign in
Added widget and tests
bcf7498Andrea Cimitan
qml/Dash/Previews/PreviewRatingDisplay.qml+9−4
@@ -50,7 +50,7 @@ PreviewWidget {
50 model: root.widgetData["reviews"]
50 model: root.widgetData["reviews"]
51
51
52 delegate: Column {
52 delegate: Column {
53− id: reviewColumn
53+ id: reviewItem
54 objectName: "reviewItem" + index
54 objectName: "reviewItem" + index
55 anchors { left: parent.left; right: parent.right;}
55 anchors { left: parent.left; right: parent.right;}
56 spacing: units.gu(1)
56 spacing: units.gu(1)
@@ -59,7 +59,8 @@ PreviewWidget {
59 id: rating
59 id: rating
60 objectName: "rating"
60 objectName: "rating"
61 size: 5
61 size: 5
62− value: modelData["rating"]
62+ value: modelData["rating"] || -1
63+ visible: value >= 0
63
64
64 property var urlIconEmpty: widgetData["rating-icon-empty"]
65 property var urlIconEmpty: widgetData["rating-icon-empty"]
65 property var urlIconFull: widgetData["rating-icon-full"]
66 property var urlIconFull: widgetData["rating-icon-full"]
@@ -72,7 +73,8 @@ PreviewWidget {
72 anchors { left: parent.left; right: parent.right }
73 anchors { left: parent.left; right: parent.right }
73 color: Theme.palette.selected.backgroundText
74 color: Theme.palette.selected.backgroundText
74 opacity: .8
75 opacity: .8
75− text: modelData["author"]
76+ text: modelData["author"] || ""
77+ visible: text !== ""
76 wrapMode: Text.Wrap
78 wrapMode: Text.Wrap
77 }
79 }
78
80
@@ -82,13 +84,16 @@ PreviewWidget {
82 anchors { left: parent.left; right: parent.right }
84 anchors { left: parent.left; right: parent.right }
83 color: Theme.palette.selected.backgroundText
85 color: Theme.palette.selected.backgroundText
84 opacity: .8
86 opacity: .8
85− text: modelData["review"]
87+ text: modelData["review"] || ""
88+ visible: text !== ""
86 wrapMode: Text.Wrap
89 wrapMode: Text.Wrap
87 }
90 }
88
91
89 Item {
92 Item {
93+ id: spacing
90 anchors { left: parent.left; right: parent.right }
94 anchors { left: parent.left; right: parent.right }
91 height: units.gu(2)
95 height: units.gu(2)
96+ visible: rating.visible || authorLabel.visible || reviewLabel.visible
92 }
97 }
93 }
98 }
94 }
99 }
tests/qmltests/Dash/Previews/tst_PreviewRatingDisplay.qml+71−5
@@ -26,21 +26,87 @@ Rectangle {
26 height: units.gu(80)
26 height: units.gu(80)
27 color: Theme.palette.selected.background
27 color: Theme.palette.selected.background
28
28
29− property var reviewsModel: {
29+ property var reviewsModel0: {
30+ "reviews": [ ]
31+ }
32+
33+ property var reviewsModel1: {
30− "reviews": [ { author: "Some dude", rating: "4.5", review: "Very cool app" },
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" },
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." },
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." },
32− { author: "Yet Another dude", rating: "5", review: "Very cool app" }, ]
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 }, ]
33 }
49 }
34
50
35 PreviewRatingDisplay {
51 PreviewRatingDisplay {
36 id: previewRatingDisplay
52 id: previewRatingDisplay
37 anchors.left: parent.left
53 anchors.left: parent.left
38 anchors.right: parent.right
54 anchors.right: parent.right
39− widgetData: reviewsModel
55+ widgetData: reviewsModelMixed
40 }
56 }
41
57
42 UT.UnityTestCase {
58 UT.UnityTestCase {
43 name: "PreviewRatingDisplayTest"
59 name: "PreviewRatingDisplayTest"
44 when: windowShown
60 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+ }
45 }
111 }
46}
112}