Port statistics and the news tablet to the Modern UI (by Codex)

This commit is contained in:
Codex committed 2026-10-25 20:10:57 +01:00
1 parent 349c416f3a
commit a45217c362
32 files changed
+2493 -23

No files matched your search

+37 -1
View File
@@ -80,6 +80,15 @@ void centered_text(Rml::Element &text_root, Rml::Element &control,
text_centers(text_root, p.x + s.x / 2, p.y + s.y / 2, horizontal, lines);
require(lines == 1, "A control label disappeared or wrapped");
}
size_t visible_text_lines(Rml::Element &node) {
size_t count = 0;
if (auto *text = dynamic_cast<Rml::ElementText *>(&node))
for (const auto &line : text->GetLines())
if (!line.text.empty() && line.width > 0) ++count;
for (int i = 0; i < node.GetNumChildren(); ++i)
count += visible_text_lines(*node.GetChild(i));
return count;
}
} // namespace
int main(int argc, char **argv) try {
require(argc == 2, "Pass the Modern asset directory");
@@ -97,10 +106,14 @@ int main(int argc, char **argv) try {
Rml::Style::FontStyle::Normal,
Rml::Style::FontWeight::Bold),
"Bold font missing");
require(Rml::LoadFontFace((root / "LatoLatin-BoldItalic.ttf").string(), "Modern",
Rml::Style::FontStyle::Italic,
Rml::Style::FontWeight::Bold),
"Bold italic font missing");
std::ostringstream css;
for (const auto *name : {"theme.rcss", "ticket.rcss", "sports.rcss",
"calendar.rcss", "reports.rcss", "report_details.rcss",
"report_pickers.rcss", "indoor.rcss", "planning.rcss", "almanac.rcss", "finance.rcss", "bank.rcss", "contracts.rcss", "amount.rcss", "environment.rcss", "advertising.rcss", "toto.rcss", "lineup.rcss", "transfer.rcss", "career_reports.rcss", "rankings.rcss", "stadium.rcss"}) {
"report_pickers.rcss", "indoor.rcss", "planning.rcss", "almanac.rcss", "finance.rcss", "bank.rcss", "contracts.rcss", "amount.rcss", "environment.rcss", "advertising.rcss", "toto.rcss", "lineup.rcss", "transfer.rcss", "career_reports.rcss", "rankings.rcss", "stadium.rcss", "statistics.rcss", "news.rcss"}) {
std::ifstream input(root / name);
require(bool(input), "Production stylesheet missing");
css << input.rdbuf() << '\n';
@@ -138,6 +151,24 @@ int main(int argc, char **argv) try {
"id='rich' "
"style='position:absolute;left:700dp;top:40dp;width:250dp;height:"
"260dp;' ");
content +=
"<div style='position:absolute;left:1200dp;top:40dp;width:1294dp;height:94dp;'>" +
button_markup("statistics-absolute", "<span id='stats-scale-label' class='statistics-cell-text'>REL.</span>",
"statistics-action statistics-absolute", "style='left:0;top:0;width:100%;height:94dp;'") + "</div>" +
"<div class='statistics-cell statistics-col-0' style='position:absolute;left:1200dp;top:160dp;width:1000dp;height:80dp;'>" +
button_markup("player-detail", "<span id='stats-player-label' class='statistics-cell-text'>Synthetic player</span>",
"statistics-player-link") + "</div>" +
"<div class='statistics-cell statistics-col-0' style='position:absolute;left:1200dp;top:260dp;width:1000dp;height:80dp;'>" +
button_markup("statistics-trophy", "<span class='statistics-world-trophy-art'></span><span id='stats-world-label' class='statistics-cell-text'>WM 2098</span>",
"statistics-world-trophy") + "</div>" +
"<div style='position:absolute;left:2300dp;top:160dp;width:1000dp;height:80dp;'>" +
button_markup("club-detail", "<span id='stats-from-label' class='report-club-name'>Synthetic source club</span><span style='width:42dp;height:42dp;'></span>",
"report-club-button statistics-club name-first") + "</div>" +
"<span id='news-brand-test' class='news-wordmark' style='position:absolute;left:2700dp;top:280dp;'>kicker</span>" +
"<div class='statistics-trophy-winner' style='left:2700dp;top:430dp;width:900dp;height:100dp;font-size:70dp;'>" +
"<div class='image-frame' style='width:100dp;height:100dp;'></div><span id='stats-winner-label'>Sample winner</span></div>" +
button_markup("statistics-curve", "<span class='statistics-series-dot'></span><span id='stats-legend-label' class='statistics-series-label'>Mannschaftsstärke</span>",
"statistics-action statistics-series-button", "style='left:2700dp;top:580dp;width:836dp;height:82dp;'");
content +=
"<div "
"style='position:absolute;left:40dp;top:400dp;width:2608dp;height:"
@@ -165,6 +196,11 @@ int main(int argc, char **argv) try {
context->Render();
}
require(!center_selects(*doc), "Control centering does not settle");
for (const auto *id : {"stats-scale-label", "stats-legend-label", "stats-player-label", "stats-world-label", "stats-from-label", "stats-winner-label", "news-brand-test"}) {
auto *label = doc->GetElementById(id);
require(label && label->GetBox().GetSize(Rml::BoxArea::Content).x > 0 && visible_text_lines(*label) > 0,
"A production statistics/news label has collapsed or lost its font face");
}
for (const auto *id : {"step", "region", "footer"}) {
auto *button = doc->GetElementById(id);
require(button, "Button missing");
+304
View File
@@ -0,0 +1,304 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/ui/demo_news.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-news-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-news"},
{"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:news-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:news-" + std::to_string(i)},
{"name", "Synthetic Club " + std::to_string(i)},
{"nation", "nation:de"},
{"competition", "competition:news-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);
}
};
Json state() {
return {
{"date", "2032-03-01"},
{"managers", {{{"name", "Synthetic Manager"}, {"club", "club:news-0"}}}},
{"cash", 123456},
{"other", {{"kept", true}}}};
}
void reject(Json &s, const Json &a, const Catalog &w) {
const auto before = s;
require(!edit_demo_news(s, a, w).empty() && s == before,
"Rejected news action altered state");
}
void provider(Fixture &f) {
auto s = state();
const auto unrelated = s, clubs = f.world->rows("clubs");
require(migrate_demo_news(s, *f.world) && valid_demo_news(s),
"Old checkpoint migration failed");
const auto initial = s;
require(migrate_demo_news(s, *f.world) && s == initial,
"Existing mailbox was reinitialized");
auto rest = s;
rest.erase("news");
require(rest == unrelated, "News migration changed unrelated fields");
const auto view = demo_news_view(*f.world, s);
require(view.at("items").size() == 9 && view.at("counts").at("inbox") == 9 &&
view.at("counts").at("archive") == 3 && view.at("unread") == 5,
"Initial mailbox counts wrong");
require(view.at("date") == "01.03.2032" &&
s.at("news").at("items")[2].at("date") == "2032-02-29" &&
s.at("news").at("items")[11].at("date") == "2032-02-18",
"Relative fixture dates or leap day wrong");
require(view.at("items")[0].at("body").get<std::string>().find(
"Synthetic Manager. Synthetic Club 0") != std::string::npos,
"Current manager and club not interpolated");
auto changed = s;
changed["managers"][0] = {{"name", "Other Manager"}, {"club", "club:news-1"}};
require(demo_news_view(*f.world, changed)
.at("items")[0]
.at("body")
.get<std::string>()
.find("Other Manager. Synthetic Club 1") != std::string::npos,
"Manager change retained stale template identity");
require(demo_news_view(*f.world, s, "inbox", "FINANZEN").at("items").size() ==
2 &&
demo_news_view(*f.world, s, "inbox", "VERTRAGSGESPRÄCHE")
.at("items")
.size() == 1,
"German case-insensitive category/title search failed");
require(demo_news_view(*f.world, s, "inbox", "unmatchable-search")
.at("items")
.empty() &&
demo_news_view(*f.world, s, "inbox", "01.03.2032")
.at("items")
.size() == 2,
"Search empty/date projection failed");
require(s == initial && f.world->rows("clubs") == clubs,
"Read-only projection mutated state or catalogue");
require(
edit_demo_news(s, {{"kind", "read-all"}, {"folder", "inbox"}}, *f.world)
.empty() &&
demo_news_unread(s) == 0,
"Read-all must mark the entire folder, including hidden results");
s = initial;
require(edit_demo_news(s, {{"kind", "read"}, {"id", "season"}}, *f.world)
.empty() &&
demo_news_unread(s) == 4,
"Open read action failed");
s = initial;
require(edit_demo_news(
s, {{"kind", "move"}, {"id", "season"}, {"folder", "archive"}},
*f.world)
.empty() &&
demo_news_unread(s) == 4,
"Archive must also mark read");
const Json patch =
Json::array({{{"id", "season"},
{"before", {{"read", false}, {"folder", "inbox"}}},
{"after", {{"read", true}, {"folder", "archive"}}}}});
const auto archived = s;
require(edit_demo_news(s, {{"kind", "undo"}, {"patch", patch}}, *f.world)
.empty() &&
s == initial,
"Undo failed to restore the small read/folder patch");
reject(s, {{"kind", "undo"}, {"patch", patch}}, *f.world);
s = archived;
require(edit_demo_news(
s, {{"kind", "move"}, {"id", "season"}, {"folder", "inbox"}},
*f.world)
.empty() &&
s.at("news").at("items")[0].at("read") == true,
"Restore must retain read state");
require(edit_demo_news(
s, {{"kind", "move"}, {"id", "season"}, {"folder", "trash"}},
*f.world)
.empty() &&
demo_news_view(*f.world, s).at("counts").at("inbox") == 8,
"Delete did not remove item from visible folders");
reject(s, {{"kind", "read"}, {"id", "season"}}, *f.world);
s = archived;
auto multi = patch;
multi.push_back({{"id", "missing"},
{"before", {{"read", false}, {"folder", "inbox"}}},
{"after", {{"read", true}, {"folder", "inbox"}}}});
reject(s, {{"kind", "undo"}, {"patch", multi}}, *f.world);
multi = patch;
multi.push_back(patch[0]);
reject(s, {{"kind", "undo"}, {"patch", multi}}, *f.world);
for (const auto &a : std::vector<Json>{
nullptr, Json::array(), Json{{"kind", 4}},
Json{{"kind", "move"}, {"id", "season"}, {"folder", "lost"}},
Json{{"kind", "read"}, {"id", 4}},
Json{{"kind", "read"}, {"id", "season"}, {"unexpected", true}},
Json{{"kind", "read-all"}, {"folder", "trash"}},
Json{{"kind", "undo"}, {"patch", Json::array()}},
Json{{"kind", "unknown"}}})
reject(s, a, *f.world);
std::vector<Json> bad;
auto invalid = initial;
invalid["news"]["items"].push_back(invalid["news"]["items"][0]);
bad.push_back(invalid);
for (const auto &[key, value] : std::vector<std::pair<std::string, Json>>{
{"id", "BAD-ID"},
{"id", ""},
{"date", "2031-02-29"},
{"date", "2032-13-01"},
{"kind", 4},
{"kind", "unsupported"},
{"title", " "},
{"title", std::string(161, 'x')},
{"body", std::string(1201, 'x')},
{"read", 1},
{"folder", "removed"}}) {
invalid = initial;
invalid["news"]["items"][0][key] = value;
bad.push_back(invalid);
}
invalid = initial;
invalid["news"]["version"] = 1.0;
bad.push_back(invalid);
invalid = initial;
invalid["news"]["query"] = "must-be-local";
bad.push_back(invalid);
invalid = initial;
for (int i = 12; i < 101; ++i) {
auto m = invalid["news"]["items"][0];
m["id"] = "test-" + std::to_string(i);
invalid["news"]["items"].push_back(m);
}
bad.push_back(invalid);
for (auto invalid : bad) {
const auto before = invalid;
require(!valid_demo_news(invalid) &&
!migrate_demo_news(invalid, *f.world) && invalid == before,
"Malformed imported mailbox was repaired or accepted");
reject(invalid, {{"kind", "read-all"}, {"folder", "inbox"}}, *f.world);
}
auto empty = initial;
empty["news"]["items"] = Json::array();
require(valid_demo_news(empty) &&
demo_news_view(*f.world, empty).at("items").empty() &&
demo_news_unread(empty) == 0,
"Valid empty mailbox rejected");
}
void source(Fixture &f) {
DemoSource source(f.world);
auto initial = source.snapshot();
require(valid_demo_news(initial.state) && !source.dirty(),
"Default source mailbox missing or dirty");
const auto clean = initial.state;
demo_news_view(*f.world, initial.state, "archive", "search");
require(source.snapshot().revision == initial.revision && !source.dirty(),
"Navigation dirtied source");
require(
source
.apply(
{initial.revision, "news", {{"kind", "read"}, {"id", "season"}}})
.ok,
"Source rejected news action");
auto current = source.snapshot();
require(source.dirty() && current.revision == initial.revision + 1,
"News action did not advance source revision");
require(
!source.apply({initial.revision,
"news",
{{"kind", "move"}, {"id", "season"}, {"folder", "trash"}}})
.ok &&
source.snapshot().state == current.state,
"Stale news action changed source");
require(!source.apply({current.revision,
"news",
{{"kind", "move"}, {"id", "season"}, {"folder", 9}}})
.ok &&
source.snapshot().state == current.state &&
source.snapshot().revision == current.revision,
"Malformed source action was not atomic");
const auto save = f.root / "checkpoint.json";
source.save(save, default_desktop());
require(!source.dirty(), "Saving news did not clear dirty");
require(
source
.apply({source.snapshot().revision,
"news",
{{"kind", "move"}, {"id", "season"}, {"folder", "trash"}}})
.ok,
"Delete source action failed");
source.load(save);
require(source.snapshot().state.at("news") == current.state.at("news") &&
!source.dirty(),
"Saved mailbox did not reload");
auto data = Json::parse(bmh::editor::read_file(save));
data.erase("news");
bmh::editor::write_atomic(save, data.dump());
source.load(save);
require(valid_demo_news(source.snapshot().state) &&
demo_news_unread(source.snapshot().state) == 5 && !source.dirty(),
"Old checkpoint did not initialize clean news");
source.save(save, default_desktop());
data = Json::parse(bmh::editor::read_file(save));
data["news"]["items"][0]["kind"] = 44;
bmh::editor::write_atomic(save, data.dump());
const auto before = source.snapshot();
bool rejected = false;
try {
source.load(save);
} catch (const std::exception &) {
rejected = true;
}
require(rejected && source.snapshot().state == before.state &&
source.snapshot().revision == before.revision && !source.dirty(),
"Malformed checkpoint replaced state or advanced revision");
auto rest = before.state;
rest.erase("news");
auto base = clean;
base.erase("news");
require(rest == base, "Mailbox actions modified unrelated presentation data");
}
} // namespace
int main() {
try {
Fixture f;
provider(f);
source(f);
std::cout << "modern news UI tests passed\n";
return 0;
} catch (const std::exception &e) {
std::cerr << e.what() << '\n';
return 1;
}
}
+140
View File
@@ -0,0 +1,140 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/ui/demo_statistics.hpp"
#include "modern/ui/model.hpp"
#include <array>
#include <chrono>
#include <iostream>
#include <set>
#include <stdexcept>
using namespace bmh::modern_ui;
namespace {
void require(bool value,const char *message) {if(!value)throw std::runtime_error(message);}
const std::array<std::string,8> nations{"de","es","en","fr","it","nl","pt","be"};
std::string club(const std::string &country,int index) {return "club:statistics-"+country+"-"+std::to_string(index);}
struct Fixture {
fs::path root;std::shared_ptr<const Catalog> world;
explicit Fixture(bool empty=false, bool english_subnation=false) {
root=fs::temp_directory_path()/("openbmh-statistics-ui-"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
fs::create_directories(root/"world");
const auto write=[&](const std::string &file,const Json &value){bmh::editor::write_atomic(root/file,value.dump());};
write("manifest.json",{{"format","openbmh-world"},{"kind","world"},{"format_version","1.1"},{"id","world:synthetic-statistics"},{"start_date","2026-07-01"},{"requires",{"editor:world-v1"}},{"x-editor",{{"profile","editor-world-v1"}}}});
Json ns=Json::array(),leagues=Json::array(),clubs=Json::array(),players=Json::array();
if(!empty)for(size_t n=0;n<nations.size();++n) {
const auto &code=nations[n];
const auto nation_id = code == "en" && english_subnation ? "nation:x-eng" : "nation:" + code;
ns.push_back({{"id",nation_id},{"name","Synthetic nation "+code}});
if(n>=5)continue;
const auto league="competition:statistics-"+code;
leagues.push_back({{"id",league},{"type","league"},{"nation",nation_id},{"tier",1},{"name","Synthetic league "+code}});
leagues.push_back({{"id",league+"-lower"},{"type","league"},{"nation",nation_id},{"tier",2},{"name","Synthetic lower league "+code}});
for(int i=0;i<20;++i) {
const auto id=club(code,i);
clubs.push_back({{"id",id},{"name","Synthetic club "+code+" "+std::to_string(i)},{"competition",league},{"nation",nation_id},{"crest","asset:synthetic-crest"}});
for(int p=0;p<12;++p)players.push_back({{"id","player:statistics-"+code+"-"+std::to_string(i)+"-"+std::to_string(p)},{"name","Synthetic player "+std::to_string(i*12+p)},{"team",id},{"nation",nation_id},{"positions",{p==0?"gk":"mid"}}});
}
clubs.push_back({{"id",club(code,20)},{"name","Synthetic lower club"},{"competition",league+"-lower"},{"nation",nation_id}});
}
write("world/nations.json",{{"items",ns}});write("world/competitions.json",{{"items",leagues}});write("world/clubs.json",{{"items",clubs}});write("world/players.json",{{"items",players}});
world=Catalog::open(root);
}
~Fixture(){std::error_code ec;fs::remove_all(root,ec);}
};
Json state() {return {{"date","2027-07-07"},{"managers",{{{"name","Synthetic manager"},{"club",club("de",4)}}}},{"cash",123456},{"reports",{{"league","competition:statistics-es"},{"filter",4}}}};}
void identities(const Catalog &world,const Json &data) {
for(const auto &r:data.at("rows"))for(const auto &c:r.at("cells")) {
if(c.contains("club"))require(world.find("clubs",c.at("club").get<std::string>()),"Statistics contains an unknown club identity");
if(c.contains("player"))require(world.find("players",c.at("player").get<std::string>()),"Statistics contains an unknown player identity");
if(c.contains("nation"))require(world.find("nations",c.at("nation").get<std::string>()),"Statistics contains an unknown nation identity");
}
}
void projections() {
Fixture f;const auto s=state(),before=s,clubs=f.world->rows("clubs"),players=f.world->rows("players");
const auto initial=demo_statistics(*f.world,s);
require(initial.at("ok")==true&&initial.at("fictional")==true&&initial.at("section")==7&&initial.at("category")==0&&initial.at("winner_country")=="nation:de","Default must open national German winners");
require(initial.at("rows").size()==12&&initial.at("columns").size()==4,"National winners lost their three title columns or twelve seasons");
require(initial.at("rows")[0].at("cells")[0].at("text")=="2026/27"&&initial.at("rows")[11].at("cells")[0].at("text")=="2015/16","Winners must end with last completed season");
require(initial.at("manager")=="Synthetic manager"&&initial.at("club")==club("de",4),"Statistics has stale own-manager identity");
const std::array<std::string,5> winner_order{"de","es","it","fr","en"};
for(size_t i=0;i<winner_order.size();++i)require(initial.at("countries")[i].at("id")=="nation:"+winner_order[i],"Winner-country order differs from Gold");
for(int section=0;section<9;++section) {
const auto data=demo_statistics(*f.world,s,{{"section",section}});
require(data.at("ok")==true&&data.at("title")==data.at("sections")[size_t(section)],"A statistics section is unavailable or mislabeled");
identities(*f.world,data);
if(section==1)require(data.at("rows").size()==10,"Transfer history must show ten distinct actual players when available");
}
for(int country=0;country<5;++country) {
const auto data=demo_statistics(*f.world,s,{{"section",3},{"country",country}});
const std::array<std::string,5> order{"de","es","en","fr","it"};
require(data.at("rows").size()==20,"Eternal table silently lost twentieth team or mixed lower leagues");
require(data.at("rows")[0].at("cells")[0].at("club")==club(order[size_t(country)],0),"Eternal country selector uses wrong nation cohort");
require(data.at("rows")[19].at("cells")[0].at("club")==club(order[size_t(country)],19),"Eternal table truncated final actual club");
identities(*f.world,data);
}
require(demo_statistics(*f.world,s,{{"section",3},{"country",5}}).at("rows").size()==20,"Absolute eternal table lost own-league cohort");
for(const auto &nation:initial.at("countries")) {
const auto id=nation.at("id").get<std::string>();const auto code=id.substr(7);
const auto data=demo_statistics(*f.world,s,{{"winner_country",id}});
require(data.at("rows")[0].at("cells")[1].at("club")==club(code,0)&&data.at("rows")[0].at("cells")[3].at("club")==club(code,1),"National winners must use selected country's actual clubs");
require(data.at("columns")[1].at("winner")==data.at("rows")[0].at("cells")[1].at("club"),"Trophy detail winner differs from latest visible winner");
identities(*f.world,data);
}
const auto international=demo_statistics(*f.world,s,{{"category",1}}),indoor=demo_statistics(*f.world,s,{{"category",5}});
require(international.at("columns").size()==4&&international.at("columns")[2].at("text")=="Pokalsieger"&&international.at("columns")[3].at("text")=="UEFA-Cup","International competition structure differs from BMH Gold");
require(indoor.at("columns").size()==3&&indoor.at("rows")[0].at("cells").size()==3&&indoor.at("columns")[1].at("text")=="Sieger"&&indoor.at("columns")[2].at("text")=="Finalist","Indoor winners need exactly two title columns");
identities(*f.world,international);identities(*f.world,indoor);
for(int view=0;view<6;++view) {
const auto data=demo_statistics(*f.world,s,{{"section",4},{"country",view}});identities(*f.world,data);
const size_t expected=view==0||view==5?6:view==3?4:8;
require(data.at("rows").size()==expected,"A world-statistics subview is missing");
if(view==3)require(data.at("columns")[0].at("round")=="Runde"&&data.at("rows")[0].at("cells")[0].at("round")=="Finale"&&!data.at("rows")[0].at("cells")[0].contains("prefix"),"World final-round metadata was flattened into the team label");
}
const auto relative=demo_statistics(*f.world,s,{{"section",2}}),absolute=demo_statistics(*f.world,s,{{"section",2},{"absolute",true},{"curves",{false,true,false,true,false,true}}});
require(relative.at("series").size()==6&&relative.at("series")[0].at("points").size()==24,"Analytics needs six 24-point curves");
require(relative.at("series")[0].at("points")!=absolute.at("series")[0].at("points")&&absolute.at("series")[0].at("active")==false&&absolute.at("series")[1].at("active")==true,"Curve toggles or relative/absolute data do not work");
const auto minutes=demo_statistics(*f.world,s,{{"section",8}});
require(minutes.at("columns").size()==19&&minutes.at("rows").size()==4&&minutes.at("rows")[0].at("cells")[1].at("tone")=="bad"&&minutes.at("rows")[0].at("cells")[4].at("tone")=="good","Minute grid must retain eighteen intervals and meaningful colors");
auto changed=s;changed["cash"]=0;changed["reports"]={{"league","elsewhere"}};
require(demo_statistics(*f.world,changed)==initial,"Statistics depends on unrelated wallet or report filters");
changed=s;changed["managers"][0]["name"]="Changed manager";changed["managers"][0]["club"]=club("de",7);
require(demo_statistics(*f.world,changed).at("manager")=="Changed manager"&&demo_statistics(*f.world,changed).at("club")==club("de",7),"Statistics retains stale manager after switch");
changed=s;changed["date"]="2027-06-30";
require(demo_statistics(*f.world,changed).at("rows")[0].at("cells")[0].at("text")=="2025/26","June date falsely completed current season");
require(s==before&&f.world->rows("clubs")==clubs&&f.world->rows("players")==players&&demo_statistics(*f.world,s)==initial,"Read projection changed input/catalogue or became nondeterministic");
// This boundary check also proves all UI filters remain outside saved state.
DemoSource source(f.world);const auto snapshot=source.snapshot();const bool dirty=source.dirty();
for(int section=0;section<9;++section)require(source.read_statistics({{"section",section}}).at("ok")==true,"Data-source read boundary does not expose statistics");
require(source.snapshot().revision==snapshot.revision&&source.snapshot().state==snapshot.state&&source.dirty()==dirty,"Statistics reads changed checkpoint state, revision or dirty flag");
}
void invalid_and_empty() {
Fixture f;
for(const auto &request:std::vector<Json>{nullptr,Json::array(),Json{{"section",-1}},Json{{"section",9}},Json{{"section","7"}},Json{{"category",2}},Json{{"country",6}},Json{{"winner_country","nation:missing"}},Json{{"winner_country",0}},Json{{"absolute",1}},Json{{"curves",{true,false}}},Json{{"curves",{true,true,true,true,true,1}}},Json{{"page",1}}})require(demo_statistics(*f.world,state(),request).at("ok")==false,"Malformed statistics filter was accepted");
Fixture empty(true);for(int section=0;section<9;++section) {
const auto data=demo_statistics(*empty.world,Json::object(),{{"section",section}});
require(data.at("ok")==true&&data.at("available")==false&&data.at("rows").empty()&&data.at("series").empty()&&data.at("club").is_null(),"Empty world fabricated statistics identities or rows");
}
for(const auto &s:std::vector<Json>{nullptr,Json::array(),Json::object(),Json{{"managers",Json::array()}},Json{{"managers",{{{"club","club:missing"}}}}}}) {
const auto data=demo_statistics(*f.world,s);require(data.at("ok")==true&&data.at("club").is_null(),"Malformed manager snapshot threw or invented own identity");
}
}
void english_subnation() {
Fixture f(false, true);
const auto initial = demo_statistics(*f.world, state());
require(initial.at("countries").size() == 5 && initial.at("countries")[4].at("id") == "nation:x-eng",
"Stable England identity disappeared from the country picker");
require(initial.at("eternal_countries").size() == 6 && initial.at("eternal_countries")[2].at("nation") == "nation:x-eng",
"Eternal table omitted England or changed its Gold index");
const auto eternal = demo_statistics(*f.world, state(), {{"section",3},{"country",2}});
require(eternal.at("rows").size() == 20 && eternal.at("rows")[19].at("cells")[0].at("club") == club("en",19),
"England's twentieth club is absent from its eternal table");
const auto winner = demo_statistics(*f.world, state(), {{"winner_country","nation:x-eng"}});
require(winner.at("columns")[1].at("text") == "Premier League" && winner.at("columns")[2].at("text") == "FA Cup" &&
winner.at("columns")[1].at("trophy") == "en-premier-league",
"England incorrectly uses German title or trophy names");
const auto world = demo_statistics(*f.world, state(), {{"section",4},{"country",1}});
require(world.at("rows")[4].at("cells")[1].at("nation") == "nation:x-eng",
"World statistics replaced England with an unrelated country");
require(!f.world->find("nations","nation:en"), "Projection changed stable nation IDs");
}
} // namespace
int main()try{projections();invalid_and_empty();english_subnation();std::cout<<"Modern statistics UI checks passed\n";return 0;}catch(const std::exception &error){std::cerr<<error.what()<<'\n';return 1;}