mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-30 07:05:24 +00:00
feat: move snippets, keybinding actions and macros out of core into plugins
This commit is contained in:
1 parent
d9bba10612
commit
e0c30a4e6f
262 files changed
+9091
-10744
No files matched your search
@@ -0,0 +1,79 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
createHostSettingsSync,
|
||||
hostImportNormalizer,
|
||||
hostPayloadLegacy,
|
||||
} from "../../src/backend/host-import.js";
|
||||
|
||||
describe("hostImportNormalizer", () => {
|
||||
it("reads a 2.8 export's quick actions and startup snippet", () => {
|
||||
expect(
|
||||
hostImportNormalizer({
|
||||
quickActions: [
|
||||
{ name: "Restart", snippetId: "3" },
|
||||
{ name: "Broken", snippetId: "" },
|
||||
],
|
||||
terminalConfig: JSON.stringify({ startupSnippetId: 5, fontSize: 12 }),
|
||||
}),
|
||||
).toEqual({
|
||||
quickActions: [{ name: "Restart", snippetId: 3 }],
|
||||
startupSnippetId: 5,
|
||||
});
|
||||
});
|
||||
|
||||
it("leaves an export that carries this plugin's settings to core", () => {
|
||||
expect(
|
||||
hostImportNormalizer({
|
||||
pluginSettings: { snippets: { startupSnippetId: 1 } },
|
||||
terminalConfig: { startupSnippetId: 5 },
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("writes nothing for a host without either", () => {
|
||||
expect(hostImportNormalizer({ name: "web" })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("hostPayloadLegacy", () => {
|
||||
it("puts the 2.8 fields back for older clients", () => {
|
||||
expect(
|
||||
hostPayloadLegacy({
|
||||
quickActions: [{ name: "Up", snippetId: 2 }],
|
||||
startupSnippetId: 7,
|
||||
}),
|
||||
).toEqual({
|
||||
quickActions: [{ name: "Up", snippetId: 2 }],
|
||||
terminalConfig: { startupSnippetId: 7 },
|
||||
});
|
||||
expect(hostPayloadLegacy({})).toEqual({ quickActions: [] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("hostSettingsSync", () => {
|
||||
const sync = createHostSettingsSync({
|
||||
findSyncIdById: async (id) => (id === 2 ? "sync-2" : null),
|
||||
findIdBySyncId: async (syncId) => (syncId === "sync-2" ? 9 : null),
|
||||
});
|
||||
|
||||
it("sends sync ids and drops what does not map", async () => {
|
||||
expect(await sync.exportValue("startupSnippetId", 2)).toBe("sync-2");
|
||||
expect(await sync.exportValue("startupSnippetId", 4)).toBeNull();
|
||||
expect(
|
||||
await sync.exportValue("quickActions", [
|
||||
{ name: "A", snippetId: 2 },
|
||||
{ name: "B", snippetId: 4 },
|
||||
]),
|
||||
).toEqual([{ name: "A", snippetId: "sync-2" }]);
|
||||
});
|
||||
|
||||
it("maps sync ids back to this side's rows", async () => {
|
||||
expect(await sync.importValue("startupSnippetId", "sync-2")).toBe(9);
|
||||
expect(await sync.importValue("startupSnippetId", "missing")).toBeNull();
|
||||
expect(
|
||||
await sync.importValue("quickActions", [
|
||||
{ name: "A", snippetId: "sync-2" },
|
||||
]),
|
||||
).toEqual([{ name: "A", snippetId: 9 }]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user