@@ -0,0 +1,171 @@
1+/*
2+ * Copyright 2013 Canonical Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ */
16+
17+import QtQuick 2.0
18+import QtTest 1.0
19+import Ubuntu.Components 0.1
20+import "../../../../Dash/Apps"
21+import Unity.Test 0.1 as UT
22+
23+Item {
24+ id: root
25+ width: units.gu(60)
26+ height: units.gu(80)
27+
28+ property var calls
29+
30+ SignalSpy {
31+ id: sendPreviewSpy
32+ target: appPreview
33+ signalName: "sendUserReview"
34+ }
35+
36+ function get_actions() {
37+ var a1 = new Object();
38+ a1.id = 123;
39+ a1.displayName = "action1";
40+ var a2 = new Object();
41+ a2.id = 456;
42+ a2.displayName = "action2";
43+ var a3 = new Object();
44+ a3.id = 789;
45+ a3.displayName = "action3";
46+
47+ return [a1, a2, a3];
48+ }
49+
50+ function get_infomap() {
51+ var map = {
52+ "more-screenshots": screenshots,
53+ "rating": rating,
54+ "rated": rated,
55+ "reviews": reviews,
56+ "comments": comments
57+ }
58+
59+ return map;
60+ }
61+
62+ property string commentary: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus a mi vitae augue rhoncus lobortis ut rutrum metus. Curabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh.";
63+ QtObject { id: screenshots; property var value: ["fake_image1.png", "fake_image2.png", "fake_image3.png"] }
64+ QtObject { id: rating; property int value: 8 }
65+ QtObject { id: rated; property int value: 120 }
66+ QtObject { id: reviews; property int value: 8 }
67+ QtObject { id: progress; property string value: "source" }
68+ QtObject { id: comments; property var value: [
69+ ["Unity User", 4, "08/20/2013", root.commentary],
70+ ["Unity User", 8, "01/15/2013", root.commentary],
71+ ["Unity User", 10, "10/02/2013", root.commentary],
72+ ]
73+ }
74+
75+ QtObject {
76+ id: data
77+ property string title: "Unity App"
78+ property string appIcon: "fake_image.png"
79+ property string description: "This is an Application description"
80+ property var execute: root.fake_call
81+ property var infoMap: get_infomap()
82+ property var actions: get_actions()
83+ }
84+
85+ function fake_call(id, data){
86+ root.calls[root.calls.length] = id;
87+ }
88+
89+ // The component under test
90+ AppPreview {
91+ id: appPreview
92+ anchors.fill: parent
93+
94+ previewData: data
95+ }
96+
97+ UT.UnityTestCase {
98+ name: "AppPreview"
99+ when: windowShown
100+
101+ function test_actions() {
102+ root.calls = new Array();
103+ var buttons = findChild(appPreview, "gridButtons");
104+ compare(buttons.count, 3, "Not the proper amount of actions detected.");
105+
106+ for(var i = 0; i < buttons.count; i++) {
107+ buttons.currentIndex = i;
108+ buttons.currentItem.clicked();
109+ }
110+
111+ var actions = get_actions();
112+ for(var i = 0; i < actions.length; i++) {
113+ compare(root.calls[i], actions[i].id, "Id of action not found.");
114+ }
115+ }
116+
117+ function test_rated() {
118+ var rated = findChild(appPreview, "ratedLabel");
119+ compare(rated.text, "(120)", "Rates not equal");
120+ }
121+
122+ function test_reviews() {
123+ var rated = findChild(appPreview, "reviewsLabel");
124+ compare(rated.text, i18n.tr("%1 review", "%1 reviews", 8).arg(8), "Reviews don't match");
125+ }
126+
127+ function test_state_nothing() {
128+ var appReviews = findChild(appPreview, "appReviews");
129+ appReviews.state = "";
130+ var reviewField = findChild(appPreview, "reviewField");
131+ var sendButton = findChild(appPreview, "sendButton");
132+ compare(reviewField.width, appReviews.width, "ReviewField width don't match");
133+ compare(sendButton.opacity, 0, "SendButton opacity should be 0");
134+ }
135+
136+ function test_send_review() {
137+ sendPreviewSpy.clear();
138+ var appReviews = findChild(appPreview, "appReviews");
139+ appReviews.sendReview("review");
140+ compare(sendPreviewSpy.count, 1, "SendReview signal not emitted");
141+ }
142+
143+ function test_review_focus() {
144+ sendPreviewSpy.clear();
145+ var appReviews = findChild(appPreview, "appReviews");
146+ var sendButton = findChild(appReviews, "sendButton");
147+ var reviewField = findChild(appReviews, "reviewField");
148+
149+ compare(reviewField.focus, false, "ReviewField shouldn't have focus");
150+ compare(appReviews.state, "", "State should be empty");
151+ mouseClick(reviewField, 1, 1);
152+ compare(reviewField.focus, true, "Review Field should have focus");
153+ compare(appReviews.state, "editing", "State should be 'editing'");
154+ }
155+
156+ function test_comments() {
157+ var commentsArea = findChild(appPreview, "commentsArea");
158+ compare(commentsArea.count, 3);
159+ for(var i = 0; i < 3; i++) {
160+ var username = commentsArea.itemAt(i).children[0].children[0].text
161+ var rate = commentsArea.itemAt(i).children[0].children[1].children[0].rating
162+ var date = commentsArea.itemAt(i).children[0].children[1].children[1].text
163+ var comment = commentsArea.itemAt(i).children[1].text
164+ compare(username, comments.value[i][0], "Username don't match");
165+ compare(rate, comments.value[i][1], "Rating don't match");
166+ compare(date, comments.value[i][2], "Date don't match");
167+ compare(comment, comments.value[i][3], "Comment don't match");
168+ }
169+ }
170+ }
171+}