Merge lp:~diegosarmentero/unity8/reset-button into lp:unity8

Proposed by Diego Sarmentero
Status: Merged
Approved by: Michał Sawicz
Approved revision: 1208
Merged at revision: 1241
Proposed branch: lp:~diegosarmentero/unity8/reset-button
Merge into: lp:unity8
Diff against target: 193 lines (+76/-30)
4 files modified
qml/Dash/Previews/PreviewPayments.qml (+2/-0)
tests/mocks/Ubuntu/Payments/MockPayments.cpp (+10/-7)
tests/mocks/Ubuntu/Payments/MockPayments.h (+1/-0)
tests/qmltests/Dash/Previews/tst_PreviewPayments.qml (+63/-23)
To merge this branch: bzr merge lp:~diegosarmentero/unity8/reset-button
Reviewer Review Type Date Requested Status
Michał Sawicz Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+232406@code.launchpad.net

Commit message

- Reset button state on cancel

To post a comment you must log in.
Revision history for this message
Michał Sawicz (saviq) wrote :

Could we get a test for this please.

review: Needs Fixing
1207. By Diego Sarmentero

adding tests

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

> Could we get a test for this please.

When trying to run the tests, for some reason this is not being properly executed in the mock:

            var paymentClient = findChild(root, "paymentClient");
            paymentClient.storeItemId = "com.example.invalid";
            paymentClient.start();

so the purchaseError signal the test need is not being emitted.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

Hey, this would be my approach to making the test work:

http://paste.ubuntu.com/8167187/

But... Why do we even want this? purchaseError triggers the "purchaseError" action, shouldn't that result in the preview being reloaded anyway, so bringing the button back is weird as it will be replaced in a moment anyway?

If we want to treat cancel and error differently, we need separate purchaseCancel on the client, don't we?

review: Needs Information
1208. By Diego Sarmentero

fixing tests as suggested

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

> Hey, this would be my approach to making the test work:
>
> http://paste.ubuntu.com/8167187/
>
> But... Why do we even want this? purchaseError triggers the "purchaseError"
> action, shouldn't that result in the preview being reloaded anyway, so
> bringing the button back is weird as it will be replaced in a moment anyway?
>
> If we want to treat cancel and error differently, we need separate
> purchaseCancel on the client, don't we?

Tests fixed as suggested.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

> Hey, this would be my approach to making the test work:
>
> http://paste.ubuntu.com/8167187/
>
> But... Why do we even want this? purchaseError triggers the "purchaseError"
> action, shouldn't that result in the preview being reloaded anyway, so
> bringing the button back is weird as it will be replaced in a moment anyway?
>
> If we want to treat cancel and error differently, we need separate
> purchaseCancel on the client, don't we?

After the discussion we had on irc regarding the architectural changes that we need to do here for cancel, success and error, we have been discussing this with alecu and ted to find which are the changes that are needed.
The code in this branch will be needed in the future for those changes anyway, and it's needed now to not block the preview, so the idea was to land this if possible (because right now it's basically a bad naming thing were the signal should be Canceled instead of Error), and include the other signal later when pay-service can differenciate the different errors.

Revision history for this message
Michał Sawicz (saviq) wrote :

 * Did you perform an exploratory manual test run of the code change and any related functionality?
Y
 * Did CI run pass? If not, please explain why.
One failure fixed elsewhere.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'qml/Dash/Previews/PreviewPayments.qml'
2--- qml/Dash/Previews/PreviewPayments.qml 2014-08-19 13:53:13 +0000
3+++ qml/Dash/Previews/PreviewPayments.qml 2014-08-29 11:44:04 +0000
4@@ -49,6 +49,7 @@
5
6 Payments {
7 id: paymentClient
8+ objectName: "paymentClient"
9
10 property var source: widgetData["source"]
11
12@@ -59,6 +60,7 @@
13 root.triggered(widgetId, "purchaseCompleted", source);
14 }
15 onPurchaseError: {
16+ paymentButton.opacity = 1;
17 root.triggered(widgetId, "purchaseError", source);
18 }
19 }
20
21=== modified file 'tests/mocks/Ubuntu/Payments/MockPayments.cpp'
22--- tests/mocks/Ubuntu/Payments/MockPayments.cpp 2014-06-30 14:43:01 +0000
23+++ tests/mocks/Ubuntu/Payments/MockPayments.cpp 2014-08-29 11:44:04 +0000
24@@ -77,13 +77,16 @@
25
26 void MockPayments::start()
27 {
28- if (!m_store_item_id.isEmpty()) {
29- if (m_store_item_id == "com.example.invalid") {
30- Q_EMIT purchaseError("Purchase failed.");
31- } else {
32- Q_EMIT purchaseCompleted();
33- }
34+ if (m_store_item_id.isEmpty()) {
35+ Q_EMIT purchaseError("No item ID supplied.");
36+ }
37+}
38+
39+void MockPayments::process()
40+{
41+ if (m_store_item_id == "com.example.invalid") {
42+ Q_EMIT purchaseError("Purchase failed.");
43 } else {
44- Q_EMIT purchaseError("No item ID supplied.");
45+ Q_EMIT purchaseCompleted();
46 }
47 }
48
49=== modified file 'tests/mocks/Ubuntu/Payments/MockPayments.h'
50--- tests/mocks/Ubuntu/Payments/MockPayments.h 2014-06-27 20:54:41 +0000
51+++ tests/mocks/Ubuntu/Payments/MockPayments.h 2014-08-29 11:44:04 +0000
52@@ -41,6 +41,7 @@
53 void setPrice(const double price);
54 void setStoreItemId(const QString& store_item_id);
55 Q_INVOKABLE void start();
56+ Q_INVOKABLE void process(); // only available for testing
57
58 Q_SIGNALS:
59 void currencyChanged(const QString& currency);
60
61=== modified file 'tests/qmltests/Dash/Previews/tst_PreviewPayments.qml'
62--- tests/qmltests/Dash/Previews/tst_PreviewPayments.qml 2014-08-19 14:48:07 +0000
63+++ tests/qmltests/Dash/Previews/tst_PreviewPayments.qml 2014-08-29 11:44:04 +0000
64@@ -48,19 +48,28 @@
65 UT.UnityTestCase {
66 name: "PreviewPaymentsTest"
67 when: windowShown
68+ property var paymentClient
69+
70+ function init()
71+ {
72+ paymentClient = findInvisibleChild(previewPayments, "paymentClient");
73+ verify(paymentClient, "Could not find the payment client object.");
74+ }
75
76 function cleanup()
77 {
78+ paymentClient = null;
79+ previewPayments.widgetData = null;
80 spy.clear();
81- var button = findChild(root, "paymentButton");
82+ var button = findChild(previewPayments, "paymentButton");
83 button.opacity = 1;
84 }
85
86 function test_purchase_text_display() {
87 previewPayments.widgetData = jsonPurchase;
88
89- var button = findChild(root, "paymentButton");
90- verify(button != null, "Button not found.");
91+ var button = findChild(previewPayments, "paymentButton");
92+ verify(button, "Button not found.");
93 compare(button.text, "0.99USD");
94 }
95
96@@ -68,11 +77,12 @@
97 // Exercise the purchaseCompleted signal here.
98 previewPayments.widgetData = jsonPurchase;
99
100- var button = findChild(root, "paymentButton");
101- verify(button != null, "Button not found.");
102+ var button = findChild(previewPayments, "paymentButton");
103+ verify(button, "Button not found.");
104
105 mouseClick(button, button.width / 2, button.height / 2);
106
107+ paymentClient.process();
108 spy.wait();
109
110 var args = spy.signalArguments[0];
111@@ -85,22 +95,51 @@
112 // Make sure the progress bar is shown.
113 previewPayments.widgetData = jsonPurchase;
114
115- var button = findChild(root, "paymentButton");
116- var progress = findChild(root, "loadingBar");
117-
118- tryCompare(progress, "visible", false);
119- tryCompare(progress, "opacity", 0);
120- tryCompare(button, "visible", true);
121- tryCompare(button, "opacity", 1);
122-
123- mouseClick(button, button.width / 2, button.height / 2);
124-
125- spy.wait();
126-
127- tryCompare(progress, "visible", true);
128- tryCompare(progress, "opacity", 1);
129- tryCompare(button, "visible", false);
130- tryCompare(button, "opacity", 0);
131+ var button = findChild(previewPayments, "paymentButton");
132+ var progress = findChild(previewPayments, "loadingBar");
133+
134+ tryCompare(progress, "visible", false);
135+ tryCompare(progress, "opacity", 0);
136+ tryCompare(button, "visible", true);
137+ tryCompare(button, "opacity", 1);
138+
139+ mouseClick(button, button.width / 2, button.height / 2);
140+
141+ paymentClient.process();
142+ spy.wait();
143+
144+ tryCompare(progress, "visible", true);
145+ tryCompare(progress, "opacity", 1);
146+ tryCompare(button, "visible", false);
147+ tryCompare(button, "opacity", 0);
148+ }
149+
150+ function test_progress_show_cancel() {
151+ // Make sure the progress bar is shown.
152+ previewPayments.widgetData = jsonPurchaseError;
153+
154+ var button = findChild(previewPayments, "paymentButton");
155+ var progress = findChild(previewPayments, "loadingBar");
156+
157+ tryCompare(progress, "visible", false);
158+ tryCompare(progress, "opacity", 0);
159+ tryCompare(button, "visible", true);
160+ tryCompare(button, "opacity", 1);
161+
162+ mouseClick(button, button.width / 2, button.height / 2);
163+
164+ tryCompare(progress, "visible", true);
165+ tryCompare(progress, "opacity", 1);
166+ tryCompare(button, "visible", false);
167+ tryCompare(button, "opacity", 0);
168+
169+ paymentClient.process();
170+ spy.wait();
171+
172+ tryCompare(progress, "visible", false);
173+ tryCompare(progress, "opacity", 0);
174+ tryCompare(button, "visible", true);
175+ tryCompare(button, "opacity", 1);
176 }
177
178 function test_purchase_error() {
179@@ -108,11 +147,12 @@
180 // passed to it as store_item_id. Exercise it here
181 previewPayments.widgetData = jsonPurchaseError;
182
183- var button = findChild(root, "paymentButton");
184- verify(button != null, "Button not found.");
185+ var button = findChild(previewPayments, "paymentButton");
186+ verify(button, "Button not found.");
187
188 mouseClick(button, button.width / 2, button.height / 2);
189
190+ paymentClient.process();
191 spy.wait();
192
193 var args = spy.signalArguments[0];

Subscribers

People subscribed via source and target branches