Skip to content

Commit f199b8a

Browse files
author
MarcoFalke
committed
Merge #11365: [Tests] Add Qt GUI tests to Overview and ReceiveCoin Page
634e38c [Tests] Add Qt GUI tests to Overview and ReceiveCoin Page (Anditto Heristyo) Pull request description: I've added some Qt wallet tests based on #9974, namely the input & buttons on ReceiveCoin. Tree-SHA512: f4223827145e35c2abee83a6ca777498bebcff3825fece10fbb1dbfd1f6bb017d3f2c0521662854b4407cdeee9c6a527269ab9cc28e0dc85c11b668155fcd195
2 parents 90926db + 634e38c commit f199b8a

File tree

1 file changed

+71
-2
lines changed

1 file changed

+71
-2
lines changed

src/qt/test/wallettests.cpp

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#include "test/test_bitcoin.h"
1414
#include "validation.h"
1515
#include "wallet/wallet.h"
16+
#include "qt/overviewpage.h"
17+
#include "qt/receivecoinsdialog.h"
18+
#include "qt/recentrequeststablemodel.h"
19+
#include "qt/receiverequestdialog.h"
1620

1721
#include <QAbstractButton>
1822
#include <QAction>
@@ -21,6 +25,9 @@
2125
#include <QPushButton>
2226
#include <QTimer>
2327
#include <QVBoxLayout>
28+
#include <QTextEdit>
29+
#include <QListView>
30+
#include <QDialogButtonBox>
2431

2532
namespace
2633
{
@@ -140,7 +147,7 @@ void BumpFee(TransactionView& view, const uint256& txid, bool expectDisabled, st
140147
// src/qt/test/test_bitcoin-qt -platform xcb # Linux
141148
// src/qt/test/test_bitcoin-qt -platform windows # Windows
142149
// src/qt/test/test_bitcoin-qt -platform cocoa # macOS
143-
void TestSendCoins()
150+
void TestGUI()
144151
{
145152
// Set up wallet and chain with 105 blocks (5 mature blocks for spending).
146153
TestChain100Setup test;
@@ -184,6 +191,68 @@ void TestSendCoins()
184191
BumpFee(transactionView, txid2, false /* expect disabled */, {} /* expected error */, false /* cancel */);
185192
BumpFee(transactionView, txid2, true /* expect disabled */, "already bumped" /* expected error */, false /* cancel */);
186193

194+
// Check current balance on OverviewPage
195+
OverviewPage overviewPage(platformStyle.get());
196+
overviewPage.setWalletModel(&walletModel);
197+
QLabel* balanceLabel = overviewPage.findChild<QLabel*>("labelBalance");
198+
QString balanceText = balanceLabel->text();
199+
int unit = walletModel.getOptionsModel()->getDisplayUnit();
200+
CAmount balance = walletModel.getBalance();
201+
QString balanceComparison = BitcoinUnits::formatWithUnit(unit, balance, false, BitcoinUnits::separatorAlways);
202+
QCOMPARE(balanceText, balanceComparison);
203+
204+
// Check Request Payment button
205+
ReceiveCoinsDialog receiveCoinsDialog(platformStyle.get());
206+
receiveCoinsDialog.setModel(&walletModel);
207+
RecentRequestsTableModel* requestTableModel = walletModel.getRecentRequestsTableModel();
208+
209+
// Label input
210+
QLineEdit* labelInput = receiveCoinsDialog.findChild<QLineEdit*>("reqLabel");
211+
labelInput->setText("TEST_LABEL_1");
212+
213+
// Amount input
214+
BitcoinAmountField* amountInput = receiveCoinsDialog.findChild<BitcoinAmountField*>("reqAmount");
215+
amountInput->setValue(1);
216+
217+
// Message input
218+
QLineEdit* messageInput = receiveCoinsDialog.findChild<QLineEdit*>("reqMessage");
219+
messageInput->setText("TEST_MESSAGE_1");
220+
int initialRowCount = requestTableModel->rowCount({});
221+
QPushButton* requestPaymentButton = receiveCoinsDialog.findChild<QPushButton*>("receiveButton");
222+
requestPaymentButton->click();
223+
for (QWidget* widget : QApplication::topLevelWidgets()) {
224+
if (widget->inherits("ReceiveRequestDialog")) {
225+
ReceiveRequestDialog* receiveRequestDialog = qobject_cast<ReceiveRequestDialog*>(widget);
226+
QTextEdit* rlist = receiveRequestDialog->QObject::findChild<QTextEdit*>("outUri");
227+
QString paymentText = rlist->toPlainText();
228+
QStringList paymentTextList = paymentText.split('\n');
229+
QCOMPARE(paymentTextList.at(0), QString("Payment information"));
230+
QVERIFY(paymentTextList.at(1).indexOf(QString("URI: bitcoin:")) != -1);
231+
QVERIFY(paymentTextList.at(2).indexOf(QString("Address:")) != -1);
232+
QCOMPARE(paymentTextList.at(3), QString("Amount: 0.00000001 ") + QString::fromStdString(CURRENCY_UNIT));
233+
QCOMPARE(paymentTextList.at(4), QString("Label: TEST_LABEL_1"));
234+
QCOMPARE(paymentTextList.at(5), QString("Message: TEST_MESSAGE_1"));
235+
}
236+
}
237+
238+
// Clear button
239+
QPushButton* clearButton = receiveCoinsDialog.findChild<QPushButton*>("clearButton");
240+
clearButton->click();
241+
QCOMPARE(labelInput->text(), QString(""));
242+
QCOMPARE(amountInput->value(), CAmount(0));
243+
QCOMPARE(messageInput->text(), QString(""));
244+
245+
// Check addition to history
246+
int currentRowCount = requestTableModel->rowCount({});
247+
QCOMPARE(currentRowCount, initialRowCount+1);
248+
249+
// Check Remove button
250+
QTableView* table = receiveCoinsDialog.findChild<QTableView*>("recentRequestsView");
251+
table->selectRow(currentRowCount-1);
252+
QPushButton* removeRequestButton = receiveCoinsDialog.findChild<QPushButton*>("removeRequestButton");
253+
removeRequestButton->click();
254+
QCOMPARE(requestTableModel->rowCount({}), currentRowCount-1);
255+
187256
bitdb.Flush(true);
188257
bitdb.Reset();
189258
}
@@ -192,5 +261,5 @@ void TestSendCoins()
192261

193262
void WalletTests::walletTests()
194263
{
195-
TestSendCoins();
264+
TestGUI();
196265
}

0 commit comments

Comments
 (0)