// test_stagec.cpp - Stage C demo/framework completions
#include "../tttest.hpp"
#include "../ttgui.hpp"
using namespace ttgui;
TEST_CASE("stagec: config dump covers focusFollowsMouse+wallpaperFg; example keys known", "[stagec][config]"){
Config c=Config::defaults(); std::string d=json::dump(c.toJson());
CHECK(d.find("focusFollowsMouse")!=std::string::npos); CHECK(d.find("wallpaperFg")!=std::string::npos);
CHECK(d.find("ttColors")!=std::string::npos);
}
TEST_CASE("stagec: bell rate-limit uses fake nowMs deterministically", "[stagec][bell]"){
Config cfg=Config::defaults(); cfg.bellAudible=false; cfg.bellVisualMs=150;
BellService b; b.cfg=&cfg; b.nowMs=0; b.ring("app"); int first=b.visualUntilMs;
b.nowMs=50; b.ring("app"); CHECK_EQ(b.visualUntilMs,first);
b.nowMs=150; b.ring("app"); CHECK(b.visualUntilMs>first);
}
TEST_CASE("stagec: MiniMap filters hide vegetation/industries", "[stagec][widget]"){
MiniMapWidget mm; mm.world={"T#~."}; mm.bounds={0,0,20,6}; mm.filters["vegetation"]=false; mm.filters["industries"]=false;
Canvas c(20,6); mm.draw(c); std::string t=c.text(); CHECK(t.find('T')==std::string::npos); CHECK(t.find('#')==std::string::npos);
MiniMapWidget mm2; mm2.world={"T#~."}; mm2.bounds={0,0,20,6}; Canvas c2(20,6); mm2.draw(c2); CHECK(c2.text().find('T')!=std::string::npos);
}
TEST_CASE("stagec: OSK bottom row emits modifiers not only space", "[stagec][widget]"){
OnScreenKeyboard osk; osk.bounds={0,0,60,6}; std::string got; osk.onKeyPress.connect([&](std::string k){ got=k; });
MouseEventData m; m.kind=MouseKind::Down; m.pos={1,4}; CHECK(osk.onMouse(m)); CHECK_EQ(got,std::string("Ctrl"));
}
TEST_CASE("stagec: TextEditor wordWrap wraps all visual lines", "[stagec][widget]"){
TextEditor ed; ed.showLineNumbers=false; ed.wordWrap=true; ed.bounds={0,0,14,5}; ed.setText("alpha beta gamma delta epsilon");
Canvas c(14,5); ed.draw(c); std::string t=c.text(); CHECK(t.find("gamma")!=std::string::npos); CHECK(t.find("epsilon")!=std::string::npos);
}
TEST_CASE("stagec: close veto blocks closeWindow until forceClose", "[stagec][wm]"){
WindowManager wm; auto* w=wm.createWindow("X","grey",{0,0,20,5}); w->onCloseRequest=[](){ return false; };
wm.closeWindow(w); CHECK_FALSE(w->closing); w->forceClose=true; wm.closeWindow(w); CHECK(w->closing); wm.processPendingCloses();
}
TEST_CASE("stagec: wide glyph width + diffRender does not orphan continuation", "[stagec][canvas]"){
CHECK_EQ(glyphDisplayWidth("\xE4\xB8\xAD"),2); CHECK_EQ(glyphDisplayWidth("A"),1);
Canvas a(6,1), b(6,1); a.set(0,0,"\xE4\xB8\xAD",CellStyle{}); std::string out=diffRender(a,b); CHECK(out.find("\xE4\xB8\xAD")!=std::string::npos);
}
TEST_CASE("stagec: capture phase hook fires and can consume", "[stagec][events]"){
struct Cap : Widget{ bool onCapture(Event&) override { return true; } };
Application app(Config::defaults()); auto* w=app.wm.createWindow("C","grey",{0,0,30,8}); auto* cap=new Cap(); cap->bounds={0,0,10,3}; w->setContent(std::unique_ptr<Widget>(cap)); w->layout();
Event e=Event::makeMouse(MouseKind::Down,{2,2}); app.dispatch(e); CHECK(e.handled);
}