mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 15:04:44 +01:00
test,gui: decouple widgets and model into a MiniGui struct
So it can be reused across tests.
This commit is contained in:
parent
2f76ac0383
commit
306aab5bb4
1 changed files with 31 additions and 12 deletions
|
@ -206,6 +206,32 @@ std::shared_ptr<CWallet> SetupDescriptorsWallet(interfaces::Node& node, TestChai
|
||||||
return wallet;
|
return wallet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct MiniGUI {
|
||||||
|
public:
|
||||||
|
SendCoinsDialog sendCoinsDialog;
|
||||||
|
TransactionView transactionView;
|
||||||
|
OptionsModel optionsModel;
|
||||||
|
std::unique_ptr<ClientModel> clientModel;
|
||||||
|
std::unique_ptr<WalletModel> walletModel;
|
||||||
|
|
||||||
|
MiniGUI(interfaces::Node& node, const PlatformStyle* platformStyle) : sendCoinsDialog(platformStyle), transactionView(platformStyle), optionsModel(node) {
|
||||||
|
bilingual_str error;
|
||||||
|
QVERIFY(optionsModel.Init(error));
|
||||||
|
clientModel = std::make_unique<ClientModel>(node, &optionsModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void initModelForWallet(interfaces::Node& node, const std::shared_ptr<CWallet>& wallet, const PlatformStyle* platformStyle)
|
||||||
|
{
|
||||||
|
WalletContext& context = *node.walletLoader().context();
|
||||||
|
AddWallet(context, wallet);
|
||||||
|
walletModel = std::make_unique<WalletModel>(interfaces::MakeWallet(context, wallet), *clientModel, platformStyle);
|
||||||
|
RemoveWallet(context, wallet, /* load_on_start= */ std::nullopt);
|
||||||
|
sendCoinsDialog.setModel(walletModel.get());
|
||||||
|
transactionView.setModel(walletModel.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
//! Simple qt wallet tests.
|
//! Simple qt wallet tests.
|
||||||
//
|
//
|
||||||
// Test widgets can be debugged interactively calling show() on them and
|
// Test widgets can be debugged interactively calling show() on them and
|
||||||
|
@ -223,18 +249,11 @@ void TestGUI(interfaces::Node& node, const std::shared_ptr<CWallet>& wallet)
|
||||||
{
|
{
|
||||||
// Create widgets for sending coins and listing transactions.
|
// Create widgets for sending coins and listing transactions.
|
||||||
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
|
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
|
||||||
SendCoinsDialog sendCoinsDialog(platformStyle.get());
|
MiniGUI mini_gui(node, platformStyle.get());
|
||||||
TransactionView transactionView(platformStyle.get());
|
mini_gui.initModelForWallet(node, wallet, platformStyle.get());
|
||||||
OptionsModel optionsModel(node);
|
WalletModel& walletModel = *mini_gui.walletModel;
|
||||||
bilingual_str error;
|
SendCoinsDialog& sendCoinsDialog = mini_gui.sendCoinsDialog;
|
||||||
QVERIFY(optionsModel.Init(error));
|
TransactionView& transactionView = mini_gui.transactionView;
|
||||||
ClientModel clientModel(node, &optionsModel);
|
|
||||||
WalletContext& context = *node.walletLoader().context();
|
|
||||||
AddWallet(context, wallet);
|
|
||||||
WalletModel walletModel(interfaces::MakeWallet(context, wallet), clientModel, platformStyle.get());
|
|
||||||
RemoveWallet(context, wallet, /* load_on_start= */ std::nullopt);
|
|
||||||
sendCoinsDialog.setModel(&walletModel);
|
|
||||||
transactionView.setModel(&walletModel);
|
|
||||||
|
|
||||||
// Update walletModel cached balance which will trigger an update for the 'labelBalance' QLabel.
|
// Update walletModel cached balance which will trigger an update for the 'labelBalance' QLabel.
|
||||||
walletModel.pollBalanceChanged();
|
walletModel.pollBalanceChanged();
|
||||||
|
|
Loading…
Add table
Reference in a new issue