@@ -0,0 +1,96 @@
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 0.1
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" }
38+ signalName: "triggered"
43+ widgetId: "previewPayments"
44+ widgetData: jsonPurchase
55+ name: "PreviewPaymentsTest"
63+ function test_purchase_completed() {
64+ var button = findChild(root, "previewPayments");
65+ verify(button != null);
66+ spy.target = previewPayments;
68+ // Exercise the purchaseCompleted signal here.
69+ previewPayments.widgetData = jsonPurchase;
70+ mouseClick(button, button.width / 2, button.height / 2);
72+ compare(spy.count, 1);
73+ var args = spy.signalArguments[0];
74+ compare(args[0], "previewPayments");
75+ compare(args[1], "purchaseCompleted");
76+ compare(args[2], jsonPurchase["source"]);
79+ function test_purchase_error() {
80+ var button = findChild(root, "previewPayments");
81+ verify(button != null);
82+ spy.target = previewPayments;
84+ // The mock Payments triggers an error when com.example.invalid is
85+ // passed to it as store_item_id. Exercise it here
86+ previewPayments.widgetData = jsonPurchaseError;
87+ mouseClick(button, button.width / 2, button.height / 2);
89+ compare(spy.count, 1);
90+ var args = spy.signalArguments[0];
91+ compare(args[0], "previewPayments");
92+ compare(args[1], "purchaseError");
93+ compare(args[2], jsonPurchaseError["source"]);