Files
stilobiqueandClaude Opus 5.5 1b2acae316
CI / Vérifications et paquet (push) Successful in 48s
CI / Release Gitea (push) Skipped
Add test suite (box rules, Python, QML against a fake Jellyfin server) and local preview jobs
- freebox-jellyfin test: box-only rules (ES5, QtQuick 2.5, qmldir, singletons),
  tooling unit tests, qmltestrunner on tests/qml against fake_server.py
- freebox-jellyfin fake-server and preview --fake-server
- package enforces the box rules; CI runs the tests
- JetBrains run configs: Local Preview, Local Preview (faux serveur), Tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 00:08:03 +01:00

82 lines
2.9 KiB
QML

import QtQuick 2.5
import QtTest 1.2
import TestEnv 1.0
// Base des tests : accès au faux serveur Jellyfin (src/freebox_jellyfin/fake_server.py)
// démarré par `freebox-jellyfin test`, qui fournit son adresse via le module TestEnv.
// Les tests tournent sur le PC (Qt 5.15) : ce dossier n'est pas soumis aux règles ES5.
TestCase {
id: testCase
readonly property string serverUrl: Env.baseUrl
readonly property string serverHost: Env.host
readonly property string serverPort: String(Env.port)
// Lance start(done) et attend l'appel de done(...) ; renvoie ses arguments (tableau).
function waitCallback(start, timeout, message) {
var box = { done: false, args: [] };
start(function () {
box.args = Array.prototype.slice.call(arguments);
box.done = true;
});
tryVerify(function () { return box.done; }, timeout || 5000, message || "callback jamais appelé");
return box.args;
}
// Requête au faux serveur ; renvoie la réponse JSON décodée (ou null).
function http(method, path, body) {
var result = waitCallback(function (done) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE)
done(xhr.status, xhr.responseText);
};
xhr.open(method, serverUrl + path);
if (body !== undefined) {
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(body));
} else {
xhr.send();
}
}, 5000, "faux serveur injoignable : " + method + " " + path);
return result[1] ? JSON.parse(result[1]) : null;
}
function resetServer() {
http("POST", "/__reset");
}
// Réponse imposée : { path, method?, status?, body?, raw?, delay? (ms) }
function mock(spec) {
http("POST", "/__mock", spec);
}
// Requêtes reçues par le faux serveur (toutes, ou celles d'un chemin).
function requests(path) {
var all = http("GET", "/__requests");
return path ? all.filter(function (r) { return r.path === path; }) : all;
}
function lastRequest(path) {
var list = requests(path);
return list.length > 0 ? list[list.length - 1] : null;
}
// Premier descendant (parcours en largeur) pour lequel predicate(objet) est vrai.
function findChild(root, predicate) {
var queue = [root];
while (queue.length > 0) {
var item = queue.shift();
if (item !== root && predicate(item))
return item;
var children = item.children || [];
for (var i = 0; i < children.length; i++)
queue.push(children[i]);
var resources = item.resources || [];
for (var j = 0; j < resources.length; j++)
queue.push(resources[j]);
}
return null;
}
}