@@ -0,0 +1,152 @@
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+ 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.";
37+ QtObject { id: screenshots; property var value: ["fake_image1.png", "fake_image2.png", "fake_image3.png"] }
38+ QtObject { id: rating; property int value: 8 }
39+ QtObject { id: rated; property int value: 120 }
40+ QtObject { id: reviews; property int value: 8 }
41+ QtObject { id: progress; property string value: "source" }
42+ QtObject { id: comments; property var value: [
43+ ["Unity User", 4, "08/20/2013", root.commentary],
44+ ["Unity User", 8, "01/15/2013", root.commentary],
45+ ["Unity User", 10, "10/02/2013", root.commentary],
46+ ]
47+ }
48+
49+ QtObject {
50+ id: data
51+ property string title: "Unity App"
52+ property string appIcon: "fake_image.png"
53+ property string description: "This is an Application description"
54+ property var execute: root.fake_call
55+ property var infoMap: {
56+ "more-screenshots": screenshots,
57+ "rating": rating,
58+ "rated": rated,
59+ "reviews": reviews,
60+ "comments": comments
61+ }
62+ property var actions: [
63+ { "id": 123, "displayName": "action1" },
64+ { "id": 456, "displayName": "action2" },
65+ { "id": 789, "displayName": "action3" },
66+ ]
67+ }
68+
69+ function fake_call(id, data){
70+ root.calls[root.calls.length] = id;
71+ }
72+
73+ // The component under test
74+ AppPreview {
75+ id: appPreview
76+ anchors.fill: parent
77+
78+ previewData: data
79+ }
80+
81+ UT.UnityTestCase {
82+ name: "AppPreview"
83+ when: windowShown
84+
85+ function cleanup() {
86+ root.calls = new Array();
87+ sendPreviewSpy.clear();
88+ var reviewField = findChild(appPreview, "reviewField");
89+ reviewField.focus = false;
90+ reviewField.text = "";
91+ }
92+
93+ function test_actions() {
94+ var buttons = findChild(appPreview, "gridButtons");
95+ compare(buttons.count, 3, "Not the proper amount of actions detected.");
96+
97+ for(var i = 0; i < buttons.count; i++) {
98+ buttons.currentIndex = i;
99+ buttons.currentItem.clicked();
100+ }
101+
102+ var actions = data.actions;
103+ for(var i = 0; i < actions.length; i++) {
104+ compare(root.calls[i], actions[i].id, "Id of action not found.");
105+ }
106+ }
107+
108+ function test_rated() {
109+ var rated = findChild(appPreview, "ratedLabel");
110+ compare(rated.text, "(120)", "Rates not equal");
111+ }
112+
113+ function test_reviews() {
114+ var rated = findChild(appPreview, "reviewsLabel");
115+ compare(rated.text, "8 reviews", "Reviews don't match");
116+ }
117+
118+ function test_send_review() {
119+ var appReviews = findChild(appPreview, "appReviews");
120+ appReviews.sendReview("review");
121+ sendPreviewSpy.wait();
122+ }
123+
124+ function test_review_focus() {
125+ var appReviews = findChild(appPreview, "appReviews");
126+ var sendButton = findChild(appReviews, "sendButton");
127+ var reviewField = findChild(appReviews, "reviewField");
128+
129+ compare(reviewField.focus, false, "ReviewField shouldn't have focus");
130+ compare(appReviews.state, "", "State should be empty");
131+
132+ mouseClick(reviewField, reviewField.width/2, reviewField.height/2);
133+ compare(reviewField.focus, true, "Review Field should have focus");
134+ compare(appReviews.state, "editing", "State should be 'editing'");
135+ }
136+
137+ function test_comments() {
138+ var commentsArea = findChild(appPreview, "commentsArea");
139+ compare(commentsArea.count, 3);
140+ for(var i = 0; i < 3; i++) {
141+ var username = commentsArea.itemAt(i).children[0].children[0].text
142+ var rate = commentsArea.itemAt(i).children[0].children[1].children[0].rating
143+ var date = commentsArea.itemAt(i).children[0].children[1].children[1].text
144+ var comment = commentsArea.itemAt(i).children[1].text
145+ compare(username, comments.value[i][0], "Username don't match");
146+ compare(rate, comments.value[i][1], "Rating don't match");
147+ compare(date, comments.value[i][2], "Date don't match");
148+ compare(comment, comments.value[i][3], "Comment don't match");
149+ }
150+ }
151+ }
152+}