@@ -1,203 +0,0 @@
1−/*
2− * Copyright 2014 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.4
18−import QtTest 1.0
19−import "../../../../qml/Dash/Previews"
20−import Unity.Test 0.1 as UT
21−import Ubuntu.Components 1.3
22−
23−Rectangle {
24− id: root
25− width: units.gu(60)
26− height: units.gu(80)
27−
28− property var jsonPurchase: {
29− "source": { "price" : 0.99, "currency": "USD", "store_item_id": "com.example.package" }
30− }
31−
32− property var jsonPurchaseError: {
33− "source": { "price" : 0.99, "currency": "USD", "store_item_id": "com.example.invalid" }
34− }
35−
36− property var jsonPurchaseCancel: {
37− "source": { "price" : 0.99, "currency": "USD", "store_item_id": "com.example.cancel" }
38− }
39−
40− SignalSpy {
41− id: spy
42− target: previewPayments
43− signalName: "triggered"
44− }
45−
46− PreviewPayments {
47− id: previewPayments
48− widgetId: "previewPayments"
49− width: units.gu(30)
50− }
51−
52− UT.UnityTestCase {
53− name: "PreviewPaymentsTest"
54− when: windowShown
55− property var paymentClient
56−
57− function init()
58− {
59− paymentClient = findInvisibleChild(previewPayments, "paymentClient");
60− verify(paymentClient, "Could not find the payment client object.");
61− }
62−
63− function cleanup()
64− {
65− paymentClient = null;
66− previewPayments.widgetData = null;
67− spy.clear();
68− var button = findChild(previewPayments, "paymentButton");
69− button.opacity = 1;
70− }
71−
72− function test_purchase_text_display() {
73− previewPayments.widgetData = jsonPurchase;
74−
75− var button = findChild(previewPayments, "paymentButton");
76− verify(button, "Button not found.");
77− compare(button.text, "0.99USD");
78− }
79−
80− function test_purchase_completed() {
81− // Exercise the purchaseCompleted signal here.
82− previewPayments.widgetData = jsonPurchase;
83−
84− var button = findChild(previewPayments, "paymentButton");
85− verify(button, "Button not found.");
86−
87− mouseClick(button);
88−
89− paymentClient.process();
90− spy.wait();
91−
92− var args = spy.signalArguments[0];
93− compare(args[0], "previewPayments");
94− compare(args[1], "purchaseCompleted");
95− compare(args[2], jsonPurchase["source"]);
96− }
97−
98− function test_progress_show() {
99− // Make sure the progress bar is shown.
100− previewPayments.widgetData = jsonPurchase;
101−
102− var button = findChild(previewPayments, "paymentButton");
103− var progress = findChild(previewPayments, "loadingBar");
104−
105− tryCompare(progress, "visible", false);
106− tryCompare(progress, "opacity", 0);
107− tryCompare(button, "visible", true);
108− tryCompare(button, "opacity", 1);
109−
110− mouseClick(button);
111−
112− paymentClient.process();
113− spy.wait();
114−
115− tryCompare(progress, "visible", true);
116− tryCompare(progress, "opacity", 1);
117− tryCompare(button, "visible", false);
118− tryCompare(button, "opacity", 0);
119− }
120−
121− function test_progress_show_cancel() {
122− // Make sure the progress bar is shown.
123− previewPayments.widgetData = jsonPurchaseError;
124−
125− var button = findChild(previewPayments, "paymentButton");
126− var progress = findChild(previewPayments, "loadingBar");
127−
128− tryCompare(progress, "visible", false);
129− tryCompare(progress, "opacity", 0);
130− tryCompare(button, "visible", true);
131− tryCompare(button, "opacity", 1);
132−
133− mouseClick(button);
134−
135− tryCompare(progress, "visible", true);
136− tryCompare(progress, "opacity", 1);
137− tryCompare(button, "visible", false);
138− tryCompare(button, "opacity", 0);
139−
140− paymentClient.process();
141− spy.wait();
142−
143− tryCompare(progress, "visible", false);
144− tryCompare(progress, "opacity", 0);
145− tryCompare(button, "visible", true);
146− tryCompare(button, "opacity", 1);
147− }
148−
149− function test_purchase_error() {
150− // The mock Payments triggers an error when com.example.invalid is
151− // passed to it as store_item_id. Exercise it here
152− previewPayments.widgetData = jsonPurchaseError;
153−
154− var button = findChild(previewPayments, "paymentButton");
155− verify(button, "Button not found.");
156−
157− mouseClick(button);
158−
159− paymentClient.process();
160− spy.wait();
161−
162− var args = spy.signalArguments[0];
163− compare(args[0], "previewPayments");
164− compare(args[1], "purchaseError");
165− compare(args[2], jsonPurchaseError["source"]);
166− }
167−
168− function test_purchase_cancelled() {
169− // The mock Payments triggers cancellation when com.example.cancel
170− // is passed to it as store_item_id. Exercise it here
171− previewPayments.widgetData = jsonPurchaseCancel;
172−
173− var button = findChild(previewPayments, "paymentButton");
174− var progress = findChild(previewPayments, "loadingBar");
175− verify(button, "Button not found.");
176− verify(progress, "Progress not found.");
177−
178− mouseClick(button);
179−
180− tryCompare(progress, "visible", true);
181− tryCompare(progress, "opacity", 1);
182− tryCompare(button, "visible", false);
183− tryCompare(button, "opacity", 0);
184−
185− paymentClient.process();
186−
187− // Signal is not used at the moment, to avoid preview refresh.
188− /*
189− *spy.wait();
190− *
191− * var args = spy.signalArguments[0];
192− * compare(args[0], "previewPayments");
193− * compare(args[1], "purchaseCancelled");
194− * compare(args[2], jsonPurchaseCancel["source"]);
195− */
196−
197− tryCompare(progress, "visible", false);
198− tryCompare(progress, "opacity", 0);
199− tryCompare(button, "visible", true);
200− tryCompare(button, "opacity", 1);
201− }
202− }
203−}