Skip to content

Commit

Permalink
qt, test: Add tests for tableView in AddressBookPage dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Apr 23, 2022
1 parent edae3ab commit 1506913
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/qt/test/addressbooktests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <interfaces/chain.h>
#include <interfaces/node.h>
#include <qt/addressbookpage.h>
#include <qt/clientmodel.h>
#include <qt/editaddressdialog.h>
#include <qt/optionsmodel.h>
Expand All @@ -23,8 +24,9 @@
#include <chrono>

#include <QApplication>
#include <QTimer>
#include <QMessageBox>
#include <QTableView>
#include <QTimer>

using wallet::AddWallet;
using wallet::CWallet;
Expand Down Expand Up @@ -131,30 +133,35 @@ void TestAddAddressesToSendBook(interfaces::Node& node)
EditAddressDialog editAddressDialog(EditAddressDialog::NewSendingAddress);
editAddressDialog.setModel(walletModel.getAddressTableModel());

AddressBookPage address_book{platformStyle.get(), AddressBookPage::ForEditing, AddressBookPage::SendingTab};
address_book.setModel(walletModel.getAddressTableModel());
auto table_view = address_book.findChild<QTableView*>("tableView");
QCOMPARE(table_view->model()->rowCount(), 1);

EditAddressAndSubmit(
&editAddressDialog, QString("uhoh"), preexisting_r_address,
QString(
"Address \"%1\" already exists as a receiving address with label "
"\"%2\" and so cannot be added as a sending address."
).arg(preexisting_r_address).arg(r_label));

check_addbook_size(2);
QCOMPARE(table_view->model()->rowCount(), 1);

EditAddressAndSubmit(
&editAddressDialog, QString("uhoh, different"), preexisting_s_address,
QString(
"The entered address \"%1\" is already in the address book with "
"label \"%2\"."
).arg(preexisting_s_address).arg(s_label));

check_addbook_size(2);
QCOMPARE(table_view->model()->rowCount(), 1);

// Submit a new address which should add successfully - we expect the
// warning message to be blank.
EditAddressAndSubmit(
&editAddressDialog, QString("new"), new_address, QString(""));

check_addbook_size(3);
QCOMPARE(table_view->model()->rowCount(), 2);
}

} // namespace
Expand Down

0 comments on commit 1506913

Please sign in to comment.