Dotfiles_ArchAP/tests/session_v2/qml/tst_exit_v2.qml

66 lines
3.2 KiB
QML

import QtQuick
import QtTest
TestCase {
name: "SessionExitGateV2"
function gate() {
const component = Qt.createComponent("../../../quickshell/.config/quickshell/labfy-sway/controlcenter/SessionExitGate.qml");
compare(component.status, Component.Ready, component.errorString());
return createTemporaryObject(component, this, {
checkpointSuccessStatus: "saved",
actions: [
{id: "logout", checkpointReason: "logout", command: ["uwsm", "stop"]},
{id: "reboot", checkpointReason: "reboot", command: ["systemctl", "reboot"]},
{id: "poweroff", checkpointReason: "poweroff", command: ["systemctl", "poweroff"]}
]
});
}
Component { id: spyComponent; SignalSpy {} }
function test_saved_releases_only_confirmed_action() {
for (const action of ["logout", "reboot", "poweroff"]) {
const g = gate();
const spy = createTemporaryObject(spyComponent, this, {target: g, signalName: "commandRequested"});
g.requestAction(action);
g.confirmAction(action);
verify(g.busy);
compare(spy.count, 0);
g.checkpointFinished(0, 0, '{"status":"saved"}', "");
compare(spy.count, 1);
compare(spy.signalArguments[0][0], action === "logout" ? ["uwsm", "stop"] : ["systemctl", action]);
}
}
function test_error_or_legacy_success_never_exits() {
for (const response of ["{}", "invalid", '{"status":"success"}', '{"status":"failed"}']) {
const g = gate();
const spy = createTemporaryObject(spyComponent, this, {target: g, signalName: "commandRequested"});
g.requestAction("logout"); g.confirmAction("logout");
g.checkpointFinished(0, 0, response, "");
compare(spy.count, 0);
verify(!g.busy);
g.cancel();
compare(spy.count, 0);
}
}
function test_backend_reason_is_visible_and_logout_stays_gated() {
for (const reason of ["CAPABILITY_UNSUPPORTED", "SNAPSHOT_CHANGED", "RECOVERY_REQUIRED", "UNKNOWN_BACKEND_REASON"]) {
const g = gate();
const spy = createTemporaryObject(spyComponent, this, {target: g, signalName: "commandRequested"});
g.requestAction("logout"); g.confirmAction("logout");
g.checkpointFinished(2, 0, JSON.stringify({status: "failed", reason: reason}), "Le checkpoint V2 a échoué.");
verify(g.errorMessage.indexOf(reason) >= 0);
verify(g.errorMessage.length > reason.length + 10);
compare(spy.count, 0);
compare(g.pendingAction.id, "logout");
g.cancel(); compare(spy.count, 0);
}
}
function test_quit_without_saving_requires_explicit_call() {
const g = gate();
const spy = createTemporaryObject(spyComponent, this, {target: g, signalName: "commandRequested"});
g.requestAction("logout"); g.confirmAction("logout");
g.quitWithoutCheckpoint(); compare(spy.count, 0);
g.checkpointFinished(2, 0, '{"status":"saved"}', "échec");
compare(spy.count, 0);
g.quitWithoutCheckpoint(); compare(spy.count, 1);
}
}