From ab8c7ec5ff3629cecef621f05708ed6c05cfe383 Mon Sep 17 00:00:00 2001 From: reionwong Date: Sat, 17 Oct 2026 09:01:53 +0800 Subject: [PATCH] fix(vpn): keep a removed WireGuard peer's card until its click is done --- src/pages/network/vpn/vpneditor.cpp | 5 +++- tests/ui/network_vpn_test.cpp | 38 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/pages/network/vpn/vpneditor.cpp b/src/pages/network/vpn/vpneditor.cpp index 0e2875b..490ed31 100644 --- a/src/pages/network/vpn/vpneditor.cpp +++ b/src/pages/network/vpn/vpneditor.cpp @@ -6,6 +6,7 @@ #include #include +#include "base/event_loop.h" #include "networkmanager/types.h" #include "pages/network/common/textchecks.h" #include "pages/network/common/rows.h" @@ -611,8 +612,10 @@ private: for (Label* label : {found->labels[0], found->labels[1], found->labels[2], found->labels[3], found->labels[4]}) std::erase(m_labels, label); m_peerCards.erase(found); - m_peers->takeChild(owner); + // The card holds the button being clicked. + std::shared_ptr gone = m_peers->takeChild(owner); update(); + cutefish::base::EventLoop::current()->post([gone] {}); }; card.publicKey = addField(card.card, "Public key", "Required"); card.publicKey->setText(peer.publicKey); diff --git a/tests/ui/network_vpn_test.cpp b/tests/ui/network_vpn_test.cpp index c4e75cf..9f003bd 100644 --- a/tests/ui/network_vpn_test.cpp +++ b/tests/ui/network_vpn_test.cpp @@ -3,12 +3,16 @@ #include +#include #include #include #include "networkmanager/handler.h" #include "networkmanager/vpnschema.h" #include "pages/network/vpn/vpneditor.h" +#include "ui/label.h" +#include "ui/test_input.h" +#include "ui/window.h" using namespace settings::network; namespace nm = cutefish::networkmanager; @@ -91,3 +95,37 @@ TEST(VpnEditor, WireGuardKeepsItsPeers) EXPECT_EQ(values.wireguard.peers[0].keepalive, "25"); EXPECT_TRUE(values.wireguard.peerRoutes); } + +TEST(VpnEditor, RemovingAWireGuardPeerKeepsTheOthers) +{ + nm::VpnForm form; + form.kind = "wireguard"; + form.installed = true; + form.wireguard.peers = {{.publicKey = "first"}, {.publicKey = "second"}}; + cutefish::ui::Window window; + auto content = std::make_unique(); + VpnEditor* editor = content.get(); + window.setContentView(std::move(content)); + window.resize({480, 1200}); + editor->load(form); + window.grab(); + + cutefish::ui::View* remove = nullptr; + const std::function findRemove = [&](cutefish::ui::View* view) { + auto* label = dynamic_cast(view); + if (!remove && label && label->text() == "Remove") + remove = view->parent(); + for (const auto& child : view->children()) + findRemove(child.get()); + }; + findRemove(editor); + ASSERT_NE(remove, nullptr); + // The button goes with the peer's card it sits in. + const cutefish::ui::PointF origin = remove->mapToWindow({0, 0}); + cutefish::ui::TestInput::click(window, {origin.x + remove->geometry().width / 2, + origin.y + remove->geometry().height / 2}); + + const nm::VpnValues values = editor->collect(); + ASSERT_EQ(values.wireguard.peers.size(), 1u); + EXPECT_EQ(values.wireguard.peers[0].publicKey, "second"); +}