on xenial help sign in
- Reset button state on cancel Fixes: 1362622

Approved by: Michał Sawicz

commit2c978cdd5102189c8a7d1c6c3efcf9f69fb4d5b5 authorDiego Sarmentero <diego.sarmentero@gmail.com> dateMon 8 Sep 2014, 14:12 (12 years ago) parent61569682bcd814
4 files changed+62−16
qml/Dash/Previews/PreviewPayments.qml+2 tests/mocks/Ubuntu/Payments/MockPayments.cpp+10−7 tests/mocks/Ubuntu/Payments/MockPayments.h+1 tests/qmltests/Dash/Previews/tst_PreviewPayments.qml+49−9
qml/Dash/Previews/PreviewPayments.qml+2
@@ -49,6 +49,7 @@ PreviewWidget {
4949
5050 Payments {
5151 id: paymentClient
52+ objectName: "paymentClient"
5253
5354 property var source: widgetData["source"]
5455
@@ -59,6 +60,7 @@ PreviewWidget {
5960 root.triggered(widgetId, "purchaseCompleted", source);
6061 }
6162 onPurchaseError: {
63+ paymentButton.opacity = 1;
6264 root.triggered(widgetId, "purchaseError", source);
6365 }
6466 }
tests/mocks/Ubuntu/Payments/MockPayments.cpp+10−7
@@ -77,13 +77,16 @@ void MockPayments::setStoreItemId(const QString &store_item_id)
7777
7878void MockPayments::start()
7979{
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 {
80+ if (m_store_item_id.isEmpty()) {
8781 Q_EMIT purchaseError("No item ID supplied.");
8882 }
8983}
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:
4141 void setPrice(const double price);
4242 void setStoreItemId(const QString& store_item_id);
4343 Q_INVOKABLE void start();
44+ Q_INVOKABLE void process(); // only available for testing
4445
4546Q_SIGNALS:
4647 void currencyChanged(const QString& currency);
tests/qmltests/Dash/Previews/tst_PreviewPayments.qml+49−9
@@ -48,19 +48,28 @@ Rectangle {
4848 UT.UnityTestCase {
4949 name: "PreviewPaymentsTest"
5050 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+ }
5158
5259 function cleanup()
5360 {
61+ paymentClient = null;
62+ previewPayments.widgetData = null;
5463 spy.clear();
55− var button = findChild(root, "paymentButton");
64+ var button = findChild(previewPayments, "paymentButton");
5665 button.opacity = 1;
5766 }
5867
5968 function test_purchase_text_display() {
6069 previewPayments.widgetData = jsonPurchase;
6170
62− var button = findChild(root, "paymentButton");
63− verify(button != null, "Button not found.");
71+ var button = findChild(previewPayments, "paymentButton");
72+ verify(button, "Button not found.");
6473 compare(button.text, "0.99USD");
6574 }
6675
@@ -68,11 +77,12 @@ Rectangle {
6877 // Exercise the purchaseCompleted signal here.
6978 previewPayments.widgetData = jsonPurchase;
7079
71− var button = findChild(root, "paymentButton");
72− verify(button != null, "Button not found.");
80+ var button = findChild(previewPayments, "paymentButton");
81+ verify(button, "Button not found.");
7382
7483 mouseClick(button, button.width / 2, button.height / 2);
7584
85+ paymentClient.process();
7686 spy.wait();
7787
7888 var args = spy.signalArguments[0];
@@ -85,8 +95,8 @@ Rectangle {
8595 // Make sure the progress bar is shown.
8696 previewPayments.widgetData = jsonPurchase;
8797
88− var button = findChild(root, "paymentButton");
89− var progress = findChild(root, "loadingBar");
98+ var button = findChild(previewPayments, "paymentButton");
99+ var progress = findChild(previewPayments, "loadingBar");
90100
91101 tryCompare(progress, "visible", false);
92102 tryCompare(progress, "opacity", 0);
@@ -95,6 +105,7 @@ Rectangle {
95105
96106 mouseClick(button, button.width / 2, button.height / 2);
97107
108+ paymentClient.process();
98109 spy.wait();
99110
100111 tryCompare(progress, "visible", true);
@@ -103,16 +114,45 @@ Rectangle {
103114 tryCompare(button, "opacity", 0);
104115 }
105116
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+
106145 function test_purchase_error() {
107146 // The mock Payments triggers an error when com.example.invalid is
108147 // passed to it as store_item_id. Exercise it here
109148 previewPayments.widgetData = jsonPurchaseError;
110149
111− var button = findChild(root, "paymentButton");
112− verify(button != null, "Button not found.");
150+ var button = findChild(previewPayments, "paymentButton");
151+ verify(button, "Button not found.");
113152
114153 mouseClick(button, button.width / 2, button.height / 2);
115154
155+ paymentClient.process();
116156 spy.wait();
117157
118158 var args = spy.signalArguments[0];