on xenial help sign in
Add implicit height/width back to the widget.

Clean up the qml unit tests and make them work. Add another test for the text value of the button. Fix the mock to default to sending an error when no item id is found.

commitee847d590953754b4a5fe5ef61753aa6443c408d authorRodney Dawes <rodney.dawes@canonical.com> dateMon 30 Jun 2014, 10:43 (12 years ago) parent2f7b59e
3 files changed+28−19
qml/Dash/Previews/PreviewPayments.qml+3 tests/mocks/Ubuntu/Payments/MockPayments.cpp+4−2 tests/qmltests/Dash/Previews/tst_PreviewPayments.qml+21−17
qml/Dash/Previews/PreviewPayments.qml+3
@@ -28,6 +28,9 @@ import Ubuntu.Payments 0.1
2828PreviewWidget {
2929 id: root
3030
31+ implicitHeight: paymentButton.implicitHeight
32+ implicitWidth: paymentButton.implicitWidth
33+
3134 Button {
3235 id: paymentButton
3336 objectName: "paymentButton"
tests/mocks/Ubuntu/Payments/MockPayments.cpp+4−2
@@ -14,10 +14,10 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#include <QLocale>
18−
1917#include "MockPayments.h"
2018
19+#include <QLocale>
20+
2121
2222MockPayments::MockPayments(QObject *parent)
2323 : QObject(parent)
@@ -83,5 +83,7 @@ void MockPayments::start()
8383 } else {
8484 Q_EMIT purchaseCompleted();
8585 }
86+ } else {
87+ Q_EMIT purchaseError("No item ID supplied.");
8688 }
8789}
tests/qmltests/Dash/Previews/tst_PreviewPayments.qml+21−17
@@ -35,20 +35,14 @@ Rectangle {
3535
3636 SignalSpy {
3737 id: spy
38+ target: previewPayments
3839 signalName: "triggered"
3940 }
4041
4142 PreviewPayments {
4243 id: previewPayments
4344 widgetId: "previewPayments"
44− widgetData: jsonPurchase
4545 width: units.gu(30)
46−
47− Rectangle {
48− anchors.fill: parent
49− color: "red"
50− opacity: 0.1
51− }
5246 }
5347
5448 UT.UnityTestCase {
@@ -60,16 +54,25 @@ Rectangle {
6054 spy.clear();
6155 }
6256
63− function test_purchase_completed() {
64− var button = findChild(root, "previewPayments");
65− verify(button != null);
66− spy.target = previewPayments;
57+ function test_purchase_text_display() {
58+ previewPayments.widgetData = jsonPurchase;
6759
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() {
6866 // Exercise the purchaseCompleted signal here.
6967 previewPayments.widgetData = jsonPurchase;
68+
69+ var button = findChild(root, "paymentButton");
70+ verify(button != null, "Button not found.");
71+
7072 mouseClick(button, button.width / 2, button.height / 2);
7173
72− compare(spy.count, 1);
74+ spy.wait();
75+
7376 var args = spy.signalArguments[0];
7477 compare(args[0], "previewPayments");
7578 compare(args[1], "purchaseCompleted");
@@ -77,16 +80,17 @@ Rectangle {
7780 }
7881
7982 function test_purchase_error() {
80− var button = findChild(root, "previewPayments");
81− verify(button != null);
82− spy.target = previewPayments;
83−
8483 // The mock Payments triggers an error when com.example.invalid is
8584 // passed to it as store_item_id. Exercise it here
8685 previewPayments.widgetData = jsonPurchaseError;
86+
87+ var button = findChild(root, "paymentButton");
88+ verify(button != null, "Button not found.");
89+
8790 mouseClick(button, button.width / 2, button.height / 2);
8891
89− compare(spy.count, 1);
92+ spy.wait();
93+
9094 var args = spy.signalArguments[0];
9195 compare(args[0], "previewPayments");
9296 compare(args[1], "purchaseError");