@@ -0,0 +1,96 @@
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.0
18+import QtTest 1.0
19+import "../../../../qml/Dash/Previews"
20+import Unity.Test 0.1 as UT
21+import Ubuntu.Components 0.1
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+ SignalSpy {
37+ id: spy
38+ signalName: "triggered"
39+ }
40+
41+ PreviewPayments {
42+ id: previewPayments
43+ widgetId: "previewPayments"
44+ widgetData: jsonPurchase
45+ width: units.gu(30)
46+
47+ Rectangle {
48+ anchors.fill: parent
49+ color: "red"
50+ opacity: 0.1
51+ }
52+ }
53+
54+ UT.UnityTestCase {
55+ name: "PreviewPaymentsTest"
56+ when: windowShown
57+
58+ function cleanup()
59+ {
60+ spy.clear();
61+ }
62+
63+ function test_purchase_completed() {
64+ var button = findChild(root, "previewPayments");
65+ verify(button != null);
66+ spy.target = previewPayments;
67+
68+ // Exercise the purchaseCompleted signal here.
69+ previewPayments.widgetData = jsonPurchase;
70+ mouseClick(button, button.width / 2, button.height / 2);
71+
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"]);
77+ }
78+
79+ function test_purchase_error() {
80+ var button = findChild(root, "previewPayments");
81+ verify(button != null);
82+ spy.target = previewPayments;
83+
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);
88+
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"]);
94+ }
95+ }
96+}