@@ -1,203 +0,0 @@
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 "../../../../qml/Dash/Previews"
20−import Unity.Test 0.1 as UT
21−import Ubuntu.Components 1.3
28− property var jsonPurchase: {
29− "source": { "price" : 0.99, "currency": "USD", "store_item_id": "com.example.package" }
32− property var jsonPurchaseError: {
33− "source": { "price" : 0.99, "currency": "USD", "store_item_id": "com.example.invalid" }
36− property var jsonPurchaseCancel: {
37− "source": { "price" : 0.99, "currency": "USD", "store_item_id": "com.example.cancel" }
42− target: previewPayments
43− signalName: "triggered"
48− widgetId: "previewPayments"
53− name: "PreviewPaymentsTest"
55− property var paymentClient
59− paymentClient = findInvisibleChild(previewPayments, "paymentClient");
60− verify(paymentClient, "Could not find the payment client object.");
65− paymentClient = null;
66− previewPayments.widgetData = null;
68− var button = findChild(previewPayments, "paymentButton");
72− function test_purchase_text_display() {
73− previewPayments.widgetData = jsonPurchase;
75− var button = findChild(previewPayments, "paymentButton");
76− verify(button, "Button not found.");
77− compare(button.text, "0.99USD");
80− function test_purchase_completed() {
81− // Exercise the purchaseCompleted signal here.
82− previewPayments.widgetData = jsonPurchase;
84− var button = findChild(previewPayments, "paymentButton");
85− verify(button, "Button not found.");
89− paymentClient.process();
92− var args = spy.signalArguments[0];
93− compare(args[0], "previewPayments");
94− compare(args[1], "purchaseCompleted");
95− compare(args[2], jsonPurchase["source"]);
98− function test_progress_show() {
99− // Make sure the progress bar is shown.
100− previewPayments.widgetData = jsonPurchase;
102− var button = findChild(previewPayments, "paymentButton");
103− var progress = findChild(previewPayments, "loadingBar");
105− tryCompare(progress, "visible", false);
106− tryCompare(progress, "opacity", 0);
107− tryCompare(button, "visible", true);
108− tryCompare(button, "opacity", 1);
112− paymentClient.process();
115− tryCompare(progress, "visible", true);
116− tryCompare(progress, "opacity", 1);
117− tryCompare(button, "visible", false);
118− tryCompare(button, "opacity", 0);
121− function test_progress_show_cancel() {
122− // Make sure the progress bar is shown.
123− previewPayments.widgetData = jsonPurchaseError;
125− var button = findChild(previewPayments, "paymentButton");
126− var progress = findChild(previewPayments, "loadingBar");
128− tryCompare(progress, "visible", false);
129− tryCompare(progress, "opacity", 0);
130− tryCompare(button, "visible", true);
131− tryCompare(button, "opacity", 1);
135− tryCompare(progress, "visible", true);
136− tryCompare(progress, "opacity", 1);
137− tryCompare(button, "visible", false);
138− tryCompare(button, "opacity", 0);
140− paymentClient.process();
143− tryCompare(progress, "visible", false);
144− tryCompare(progress, "opacity", 0);
145− tryCompare(button, "visible", true);
146− tryCompare(button, "opacity", 1);
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;
154− var button = findChild(previewPayments, "paymentButton");
155− verify(button, "Button not found.");
159− paymentClient.process();
162− var args = spy.signalArguments[0];
163− compare(args[0], "previewPayments");
164− compare(args[1], "purchaseError");
165− compare(args[2], jsonPurchaseError["source"]);
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;
173− var button = findChild(previewPayments, "paymentButton");
174− var progress = findChild(previewPayments, "loadingBar");
175− verify(button, "Button not found.");
176− verify(progress, "Progress not found.");
180− tryCompare(progress, "visible", true);
181− tryCompare(progress, "opacity", 1);
182− tryCompare(button, "visible", false);
183− tryCompare(button, "opacity", 0);
185− paymentClient.process();
187− // Signal is not used at the moment, to avoid preview refresh.
191− * var args = spy.signalArguments[0];
192− * compare(args[0], "previewPayments");
193− * compare(args[1], "purchaseCancelled");
194− * compare(args[2], jsonPurchaseCancel["source"]);
197− tryCompare(progress, "visible", false);
198− tryCompare(progress, "opacity", 0);
199− tryCompare(button, "visible", true);
200− tryCompare(button, "opacity", 1);