on xenial help sign in
fixing tests as suggested
2bcd814Diego Sarmentero
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+26−17
@@ -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);
@@ -105,10 +116,10 @@ Rectangle {
105
116
106 function test_progress_show_cancel() {
117 function test_progress_show_cancel() {
107 // Make sure the progress bar is shown.
118 // Make sure the progress bar is shown.
108− previewPayments.widgetData = jsonPurchase;
119+ previewPayments.widgetData = jsonPurchaseError;
109
120
110− var button = findChild(root, "paymentButton");
121+ var button = findChild(previewPayments, "paymentButton");
111− var progress = findChild(root, "loadingBar");
122+ var progress = findChild(previewPayments, "loadingBar");
112
123
113 tryCompare(progress, "visible", false);
124 tryCompare(progress, "visible", false);
114 tryCompare(progress, "opacity", 0);
125 tryCompare(progress, "opacity", 0);
@@ -117,16 +128,13 @@ Rectangle {
117
128
118 mouseClick(button, button.width / 2, button.height / 2);
129 mouseClick(button, button.width / 2, button.height / 2);
119
130
120− spy.wait();
121−
122 tryCompare(progress, "visible", true);
131 tryCompare(progress, "visible", true);
123 tryCompare(progress, "opacity", 1);
132 tryCompare(progress, "opacity", 1);
124 tryCompare(button, "visible", false);
133 tryCompare(button, "visible", false);
125 tryCompare(button, "opacity", 0);
134 tryCompare(button, "opacity", 0);
126
135
127− var paymentClient = findChild(root, "paymentClient");
136+ paymentClient.process();
128− paymentClient.storeItemId = "com.example.invalid";
137+ spy.wait();
129− paymentClient.start();
130
138
131 tryCompare(progress, "visible", false);
139 tryCompare(progress, "visible", false);
132 tryCompare(progress, "opacity", 0);
140 tryCompare(progress, "opacity", 0);
@@ -139,11 +147,12 @@ Rectangle {
139 // passed to it as store_item_id. Exercise it here
147 // passed to it as store_item_id. Exercise it here
140 previewPayments.widgetData = jsonPurchaseError;
148 previewPayments.widgetData = jsonPurchaseError;
141
149
142− var button = findChild(root, "paymentButton");
150+ var button = findChild(previewPayments, "paymentButton");
143− verify(button != null, "Button not found.");
151+ verify(button, "Button not found.");
144
152
145 mouseClick(button, button.width / 2, button.height / 2);
153 mouseClick(button, button.width / 2, button.height / 2);
146
154
155+ paymentClient.process();
147 spy.wait();
156 spy.wait();
148
157
149 var args = spy.signalArguments[0];
158 var args = spy.signalArguments[0];