on xenial help sign in
Show progress bar on payment button click
6fea321Diego Sarmentero
qml/Dash/Previews/PreviewPayments.qml+22−3
@@ -37,9 +37,15 @@ PreviewWidget {
37
37
38 color: Theme.palette.selected.foreground
38 color: Theme.palette.selected.foreground
39 text: paymentClient.formattedPrice
39 text: paymentClient.formattedPrice
40+ onClicked: {
40− onClicked: paymentClient.start()
41+ paymentClient.start();
42+ paymentButton.opacity = 0;
43+ }
41 anchors.right: parent.right
44 anchors.right: parent.right
42 width: (root.width - units.gu(1)) / 2
45 width: (root.width - units.gu(1)) / 2
46+ opacity: 1
47+ visible: paymentButton.opacity == 0 ? false : true
48+ Behavior on opacity { PropertyAnimation { duration: UbuntuAnimation.FastDuration } }
43
49
44 Payments {
50 Payments {
45 id: paymentClient
51 id: paymentClient
@@ -49,8 +55,21 @@ PreviewWidget {
49 price: source["price"]
55 price: source["price"]
50 currency: source["currency"]
56 currency: source["currency"]
51 storeItemId: source["store_item_id"]
57 storeItemId: source["store_item_id"]
58+ onPurchaseCompleted: {
52− onPurchaseCompleted: root.triggered(widgetId, "purchaseCompleted", source)
59+ root.triggered(widgetId, "purchaseCompleted", source);
60+ }
61+ onPurchaseError: {
53− onPurchaseError: root.triggered(widgetId, "purchaseError", source)
62+ root.triggered(widgetId, "purchaseError", source);
63+ }
54 }
64 }
55 }
65 }
66+
67+ ProgressBar {
68+ id: loadingBar
69+ objectName: "loadingBar"
70+ indeterminate: true
71+ anchors.fill: paymentButton
72+ opacity: 1 - paymentButton.opacity
73+ visible: !paymentButton.visible
74+ }
56}
75}
tests/qmltests/Dash/Previews/tst_PreviewPayments.qml+24
@@ -52,6 +52,8 @@ Rectangle {
52 function cleanup()
52 function cleanup()
53 {
53 {
54 spy.clear();
54 spy.clear();
55+ var button = findChild(root, "paymentButton");
56+ button.opacity = 1;
55 }
57 }
56
58
57 function test_purchase_text_display() {
59 function test_purchase_text_display() {
@@ -79,6 +81,28 @@ Rectangle {
79 compare(args[2], jsonPurchase["source"]);
81 compare(args[2], jsonPurchase["source"]);
80 }
82 }
81
83
84+ function test_progress_show() {
85+ // Make sure the progress bar is shown.
86+ previewPayments.widgetData = jsonPurchase;
87+
88+ var button = findChild(root, "paymentButton");
89+ var progress = findChild(root, "loadingBar");
90+
91+ tryCompare(progress, "visible", false);
92+ tryCompare(progress, "opacity", 0);
93+ tryCompare(button, "visible", true);
94+ tryCompare(button, "opacity", 1);
95+
96+ mouseClick(button, button.width / 2, button.height / 2);
97+
98+ spy.wait();
99+
100+ tryCompare(progress, "visible", true);
101+ tryCompare(progress, "opacity", 1);
102+ tryCompare(button, "visible", false);
103+ tryCompare(button, "opacity", 0);
104+ }
105+
82 function test_purchase_error() {
106 function test_purchase_error() {
83 // The mock Payments triggers an error when com.example.invalid is
107 // The mock Payments triggers an error when com.example.invalid is
84 // passed to it as store_item_id. Exercise it here
108 // passed to it as store_item_id. Exercise it here