// Tear-off by holding the drag on the window edge (SPEC FR-73, A-02): terminals clamp a drag that leaves the window to the edge cell and
// then send no more motion, so the UI also tears the chat off when the pointer has stayed on the edge for tearoff.edge_hold_ms.
#include "rig.hpp"
using namespace uitest;
namespace {
const char* kTerm = "\"terminal\":{\"command\":\"@TMP@/term.sh {cmd}\"}";
/// Drags chat row 1 to the left window edge and stays there (no release).
void dragToEdgeAndHold(Rig& r) {
ttgui::Rect a = r.app.shell().list->absoluteBounds();
ttgui::Point start{a.x + 4, a.y + 2};
r.mouse(ttgui::MouseKind::Down, start.x, start.y);
for (int x = start.x; x > 0; x -= 6) r.mouse(ttgui::MouseKind::Drag, x, start.y);
r.mouse(ttgui::MouseKind::Drag, 0, start.y);
}
/// The UI loop advances the clock and runs the tick handler; headless tests do the same by hand.
void tick(Rig& r, long long ms) {
r.app.app().tickMs += ms;
r.app.app().onTickExtra();
}
} // namespace
TEST_CASE("holding a dragged chat row on the edge tears it off after the hold time, without a release", "[ui][tearoff][integration]") {
Rig r(120, 34, std::string(kTerm));
std::string o = r.tmp.path + "/argv.txt";
r.fakeTerminal(o);
dragToEdgeAndHold(r);
tick(r, 200);
::usleep(150000);
CHECK(!std::filesystem::exists(o)); // held for 200 ms of 600: not yet
tick(r, 500);
REQUIRE(Rig::waitForFile(o));
CHECK(has(Rig::readFile(o), "--chat user:"));
}
TEST_CASE("the hold only counts on the edge: leaving it, or releasing in the middle, tears nothing off", "[ui][tearoff][integration]") {
Rig r(120, 34, std::string(kTerm));
std::string o = r.tmp.path + "/argv.txt";
r.fakeTerminal(o);
dragToEdgeAndHold(r);
tick(r, 400);
r.mouse(ttgui::MouseKind::Drag, 60, 10); // moved away from the edge: the hold starts over
tick(r, 400);
tick(r, 400);
::usleep(150000);
CHECK(!std::filesystem::exists(o));
r.mouse(ttgui::MouseKind::Up, 60, 10);
::usleep(150000);
CHECK(!std::filesystem::exists(o));
}
TEST_CASE("after a hold tear-off the release does not open a second window; edge_hold_ms 0 keeps only release at the edge", "[ui][tearoff][integration]") {
{
Rig r(120, 34, std::string(kTerm));
std::string o = r.tmp.path + "/argv.txt";
r.fakeTerminal(o);
dragToEdgeAndHold(r);
tick(r, 700);
REQUIRE(Rig::waitForFile(o));
std::filesystem::remove(o);
r.mouse(ttgui::MouseKind::Up, 0, 4);
::usleep(200000);
CHECK(!std::filesystem::exists(o)); // one gesture, one window
}
{
Rig r(120, 34, std::string(kTerm) + ",\"tearoff\":{\"edge_hold_ms\":0}");
std::string o = r.tmp.path + "/argv.txt";
r.fakeTerminal(o);
dragToEdgeAndHold(r);
tick(r, 5000);
::usleep(150000);
CHECK(!std::filesystem::exists(o)); // the hold gesture is switched off
r.mouse(ttgui::MouseKind::Up, 0, 4);
REQUIRE(Rig::waitForFile(o)); // release at the edge still works
}
}