on xenial help sign in
fixing tests as suggested
commit2bcd81438db85436a4665e13e75b5b55d168557c authorDiego Sarmentero <diego.sarmentero@gmail.com> dateFri 29 Aug 2014, 08:43 (12 years ago) parent614e7b1
3 files changed+37−24
tests/mocks/Ubuntu/Payments/MockPayments.cpp+10−7 tests/mocks/Ubuntu/Payments/MockPayments.h+1 tests/qmltests/Dash/Previews/tst_PreviewPayments.qml+26−17
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+26−17
@@ -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);
@@ -105,10 +116,10 @@ Rectangle {
105116
106117 function test_progress_show_cancel() {
107118 // Make sure the progress bar is shown.
108− previewPayments.widgetData = jsonPurchase;
119+ previewPayments.widgetData = jsonPurchaseError;
109120
110− var button = findChild(root, "paymentButton");
111− var progress = findChild(root, "loadingBar");
121+ var button = findChild(previewPayments, "paymentButton");
122+ var progress = findChild(previewPayments, "loadingBar");
112123
113124 tryCompare(progress, "visible", false);
114125 tryCompare(progress, "opacity", 0);
@@ -117,16 +128,13 @@ Rectangle {
117128
118129 mouseClick(button, button.width / 2, button.height / 2);
119130
120− spy.wait();
121−
122131 tryCompare(progress, "visible", true);
123132 tryCompare(progress, "opacity", 1);
124133 tryCompare(button, "visible", false);
125134 tryCompare(button, "opacity", 0);
126135
127− var paymentClient = findChild(root, "paymentClient");
128− paymentClient.storeItemId = "com.example.invalid";
129− paymentClient.start();
136+ paymentClient.process();
137+ spy.wait();
130138
131139 tryCompare(progress, "visible", false);
132140 tryCompare(progress, "opacity", 0);
@@ -139,11 +147,12 @@ Rectangle {
139147 // passed to it as store_item_id. Exercise it here
140148 previewPayments.widgetData = jsonPurchaseError;
141149
142− var button = findChild(root, "paymentButton");
143− verify(button != null, "Button not found.");
150+ var button = findChild(previewPayments, "paymentButton");
151+ verify(button, "Button not found.");
144152
145153 mouseClick(button, button.width / 2, button.height / 2);
146154
155+ paymentClient.process();
147156 spy.wait();
148157
149158 var args = spy.signalArguments[0];