feat(automation): pure UI node model + JSON serializer with unit test

This commit is contained in:
SoftFever
2026-06-03 01:28:43 +08:00
parent 11301086a7
commit 0be138b981
7 changed files with 212 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
#include <catch2/catch_all.hpp>
#include "slic3r/GUI/Automation/WidgetSerializer.hpp"
using namespace Slic3r::GUI::Automation;
TEST_CASE("node_to_json emits the unified node shape", "[automation][serializer]") {
UiNode n;
n.backend = BackendKind::Wx;
n.id = "btn_slice";
n.path = "MainFrame/Panel[2]/Button[0]";
n.klass = "Button";
n.label = "Slice plate";
n.rect = {100, 200, 120, 32};
n.enabled = true;
n.visible = true;
const nlohmann::json j = node_to_json(n, /*include_children*/ false);
CHECK(j.at("backend") == "wx");
CHECK(j.at("id") == "btn_slice");
CHECK(j.at("path") == "MainFrame/Panel[2]/Button[0]");
CHECK(j.at("class") == "Button");
CHECK(j.at("label") == "Slice plate");
CHECK(j.at("rect").at("x") == 100);
CHECK(j.at("rect").at("w") == 120);
CHECK(j.at("enabled") == true);
CHECK(j.at("visible") == true);
// `handle` must never leak into JSON.
CHECK_FALSE(j.contains("handle"));
// No value set -> no "value" key.
CHECK_FALSE(j.contains("value"));
}