Files
DankMaterialShell/quickshell/tests/settings-cc-grid.test.mjs
T

42 lines
3.0 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import { loadScript } from "./qml-script.mjs";
const store = loadScript(new URL("../Common/settings/SettingsStore.js", import.meta.url));
test("control center width percentages become square grid cells", () => {
const migrated = store.migrateToVersion({
configVersion: 26,
controlCenterWidth: 800,
controlCenterWidgets: [{ id: "wifi", width: 75 }, { id: "diskUsage", width: 25, mountPath: "/", instanceId: "disk" }, { id: "battery" }, { id: "plugin_x", width: 100, w: 3, h: 2, enabled: false }]
}, 27);
assert.equal(migrated.configVersion, 27);
assert.equal(migrated.controlCenterColumns, 12);
assert.equal(migrated.controlCenterWidth, undefined);
assert.deepEqual(JSON.parse(JSON.stringify(migrated.controlCenterWidgets)), [{ id: "wifi", w: 6, h: 1 }, { id: "diskUsage", mountPath: "/", instanceId: "disk", w: 2, h: 1 }, { id: "battery", w: 4, h: 1 }, { id: "plugin_x", w: 6, h: 2, enabled: false }]);
assert.equal(store.migrateToVersion(migrated, 27), null);
});
test("sparse settings migrate without inventing grid keys", () => {
const migrated = store.migrateToVersion({ configVersion: 26, controlCenterWidth: 550, controlCenterWidgets: [{ id: "wifi", width: 50 }, { id: "battery", width: 100 }] }, 27);
assert.equal(migrated.controlCenterColumns, 8);
assert.deepEqual(JSON.parse(JSON.stringify(migrated.controlCenterWidgets)), [{ id: "wifi", w: 4, h: 1 }, { id: "battery", w: 8, h: 1 }]);
const sparse = store.migrateToVersion({ configVersion: 26 }, 27);
assert.equal(sparse.controlCenterColumns, undefined);
assert.equal(sparse.controlCenterWidgets, undefined);
});
test("header entries become a user row and lock, power and settings tiles", () => {
const released = store.migrateToVersion({ configVersion: 18, controlCenterWidgets: [{ id: "wifi", width: 50 }] }, 35);
assert.deepEqual(JSON.parse(JSON.stringify(released.controlCenterWidgets.map(w => [w.id, w.w, w.h, !!w.footer]))), [["user", 5, 1, false], ["settings", 1, 1, false], ["lock", 1, 1, false], ["power", 1, 1, false], ["wifi", 4, 1, false], ["runningApps", 4, 1, true]]);
});
test("the edit button joins the footer end once and keeps a placed one", () => {
const migrated = store.migrateToVersion({ configVersion: 36, controlCenterWidgets: [{ id: "wifi", w: 4, h: 1 }] }, 37);
assert.equal(migrated.configVersion, 37);
assert.deepEqual(JSON.parse(JSON.stringify(migrated.controlCenterWidgets)), [{ id: "wifi", w: 4, h: 1 }, { id: "edit", enabled: true, w: 1, h: 1, small: true, footer: true, footerEnd: true }]);
const placed = store.migrateToVersion({ configVersion: 36, controlCenterWidgets: [{ id: "edit", w: 1, h: 1, col: 2, row: 0 }] }, 37);
assert.deepEqual(JSON.parse(JSON.stringify(placed.controlCenterWidgets)), [{ id: "edit", w: 1, h: 1, col: 2, row: 0 }]);
assert.equal(store.migrateToVersion({ configVersion: 36 }, 37).controlCenterWidgets, undefined);
});