Populate native desktop status, fixture and news widgets from the session (by Codex)
This commit is contained in:
1 parent
fd5c2b5330
commit
dc911f3281
21 files changed
+419
-91
No files matched your search
@@ -0,0 +1,97 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace bmh::modern_ui;
|
||||
namespace {
|
||||
void check(bool v, const char *s) {
|
||||
if (!v)
|
||||
throw std::runtime_error(s);
|
||||
}
|
||||
template <class F> void rejects(F fn) {
|
||||
bool caught = false;
|
||||
try {
|
||||
fn();
|
||||
} catch (const std::exception &) {
|
||||
caught = true;
|
||||
}
|
||||
check(caught, "invalid desktop accepted");
|
||||
}
|
||||
} // namespace
|
||||
int main() try {
|
||||
const Json meta = {{"contractVersion", "bmh-modern-ui@draft1"},
|
||||
{"careerId", "career:test"},
|
||||
{"worldId", "world:test"},
|
||||
{"worldRevision", "1"},
|
||||
{"stateRevision", "4"},
|
||||
{"scope",
|
||||
{{"managerId", "manager:one"},
|
||||
{"teamId", "club:one"},
|
||||
{"role", "club"}}}};
|
||||
Json b;
|
||||
for (auto *kind : {"session", "desktop", "camps", "desktop-widgets"})
|
||||
b[kind] = {{"messageType", "snapshot"},
|
||||
{"meta", meta},
|
||||
{"data", {{"kind", kind}}}};
|
||||
auto &d = b["desktop"]["data"];
|
||||
d.update(
|
||||
{{"manager", {{"id", "manager:one"}}},
|
||||
{"team", {{"id", "club:one"}}},
|
||||
{"accounts",
|
||||
{{"cash", {{"currency", "EUR"}, {"minorUnits", 2}, {"minor", "0"}}}}},
|
||||
{"nextFixture", nullptr}});
|
||||
b["camps"]["data"]["camps"] = Json::array();
|
||||
auto &w = b["desktop-widgets"]["data"];
|
||||
w.update({{"own", {{"teamId", "club:one"}, {"rank", 2}, {"strength", 75}}},
|
||||
{"opponent", nullptr},
|
||||
{"warnings", Json::array({true, false, nullptr, false, false, true,
|
||||
false, false, false, true})},
|
||||
{"fanCount", 12000}});
|
||||
const auto original = b;
|
||||
auto p = engine_widgets_projection(b);
|
||||
check(b == original, "read projection changed input");
|
||||
check(p["warnings"].size() == 10 && p["warnings"][0]["attention"] == true &&
|
||||
p["warnings"][2]["attention"].is_null(),
|
||||
"known or unknown warnings lost");
|
||||
check(p["own"]["rank"] == 2 && p["own"]["strength"] == 75 &&
|
||||
p["opponent"].is_null(),
|
||||
"summary invented or lost");
|
||||
check(!p.contains("fans"), "fan count misrepresented as mood");
|
||||
w["opponent"] = {
|
||||
{"teamId", "club:two"}, {"rank", nullptr}, {"strength", nullptr}};
|
||||
rejects([&] { engine_widgets_projection(b); });
|
||||
d["nextFixture"] = {{"home", {{"id", "club:two"}}},
|
||||
{"away", {{"id", "club:one"}}},
|
||||
{"competition", {{"text", "Synthetic cup"}}}};
|
||||
p = engine_widgets_projection(b);
|
||||
check(p["fixture"]["home"]["id"] == "club:two" &&
|
||||
p["opponent"]["rank"].is_null(),
|
||||
"away order or unknown rank changed");
|
||||
auto bad = b;
|
||||
bad["desktop-widgets"]["meta"]["stateRevision"] = "5";
|
||||
rejects([&] { engine_widgets_projection(bad); });
|
||||
bad = b;
|
||||
bad["desktop-widgets"]["data"]["own"]["teamId"] = "other";
|
||||
rejects([&] { engine_widgets_projection(bad); });
|
||||
bad = b;
|
||||
bad["desktop-widgets"]["data"]["warnings"][0] = 1;
|
||||
rejects([&] { engine_widgets_projection(bad); });
|
||||
bad = b;
|
||||
bad["desktop-widgets"]["data"]["warnings"].erase(0);
|
||||
rejects([&] { engine_widgets_projection(bad); });
|
||||
bad = b;
|
||||
bad["desktop-widgets"]["data"]["opponent"]["teamId"] = "wrong";
|
||||
rejects([&] { engine_widgets_projection(bad); });
|
||||
bad = b;
|
||||
bad["desktop-widgets"]["data"]["own"]["rank"] = 0;
|
||||
rejects([&] { engine_widgets_projection(bad); });
|
||||
bad = b;
|
||||
bad["desktop-widgets"]["data"]["own"]["strength"] = 100;
|
||||
rejects([&] { engine_widgets_projection(bad); });
|
||||
std::cout << "desktop actual status, nulls, context, rival and away-order "
|
||||
"checks passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
Reference in new issue
Block a user