@@ -1,276 +0,0 @@
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 "../../../../qml/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− // Fake shell
29− QtObject { id: shell; property int height: appPreview.height }
30−
31− property var calls: []
32−
33− SignalSpy {
34− id: sendPreviewSpy
35− target: appPreview
36− signalName: "sendUserReview"
37− }
38−
39− 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.";
40− QtObject { id: screenshots; property var value: ["fake_image1.png", "fake_image2.png", "fake_image3.png"] }
41− QtObject { id: rating; property real value: 0.8 }
42− QtObject { id: rated; property int value: 120 }
43− QtObject { id: reviews; property int value: 8 }
44− QtObject { id: progress; property string value: "source" }
45− QtObject { id: publisher; property string value: "Ubuntu Developer" }
46− QtObject { id: comments; property var value: [
47− ["Unity User", 4, "08/20/2013", root.commentary],
48− ["Unity User", 8, "01/15/2013", root.commentary],
49− ["Unity User", 10, "10/02/2013", root.commentary],
50− ]
51− }
52− QtObject { id: showProgress; property bool value: true }
53− QtObject { id: progressSource; property string value: "service" }
54−
55− QtObject {
56− id: data
57− property string title: "Unity App"
58− property string appIcon: "fake_image.png"
59− property string description: "This is an Application description"
60− property real rating: rating.value
61− property int numRatings: reviews.value
62− property var execute: root.fake_call
63− property var infoMap: {
64− "more-screenshots": screenshots,
65− "rated": rated,
66− "comments": comments,
67− "publisher": publisher
68− }
69− property var actions: [
70− { "id": 123, "displayName": "action1" },
71− { "id": 456, "displayName": "action2" },
72− { "id": 789, "displayName": "action3" },
73− ]
74− }
75−
76− QtObject {
77− id: dataProgress
78− property string title: "Unity App"
79− property string appIcon: "fake_image.png"
80− property string description: "This is an Application description"
81− property real rating: rating.value
82− property int numRatings: reviews.value
83− property var execute: root.fake_call
84− property var infoMap: {
85− "show_progressbar": showProgress,
86− "more-screenshots": screenshots,
87− "rated": rated,
88− "comments": comments,
89− "publisher": publisher,
90− "progressbar_source": progressSource
91− }
92− property var actions: [
93− { "id": 123, "displayName": "action1" },
94− { "id": 456, "displayName": "action2" },
95− { "id": 789, "displayName": "action3" },
96− ]
97− }
98−
99− function fake_call(id, data){
100− root.calls[root.calls.length] = [id, data];
101− }
102−
103− // The component under test
104− AppPreview {
105− id: appPreview
106− anchors.fill: parent
107−
108− previewData: data
109− }
110−
111− UT.UnityTestCase {
112− name: "AppPreview"
113− when: windowShown
114−
115− function init() {
116− waitForRendering(appPreview)
117− }
118−
119− function cleanup() {
120− root.calls = new Array();
121− sendPreviewSpy.clear();
122− // TODO: This doesn't work right now as Reviews are disabled
123− //var reviewField = findChild(appPreview, "reviewField");
124− //reviewField.focus = false;
125− //reviewField.text = "";
126− //data.rating = rating.value;
127− dataProgress.infoMap["progressbar_source"].value = "service";
128− //var appReviews = findChild(appPreview, "appReviews");
129− //appReviews.visible = false;
130− //appPreview.keyboardSize = 0;
131− }
132−
133− function test_actions() {
134− var buttons = findChild(appPreview, "buttonList");
135− compare(buttons.count, 3, "Not the proper amount of actions detected.");
136−
137− for(var i = 0; i < buttons.count; i++) {
138− var button = findChild(appPreview, "button" + i);
139− mouseClick(button, 1, 1);
140− appPreview.showProcessingAction = false;
141− }
142−
143− var actions = data.actions;
144− for(var j = 0; j < actions.length; j++) {
145− compare(root.calls[j][0], actions[j].id, "Id of action not found.");
146− }
147− }
148−
149− function test_check_app_info() {
150− var appInfo = findChild(appPreview, "previewHeader");
151− var titleLabel = findChild(appInfo, "titleLabel");
152− var subtitleLabel = findChild(appInfo, "subtitleLabel");
153− compare(titleLabel.text, data.title, "App Title doesn't match.");
154− compare(subtitleLabel.text, publisher.value, "Publisher name doesn't match.");
155− }
156−
157− function test_rated() {
158− var rated = findChild(appPreview, "ratedLabel");
159− compare(rated.text, "(120)", "Rates not equal");
160− }
161−
162− function test_reviews() {
163− var rated = findChild(appPreview, "reviewsLabel");
164− compare(rated.text, "8 reviews", "Reviews don't match");
165− }
166−
167− // TODO: Disabled as reviewing and commenting is currently disabled
168− function test_send_review() {
169− skip();
170− var appReviews = findChild(appPreview, "appReviews");
171− appReviews.sendReview("review");
172− sendPreviewSpy.wait();
173− }
174−
175− function test_review_focus() {
176− skip();
177− var columnReviewRating = findChild(appPreview, "columnReviewRating");
178− columnReviewRating.visible = true;
179− var appReviews = findChild(appPreview, "appReviews");
180− appReviews.visible = true;
181− var sendButton = findChild(appReviews, "sendButton");
182− var reviewField = findChild(appReviews, "reviewField");
183−
184− compare(reviewField.focus, false, "ReviewField shouldn't have focus");
185− compare(appReviews.state, "", "State should be empty");
186−
187− mouseClick(reviewField, reviewField.width/2, reviewField.height/2);
188− compare(reviewField.focus, true, "Review Field should have focus");
189− compare(appReviews.state, "editing", "State should be 'editing'");
190− }
191−
192− function test_comments() {
193− skip();
194− var commentsArea = findChild(appPreview, "commentsArea");
195− compare(commentsArea.count, 3);
196− for(var i = 0; i < 3; i++) {
197− var username = commentsArea.itemAt(i).children[0].children[0].text
198− var rate = commentsArea.itemAt(i).children[0].children[1].children[0].rating
199− var date = commentsArea.itemAt(i).children[0].children[1].children[1].text
200− var comment = commentsArea.itemAt(i).children[1].text
201− compare(username, comments.value[i][0], "Username don't match");
202− compare(rate, comments.value[i][1], "Rating don't match");
203− compare(date, comments.value[i][2], "Date don't match");
204− compare(comment, comments.value[i][3], "Comment don't match");
205− }
206− }
207−
208− function test_negative_rating() {
209− skip();
210− data.rating = -1.0;
211− var rated = findChild(appPreview, "reviewsLabel");
212− verify(rated.visible == false);
213− var commentsArea = findChild(appPreview, "commentsArea");
214− verify(commentsArea.visible == false);
215− var appReviews = findChild(appPreview, "appReviews");
216− verify(appReviews.visible == false);
217− var buttons = findChild(appPreview, "gridButtons");
218− verify(buttons.visible == true);
219− }
220−
221− function test_automatic_scroll_on_keyboard_shown() {
222− skip();
223− waitForRendering(appPreview);
224− var appReviews = findChild(appPreview, "appReviews");
225− appReviews.visible = true;
226−
227− var leftFlickable = findChild(appPreview, "leftFlickable");
228− leftFlickable.contentY = leftFlickable.contentHeight;
229− var reviewField = findChild(appReviews, "reviewField");
230− appPreview.keyboardSize = 400;
231− appReviews.editing(reviewField);
232− var newFlickPos = leftFlickable.contentY;
233− var keyboardY = shell.height - appPreview.keyboardSize;
234− verify(newFlickPos < keyboardY);
235− }
236−
237− function test_progress_show() {
238− appPreview.previewData = dataProgress;
239− var progress = findChild(appPreview, "progressBar");
240− verify(progress.visible == true);
241− }
242−
243− function test_progress_download_finish() {
244− appPreview.previewData = dataProgress;
245− var progress = findChild(appPreview, "progressBar");
246− dataProgress.infoMap["progressbar_source"].value = "finish";
247−
248− var actions = dataProgress.actions;
249− compare(root.calls[0][0], actions[0].id, "Id of action not found.");
250− compare(root.calls[0][1], {}, "Data of action not found.");
251− }
252−
253− function test_progress_download_error() {
254− appPreview.previewData = dataProgress;
255− var progress = findChild(appPreview, "progressBar");
256− dataProgress.infoMap["progressbar_source"].value = "error";
257−
258− var actions = dataProgress.actions;
259− compare(root.calls[0][0], actions[1].id, "Id of action not found.");
260− compare(root.calls[0][1], {"error": "DOWNLOAD ERROR"}, "Data of action not found.");
261− }
262−
263− function test_placeholderScreenshot() {
264− var placeholderScreenshot = findChild(appPreview, "placeholderScreenshot");
265− compare(placeholderScreenshot.visible, false);
266−
267− data.infoMap["more-screenshots"] = [];
268− appPreview.previewData = data;
269− tryCompare(placeholderScreenshot, "visible", true);
270−
271− data.infoMap["more-screenshots"] = screenshots;
272− appPreview.previewData = data;
273− tryCompare(placeholderScreenshot, "visible", false);
274− }
275− }
276−}