@@ -0,0 +1,112 @@
2+ * Copyright 2014 Canonical Ltd.
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19+import Ubuntu.Components 0.1
20+import "../../../../qml/Dash/Previews"
21+import Unity.Test 0.1 as UT
27+ color: Theme.palette.selected.background
29+ property var reviewsModel0: {
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" }, ]
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" }, ]
44+ property var reviewsModelMixed: {
45+ "reviews": [ { author: "Some dude", review: "Very cool app" },
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 }, ]
51+ PreviewRatingDisplay {
52+ id: previewRatingDisplay
53+ anchors.left: parent.left
54+ anchors.right: parent.right
55+ widgetData: reviewsModelMixed
59+ name: "PreviewRatingDisplayTest"
62+ function test_reviews_data() {
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}
71+ function test_reviews(data) {
72+ previewRatingDisplay.widgetData = data.reviewsModel;
74+ var reviewsRepeater = findChild(previewRatingDisplay, "reviewsRepeater");
75+ compare(reviewsRepeater.count, data.reviewsModel["reviews"].length);
77+ for (var i = 0; i < data.reviewsModel["reviews"].length; ++i) {
78+ var reviewItem = findChild(previewRatingDisplay, "reviewItem" + i);
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"]);
85+ compare(rating.visible, false);
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"]);
94+ compare(authorLabel.visible, false);
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"]);
103+ compare(reviewLabel.visible, false);
106+ if (!rating.visible && !authorLabel.visible && !reviewLabel.visible) {
107+ verify(reviewItem.height === 0);