Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

quickshell/nuguland/features/launcher/launcher-ipc.test.js

Raw
'use strict';

const path = require('path');
const { runIpcSelfTests } = require('../../test-fixtures/ipc-selftest.js');

// The production Launcher loads in an isolated Quickshell, and launch.js runs under
// the QML engine (launch.test.js covers it in node): accent folding, match tiers,
// frecency order, details and actions; nothing launches.
runIpcSelfTests({
    files: ['Launcher.qml', 'launch.js'].map(file => path.join(__dirname, file)),
    imports: ['import "launch.js" as Launch'],
    body: `
    Launcher { id: launcher }

    function check(): string {
        const cases = [];
        const ok = (name, pass) => cases.push({ name: name, pass: !!pass });
        ok("intent-app", Launch.prefixIntent("firefox").intent === "app");
        ok("fold-accents", Launch.normalize("Déjà Dup") === "deja dup");
        const tiers = Launch.buildApps([
            { "id": "code", "name": "Visual Studio Code" },
            { "id": "wezterm", "name": "WezTerm" },
            { "id": "zellij", "name": "Zellij", "genericName": "Terminal Workspace" }
        ]);
        const titles = (query, frecency) => Launch.rankResults(query, { "apps": tiers, "frecency": frecency || {}, "now": 0 }).results.map(r => r.title).join();
        ok("match-tiers", titles("vsc") === "Visual Studio Code" && titles("code visual") === "Visual Studio Code" && titles("zzz") === "");
        ok("frecency-within-tier", titles("term", { "zellij": { "score": 9, "at": 0 } }) === "WezTerm,Zellij" && titles("", { "zellij": { "score": 1, "at": 0 } }) === "Zellij,Visual Studio Code,WezTerm");
        const built = Launch.buildApps([{
            "id": "firefox", "name": "Firefox", "genericName": "Web Browser", "icon": "firefox",
            "categories": ["Network"], "keywords": ["web", "browser"],
            "actions": [{ "id": "new-window", "name": "New Window", "command": ["firefox", "--new-window"] }]
        }]);
        ok("app-details", built[0].details[0].value === "Network" && built[0].keywords[0] === "web");
        ok("app-actions", built[0].actions[0].title === "New Window");
        const ranked = Launch.rankResults("browser", { "apps": built });
        ok("rank-keyword", ranked.selectedIndex === 0 && ranked.results[0].title === "Firefox" && ranked.results[0].provider === "app");
        const terminal = launcher.recordFor({ "id": "terminal", "desktopId": "org.example.Terminal", "terminal": true });
        const graphical = launcher.recordFor({ "id": "browser", "desktopId": "browser.desktop", "terminal": false });
        ok("terminal-route", terminal.slice === "work.slice" && JSON.stringify(terminal.argv) === JSON.stringify(["uwsm", "app", "-s", "work.slice", "--", "org.example.Terminal.desktop"]));
        ok("graphical-route", graphical.slice === "app-graphical.slice" && JSON.stringify(graphical.argv) === JSON.stringify(["uwsm", "app", "-s", "a", "--", "browser.desktop"]));
        ok("missing-id", launcher.recordFor({ "id": "missing" }).argv.length === 0);
        return JSON.stringify({ fail: cases.filter(c => !c.pass).length, cases: cases });
    }`,
    methods: [['launcher', 'check()']]
});
console.log('launcher-ipc.test.js: ALL PASS');