Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions modern/tests/test_pos_flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <catch2/catch_test_macros.hpp>

#include "net/build_info.hh"
#include "net/stress.hh"
#include "layout_fixture.hh"
#include "layoutcontroller.hh"
#include "print/raster.hh"
Expand Down Expand Up @@ -2234,29 +2235,26 @@ TEST_CASE("UI: ring items in by number (keyboard, or Find)", "[flow][ui][plu]")
}
}

TEST_CASE("UI: no stress test, no page tour: the screen stays where it is", "[flow][ui][stress]")
TEST_CASE("UI: no stress test, no stress panel: the screen stays where it is", "[flow][ui]")
{
Screen s;
// The stress panel is always there (hidden); its tour of the pages must
// not run without a stress test, or a store's screen changes by itself.
// Hidden (no stress test), so looked for among hidden items too.
const std::function<QQuickItem *(QQuickItem *)> find = [&find](QQuickItem *root) -> QQuickItem * {
for (QQuickItem *item : root->childItems()) {
if (item->objectName() == u"stressPanel"_s)
return item;
if (QQuickItem *hit = find(item))
return hit;
}
return nullptr;
};
QQuickItem *panel = find(s.window->contentItem());
REQUIRE(panel);
QObject *tour = panel->findChild<QObject *>(u"stressPageTour"_s);
// A store's window never builds the stress panel (Main.qml loads it only
// for a stress test), so there is no tour of the pages to move its screen.
CHECK_FALSE(s.window->findChild<QObject *>(u"stressPanel"_s));
CHECK_FALSE(s.window->findChild<QObject *>(u"stressPageTour"_s));

// The control: a stress test on the window brings the panel, tour running,
// so the two names above are live rather than stale.
net::StressRunner stress(s.pos.shared(), nullptr, {}); // never started: just something to show
s.window->setProperty("stress", QVariant::fromValue(static_cast<QObject *>(&stress)));
QTest::qWait(20);
QObject *tour = s.window->findChild<QObject *>(u"stressPageTour"_s);
REQUIRE(tour);
CHECK_FALSE(tour->property("running").toBool());
const QString page = s.c.pageId();
QTest::qWait(200);
CHECK(s.c.pageId() == page);
REQUIRE(tour->inherits("QQmlTimer"));
CHECK(tour->property("running").toBool());
s.window->setProperty("stress", QVariant::fromValue(static_cast<QObject *>(nullptr))); // before `stress` dies
QTest::qWait(20); // the Loader deletes its item with deleteLater(); qWait flushes DeferredDelete
CHECK_FALSE(s.window->findChild<QObject *>(u"stressPanel"_s));
}

TEST_CASE("UI: the manager's dashboard: today so far", "[flow][ui][dashboard]")
Expand Down
14 changes: 9 additions & 5 deletions modern/ui/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1257,10 +1257,14 @@ ApplicationWindow {
function onNoticeChanged() { root.toast(root.editor.notice) }
}

StressPanel {
objectName: "stressPanel"
visible: root.stress !== null
stress: root.stress
controller: root.controller
// The stress test's numbers (vtmodern --stress). Only built then: a
// store's window has no panel, and no tour of the pages.
Loader {
anchors.fill: parent
z: 95
active: root.stress !== null
sourceComponent: Item {
StressPanel { stress: root.stress; controller: root.controller }
}
}
}
6 changes: 3 additions & 3 deletions modern/ui/qml/StressPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ Rectangle {
border.color: done ? (st.passed ? "#2fa35a" : "#d64545") : "#3a4250"
border.width: done ? 3 : 1

// Around the restaurant: a page every 15 seconds (only in a stress test:
// the panel is always there, hidden).
// Around the restaurant: a page every 15 seconds. (Main.qml builds this
// panel only during a stress test: a store's screen is never toured.)
Timer {
objectName: "stressPageTour"
readonly property var pages: ["tables", "seating", "kitchen", "expo", "dashboard", "deliveries"]
property int at: 0
interval: 15000
repeat: true
running: panel.stress !== null && panel.autoPages && !panel.done && panel.controller !== null
running: panel.autoPages && !panel.done && panel.controller !== null
onTriggered: { at = (at + 1) % pages.length; panel.controller.jumpTo(pages[at]) }
}

Expand Down
Loading