on xenial help sign in
Add implicit height/width back to the widget.
ee847d5Rodney Dawes
qml/Dash/Previews/PreviewPayments.qml+3
@@ -28,6 +28,9 @@ import Ubuntu.Payments 0.1
28PreviewWidget {
28PreviewWidget {
29 id: root
29 id: root
30
30
31+ implicitHeight: paymentButton.implicitHeight
32+ implicitWidth: paymentButton.implicitWidth
33+
31 Button {
34 Button {
32 id: paymentButton
35 id: paymentButton
33 objectName: "paymentButton"
36 objectName: "paymentButton"
tests/mocks/Ubuntu/Payments/MockPayments.cpp+4−2
@@ -14,10 +14,10 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17−#include <QLocale>
18−
19#include "MockPayments.h"
17#include "MockPayments.h"
20
18
19+#include <QLocale>
20+
21
21
22MockPayments::MockPayments(QObject *parent)
22MockPayments::MockPayments(QObject *parent)
23 : QObject(parent)
23 : QObject(parent)
@@ -83,5 +83,7 @@ void MockPayments::start()
83 } else {
83 } else {
84 Q_EMIT purchaseCompleted();
84 Q_EMIT purchaseCompleted();
85 }
85 }
86+ } else {
87+ Q_EMIT purchaseError("No item ID supplied.");
86 }
88 }
87}
89}
tests/qmltests/Dash/Previews/tst_PreviewPayments.qml+21−17
@@ -35,20 +35,14 @@ Rectangle {
35
35
36 SignalSpy {
36 SignalSpy {
37 id: spy
37 id: spy
38+ target: previewPayments
38 signalName: "triggered"
39 signalName: "triggered"
39 }
40 }
40
41
41 PreviewPayments {
42 PreviewPayments {
42 id: previewPayments
43 id: previewPayments
43 widgetId: "previewPayments"
44 widgetId: "previewPayments"
44− widgetData: jsonPurchase
45 width: units.gu(30)
45 width: units.gu(30)
46−
47− Rectangle {
48− anchors.fill: parent
49− color: "red"
50− opacity: 0.1
51− }
52 }
46 }
53
47
54 UT.UnityTestCase {
48 UT.UnityTestCase {
@@ -60,16 +54,25 @@ Rectangle {
60 spy.clear();
54 spy.clear();
61 }
55 }
62
56
63− function test_purchase_completed() {
57+ function test_purchase_text_display() {
64− var button = findChild(root, "previewPayments");
58+ previewPayments.widgetData = jsonPurchase;
65− verify(button != null);
66− spy.target = previewPayments;
67
59
60+ var button = findChild(root, "paymentButton");
61+ verify(button != null, "Button not found.");
62+ compare(button.text, "USD0.99");
63+ }
64+
65+ function test_purchase_completed() {
68 // Exercise the purchaseCompleted signal here.
66 // Exercise the purchaseCompleted signal here.
69 previewPayments.widgetData = jsonPurchase;
67 previewPayments.widgetData = jsonPurchase;
68+
69+ var button = findChild(root, "paymentButton");
70+ verify(button != null, "Button not found.");
71+
70 mouseClick(button, button.width / 2, button.height / 2);
72 mouseClick(button, button.width / 2, button.height / 2);
71
73
72− compare(spy.count, 1);
74+ spy.wait();
75+
73 var args = spy.signalArguments[0];
76 var args = spy.signalArguments[0];
74 compare(args[0], "previewPayments");
77 compare(args[0], "previewPayments");
75 compare(args[1], "purchaseCompleted");
78 compare(args[1], "purchaseCompleted");
@@ -77,16 +80,17 @@ Rectangle {
77 }
80 }
78
81
79 function test_purchase_error() {
82 function test_purchase_error() {
80− var button = findChild(root, "previewPayments");
81− verify(button != null);
82− spy.target = previewPayments;
83−
84 // The mock Payments triggers an error when com.example.invalid is
83 // The mock Payments triggers an error when com.example.invalid is
85 // passed to it as store_item_id. Exercise it here
84 // passed to it as store_item_id. Exercise it here
86 previewPayments.widgetData = jsonPurchaseError;
85 previewPayments.widgetData = jsonPurchaseError;
86+
87+ var button = findChild(root, "paymentButton");
88+ verify(button != null, "Button not found.");
89+
87 mouseClick(button, button.width / 2, button.height / 2);
90 mouseClick(button, button.width / 2, button.height / 2);
88
91
89− compare(spy.count, 1);
92+ spy.wait();
93+
90 var args = spy.signalArguments[0];
94 var args = spy.signalArguments[0];
91 compare(args[0], "previewPayments");
95 compare(args[0], "previewPayments");
92 compare(args[1], "purchaseError");
96 compare(args[1], "purchaseError");