- Live ticker: the paused live state carries both starting elevens; the ticker lists them until the first report. A single match no longer gets an empty strip above the score, repeated status lines are gone, whistles carry no club badge, dates are written out. - Desk: "Die letzten Spiele" and the table place curve are fed by the engine (desktop-widgets read: recent, rankCurve) and belong to the default layout; the own crest widget is bound. - News: the German press templates are rewritten to one plain sentence each (the catalogue accepts a single sentence now); the reference snapshots follow, and the catalogue test can rewrite them with --update. Mailbox texts show world spellings of clubs and players and the euro sign. - Small type raised in advertising, lineup, news, toto, transfer and others; the transfer market column no longer runs under its scrollbar. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
160 lines
6.5 KiB
C++
160 lines
6.5 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
#include "modern/ui/demo_widgets.hpp"
|
|
#include "modern/ui/desktop.hpp"
|
|
#include "modern/ui/model.hpp"
|
|
#include <chrono>
|
|
#include <iostream>
|
|
#include <set>
|
|
#include <stdexcept>
|
|
using namespace bmh::modern_ui;
|
|
namespace {
|
|
void require(bool yes, const char *why) {
|
|
if (!yes)
|
|
throw std::runtime_error(why);
|
|
}
|
|
struct Fixture {
|
|
fs::path root;
|
|
std::shared_ptr<const Catalog> world;
|
|
Fixture() {
|
|
root = fs::temp_directory_path() /
|
|
("openbmh-desktop-ui-" +
|
|
std::to_string(
|
|
std::chrono::steady_clock::now().time_since_epoch().count()));
|
|
fs::create_directories(root / "world");
|
|
const auto write = [&](const std::string &name, const Json &data) {
|
|
bmh::editor::write_atomic(root / name, data.dump());
|
|
};
|
|
write("manifest.json", {{"format", "openbmh-world"},
|
|
{"kind", "world"},
|
|
{"format_version", "1.1"},
|
|
{"id", "world:synthetic-desktop"},
|
|
{"start_date", "2032-07-01"},
|
|
{"requires", {"editor:world-v1"}},
|
|
{"x-editor", {{"profile", "editor-world-v1"}}}});
|
|
write("world/nations.json",
|
|
{{"items", {{{"id", "nation:de"}, {"name", "Synthetic nation"}}}}});
|
|
write("world/competitions.json", {{"items",
|
|
{{{"id", "competition:desktop-test"},
|
|
{"type", "league"},
|
|
{"nation", "nation:de"},
|
|
{"name", "Synthetic league"}}}}});
|
|
Json clubs = Json::array();
|
|
for (int i = 0; i < 2; ++i)
|
|
clubs.push_back({{"id", "club:desktop-" + std::to_string(i)},
|
|
{"name", "Synthetic Club " + std::to_string(i)},
|
|
{"nation", "nation:de"},
|
|
{"competition", "competition:desktop-test"}});
|
|
write("world/clubs.json", {{"items", clubs}});
|
|
write("world/players.json", {{"items", Json::array()}});
|
|
world = Catalog::open(root);
|
|
}
|
|
~Fixture() {
|
|
std::error_code ec;
|
|
fs::remove_all(root, ec);
|
|
}
|
|
};
|
|
void test(Fixture &f) {
|
|
DemoSource source(f.world);
|
|
const auto initial = source.snapshot();
|
|
auto layout = default_desktop();
|
|
require(valid_desktop(layout) && widget_definitions().size() == 17 &&
|
|
widget_catalogue().size() == 17,
|
|
"Widget catalogue incomplete");
|
|
int visible = 0;
|
|
for (const auto &[id, o] : layout.at("objects").items()) {
|
|
require(o.at("pinned") == true, "Standard must be fixed");
|
|
if (o.at("widget") == true && o.at("visible") == true)
|
|
++visible;
|
|
}
|
|
require(visible == 10 && desktop_routes().size() == 32,
|
|
"Default desktop counts wrong");
|
|
for (const auto &d : widget_catalogue()) {
|
|
bool found = false;
|
|
for (const auto &def : widget_definitions())
|
|
if (def.id == d.at("id").get<std::string>()) {
|
|
found = true;
|
|
require(def.sizes.size() == d.at("spans").size(),
|
|
"Widget size metadata mismatch");
|
|
}
|
|
require(found, "Unknown catalogue widget");
|
|
}
|
|
const auto projected = demo_desktop_widgets(*f.world, initial.state);
|
|
require(projected.at("warnings").size() == 10 &&
|
|
projected.at("own_curve").size() == 12 &&
|
|
projected.at("form").size() == 6,
|
|
"Widget projection incomplete");
|
|
require(source.snapshot().state == initial.state && !source.dirty(),
|
|
"Read-only widget data changed source");
|
|
auto altered = initial.state;
|
|
altered["cash"] = 0;
|
|
altered["finance"]["stocks"][0] = 1;
|
|
altered["contracts"]["players"] = Json::object();
|
|
auto warnings = demo_desktop_widgets(*f.world, altered).at("warnings");
|
|
require(warnings[0].at("attention") == true &&
|
|
warnings[1].at("attention") == true,
|
|
"Warnings do not reflect shared state");
|
|
const auto original = layout;
|
|
require(!resize_desktop_widget(layout, "account", 4, 1) && layout == original,
|
|
"Pinned widget resized");
|
|
require(!add_desktop_widget(layout, "calendar", 2, 2) && layout == original,
|
|
"Visible widget added twice");
|
|
require(!add_desktop_widget(layout, "fans", 8, 8) && layout == original,
|
|
"Unsupported size accepted");
|
|
require(set_desktop_grid(layout, false), "Free placement failed");
|
|
require(add_desktop_widget(layout, "fans", 2, 1) &&
|
|
!layout.at("objects").at("fans").at("pinned").get<bool>(),
|
|
"Optional widget not added movable");
|
|
require(layout.at("objects").at("fans").at("visible") == true,
|
|
"Added widget hidden");
|
|
require(arrange_desktop(layout) && layout.at("grid") == false,
|
|
"Arrange must preserve free/grid choice");
|
|
const auto before = layout;
|
|
require(set_desktop_grid(layout, true) && valid_desktop(layout),
|
|
"Snap mode failed");
|
|
for (const auto &[id, o] : original.at("objects").items())
|
|
if (o.at("visible") == true)
|
|
require(layout.at("objects").at(id) == o, "Snap moved a pinned object");
|
|
auto bad = layout;
|
|
bad["objects"]["fans"]["z"] = -1;
|
|
require(!valid_desktop(bad), "Invalid z order accepted");
|
|
auto changed = initial.state.at("settings");
|
|
changed["cells"][0] = 1 - changed["cells"][0].get<int>();
|
|
require(source.apply({initial.revision, "settings", changed}).ok,
|
|
"Cannot dirty source fixture");
|
|
const auto revision = source.snapshot().revision;
|
|
require(!source.mark_saved(revision - 1) && source.dirty(),
|
|
"Stale save acknowledgment cleared dirty state");
|
|
require(source.mark_saved(revision) && !source.dirty() &&
|
|
source.snapshot().revision == revision,
|
|
"Save acknowledgment changed revision");
|
|
const auto saved = f.root / "desktop.ui.json";
|
|
source.save(saved, layout);
|
|
auto data = Json::parse(bmh::editor::read_file(saved));
|
|
const auto restored = source.load_data(data);
|
|
require(restored == layout && !source.dirty(),
|
|
"In-memory load differs from file load");
|
|
const auto good = source.snapshot();
|
|
data["desktop"]["objects"]["calendar"]["x"] = -1;
|
|
bool rejected = false;
|
|
try {
|
|
source.load_data(data);
|
|
} catch (const std::exception &) {
|
|
rejected = true;
|
|
}
|
|
require(rejected && source.snapshot().state == good.state &&
|
|
source.snapshot().revision == good.revision,
|
|
"Failed in-memory load was not atomic");
|
|
}
|
|
} // namespace
|
|
int main() {
|
|
try {
|
|
Fixture f;
|
|
test(f);
|
|
std::cout << "modern desktop UI tests passed\n";
|
|
return 0;
|
|
} catch (const std::exception &e) {
|
|
std::cerr << e.what() << '\n';
|
|
return 1;
|
|
}
|
|
}
|