on xenial help sign in
- Reset button state on cancel Fixes: 1362622
2c978cdDiego Sarmentero
qml/Dash/Previews/PreviewPayments.qml+2
@@ -49,6 +49,7 @@ PreviewWidget {
49
49
50 Payments {
50 Payments {
51 id: paymentClient
51 id: paymentClient
52+ objectName: "paymentClient"
52
53
53 property var source: widgetData["source"]
54 property var source: widgetData["source"]
54
55
@@ -59,6 +60,7 @@ PreviewWidget {
59 root.triggered(widgetId, "purchaseCompleted", source);
60 root.triggered(widgetId, "purchaseCompleted", source);
60 }
61 }
61 onPurchaseError: {
62 onPurchaseError: {
63+ paymentButton.opacity = 1;
62 root.triggered(widgetId, "purchaseError", source);
64 root.triggered(widgetId, "purchaseError", source);
63 }
65 }
64 }
66 }
tests/mocks/Ubuntu/Payments/MockPayments.cpp+10−7
@@ -77,13 +77,16 @@ void MockPayments::setStoreItemId(const QString &store_item_id)
77
77
78void MockPayments::start()
78void MockPayments::start()
79{
79{
80− if (!m_store_item_id.isEmpty()) {
80+ if (m_store_item_id.isEmpty()) {
81− if (m_store_item_id == "com.example.invalid") {
82− Q_EMIT purchaseError("Purchase failed.");
83− } else {
84− Q_EMIT purchaseCompleted();
85− }
86− } else {
87 Q_EMIT purchaseError("No item ID supplied.");
81 Q_EMIT purchaseError("No item ID supplied.");
88 }
82 }
89}
83}
84+
85+void MockPayments::process()
86+{
87+ if (m_store_item_id == "com.example.invalid") {
88+ Q_EMIT purchaseError("Purchase failed.");
89+ } else {
90+ Q_EMIT purchaseCompleted();
91+ }
92+}
tests/mocks/Ubuntu/Payments/MockPayments.h+1
@@ -41,6 +41,7 @@ public:
41 void setPrice(const double price);
41 void setPrice(const double price);
42 void setStoreItemId(const QString& store_item_id);
42 void setStoreItemId(const QString& store_item_id);
43 Q_INVOKABLE void start();
43 Q_INVOKABLE void start();
44+ Q_INVOKABLE void process(); // only available for testing
44
45
45Q_SIGNALS:
46Q_SIGNALS:
46 void currencyChanged(const QString& currency);
47 void currencyChanged(const QString& currency);
tests/qmltests/Dash/Previews/tst_PreviewPayments.qml+49−9
@@ -48,19 +48,28 @@ Rectangle {
48 UT.UnityTestCase {
48 UT.UnityTestCase {
49 name: "PreviewPaymentsTest"
49 name: "PreviewPaymentsTest"
50 when: windowShown
50 when: windowShown
51+ property var paymentClient
52+
53+ function init()
54+ {
55+ paymentClient = findInvisibleChild(previewPayments, "paymentClient");
56+ verify(paymentClient, "Could not find the payment client object.");
57+ }
51
58
52 function cleanup()
59 function cleanup()
53 {
60 {
61+ paymentClient = null;
62+ previewPayments.widgetData = null;
54 spy.clear();
63 spy.clear();
55− var button = findChild(root, "paymentButton");
64+ var button = findChild(previewPayments, "paymentButton");
56 button.opacity = 1;
65 button.opacity = 1;
57 }
66 }
58
67
59 function test_purchase_text_display() {
68 function test_purchase_text_display() {
60 previewPayments.widgetData = jsonPurchase;
69 previewPayments.widgetData = jsonPurchase;
61
70
62− var button = findChild(root, "paymentButton");
71+ var button = findChild(previewPayments, "paymentButton");
63− verify(button != null, "Button not found.");
72+ verify(button, "Button not found.");
64 compare(button.text, "0.99USD");
73 compare(button.text, "0.99USD");
65 }
74 }
66
75
@@ -68,11 +77,12 @@ Rectangle {
68 // Exercise the purchaseCompleted signal here.
77 // Exercise the purchaseCompleted signal here.
69 previewPayments.widgetData = jsonPurchase;
78 previewPayments.widgetData = jsonPurchase;
70
79
71− var button = findChild(root, "paymentButton");
80+ var button = findChild(previewPayments, "paymentButton");
72− verify(button != null, "Button not found.");
81+ verify(button, "Button not found.");
73
82
74 mouseClick(button, button.width / 2, button.height / 2);
83 mouseClick(button, button.width / 2, button.height / 2);
75
84
85+ paymentClient.process();
76 spy.wait();
86 spy.wait();
77
87
78 var args = spy.signalArguments[0];
88 var args = spy.signalArguments[0];
@@ -85,8 +95,8 @@ Rectangle {
85 // Make sure the progress bar is shown.
95 // Make sure the progress bar is shown.
86 previewPayments.widgetData = jsonPurchase;
96 previewPayments.widgetData = jsonPurchase;
87
97
88− var button = findChild(root, "paymentButton");
98+ var button = findChild(previewPayments, "paymentButton");
89− var progress = findChild(root, "loadingBar");
99+ var progress = findChild(previewPayments, "loadingBar");
90
100
91 tryCompare(progress, "visible", false);
101 tryCompare(progress, "visible", false);
92 tryCompare(progress, "opacity", 0);
102 tryCompare(progress, "opacity", 0);
@@ -95,6 +105,7 @@ Rectangle {
95
105
96 mouseClick(button, button.width / 2, button.height / 2);
106 mouseClick(button, button.width / 2, button.height / 2);
97
107
108+ paymentClient.process();
98 spy.wait();
109 spy.wait();
99
110
100 tryCompare(progress, "visible", true);
111 tryCompare(progress, "visible", true);
@@ -103,16 +114,45 @@ Rectangle {
103 tryCompare(button, "opacity", 0);
114 tryCompare(button, "opacity", 0);
104 }
115 }
105
116
117+ function test_progress_show_cancel() {
118+ // Make sure the progress bar is shown.
119+ previewPayments.widgetData = jsonPurchaseError;
120+
121+ var button = findChild(previewPayments, "paymentButton");
122+ var progress = findChild(previewPayments, "loadingBar");
123+
124+ tryCompare(progress, "visible", false);
125+ tryCompare(progress, "opacity", 0);
126+ tryCompare(button, "visible", true);
127+ tryCompare(button, "opacity", 1);
128+
129+ mouseClick(button, button.width / 2, button.height / 2);
130+
131+ tryCompare(progress, "visible", true);
132+ tryCompare(progress, "opacity", 1);
133+ tryCompare(button, "visible", false);
134+ tryCompare(button, "opacity", 0);
135+
136+ paymentClient.process();
137+ spy.wait();
138+
139+ tryCompare(progress, "visible", false);
140+ tryCompare(progress, "opacity", 0);
141+ tryCompare(button, "visible", true);
142+ tryCompare(button, "opacity", 1);
143+ }
144+
106 function test_purchase_error() {
145 function test_purchase_error() {
107 // The mock Payments triggers an error when com.example.invalid is
146 // The mock Payments triggers an error when com.example.invalid is
108 // passed to it as store_item_id. Exercise it here
147 // passed to it as store_item_id. Exercise it here
109 previewPayments.widgetData = jsonPurchaseError;
148 previewPayments.widgetData = jsonPurchaseError;
110
149
111− var button = findChild(root, "paymentButton");
150+ var button = findChild(previewPayments, "paymentButton");
112− verify(button != null, "Button not found.");
151+ verify(button, "Button not found.");
113
152
114 mouseClick(button, button.width / 2, button.height / 2);
153 mouseClick(button, button.width / 2, button.height / 2);
115
154
155+ paymentClient.process();
116 spy.wait();
156 spy.wait();
117
157
118 var args = spy.signalArguments[0];
158 var args = spy.signalArguments[0];