mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-29 14:45:24 +00:00
feat: redesign user host defaults system
This commit is contained in:
1 parent
3028ab1176
commit
a4a4d4f27b
144 files changed
+24609
-2555
No files matched your search
@@ -54,8 +54,9 @@ describe("hostPayloadLegacy", () => {
|
||||
fontSize: 20,
|
||||
}) as { terminalConfig: Record<string, unknown> };
|
||||
expect(terminalConfig.autoTmux).toBe(true);
|
||||
expect(terminalConfig).not.toHaveProperty("fontSize");
|
||||
expect(terminalConfig).not.toHaveProperty("localEcho");
|
||||
// The values already follow the host defaults, so the look is included.
|
||||
expect(terminalConfig.fontSize).toBe(20);
|
||||
expect(terminalConfig.localEcho).toBe("auto");
|
||||
});
|
||||
|
||||
it("includes the look of a host that has its own", () => {
|
||||
|
||||
@@ -146,26 +146,20 @@ describe("terminal settings routes", () => {
|
||||
authType: "password",
|
||||
});
|
||||
|
||||
it("hands every user their own terminal settings and the new-host defaults", async () => {
|
||||
server = await startServer({
|
||||
settings: { newHostFontSize: 20, newHostTheme: "nord" },
|
||||
});
|
||||
it("hands every user their own terminal settings", async () => {
|
||||
server = await startServer();
|
||||
await server.mock.ctx.settings.setUser(
|
||||
"user-1",
|
||||
"commandAutocomplete",
|
||||
true,
|
||||
);
|
||||
await server.mock.ctx.settings.setUser("user-1", "terminalDefaults", {
|
||||
fontSize: 18,
|
||||
});
|
||||
const { body } = await server.request("GET", "/client-settings");
|
||||
expect(body.user).toMatchObject({
|
||||
commandAutocomplete: true,
|
||||
terminalDefaults: { fontSize: 18 },
|
||||
localEcho: "auto",
|
||||
linkClickBehavior: "confirm",
|
||||
});
|
||||
expect(body.newHostDefaults).toMatchObject({ fontSize: 20, theme: "nord" });
|
||||
expect(body).not.toHaveProperty("newHostDefaults");
|
||||
const other = await server.request("GET", "/client-settings", {
|
||||
user: "user-2",
|
||||
});
|
||||
|
||||
@@ -30,19 +30,25 @@ describe("hostSettingsFromTerminalConfig", () => {
|
||||
});
|
||||
|
||||
describe("resolveTerminalSettings", () => {
|
||||
it("uses the user's defaults while the host follows them", () => {
|
||||
it("runs with the host's values, which already follow its defaults", () => {
|
||||
const host = readHostTerminalSettings({ fontSize: 30, autoTmux: true });
|
||||
const resolved = resolveTerminalSettings(host, { fontSize: 18 });
|
||||
expect(resolved.fontSize).toBe(18);
|
||||
const resolved = resolveTerminalSettings(host);
|
||||
expect(resolved.fontSize).toBe(30);
|
||||
expect(resolved.autoTmux).toBe(true);
|
||||
});
|
||||
|
||||
it("uses the host's own look once it opts out", () => {
|
||||
it("ignores the old follow-the-user switch", () => {
|
||||
const host = readHostTerminalSettings({
|
||||
inheritAppearance: false,
|
||||
fontSize: 30,
|
||||
inheritAppearance: true,
|
||||
fontSize: 22,
|
||||
});
|
||||
expect(resolveTerminalSettings(host, { fontSize: 18 }).fontSize).toBe(30);
|
||||
expect(resolveTerminalSettings(host).fontSize).toBe(22);
|
||||
});
|
||||
|
||||
it("defaults echo and link clicks to concrete modes", () => {
|
||||
const resolved = resolveTerminalSettings(readHostTerminalSettings({}));
|
||||
expect(resolved.localEcho).toBe("auto");
|
||||
expect(resolved.linkClickBehavior).toBe("confirm");
|
||||
});
|
||||
|
||||
it("falls back to the built-in defaults", () => {
|
||||
@@ -62,7 +68,6 @@ describe("readUserSettings", () => {
|
||||
linkClickBehavior: "direct",
|
||||
}),
|
||||
).toEqual({
|
||||
terminalDefaults: { fontSize: 16 },
|
||||
customThemes: [{ id: "a", name: "A", colors: {} }],
|
||||
commandAutocomplete: false,
|
||||
localEcho: "auto",
|
||||
|
||||
@@ -116,11 +116,11 @@ describe(`${manifest.id} activate`, () => {
|
||||
it("registers its settings components", async () => {
|
||||
rendered = await renderWithApp(plugin, { manifest, locales });
|
||||
expect(rendered.registered.settingsComponents()).toEqual(
|
||||
expect.arrayContaining([
|
||||
"terminalDefaults",
|
||||
"newHostTheme",
|
||||
"newHostFontFamily",
|
||||
]),
|
||||
expect.arrayContaining(["touchInput", "imageStorageTest"]),
|
||||
);
|
||||
// Terminal defaults are host defaults now, set in the host editor.
|
||||
expect(rendered.registered.settingsComponents()).not.toContain(
|
||||
"terminalDefaults",
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
||||
import { TerminalDefaultsSettings } from "../../../src/frontend/settings/TerminalDefaultsSettings";
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
describe("TerminalDefaultsSettings", () => {
|
||||
it("counts the defaults the user set", () => {
|
||||
render(
|
||||
<TerminalDefaultsSettings
|
||||
pluginId="ssh-terminal"
|
||||
values={{ terminalDefaults: { fontSize: 18, cursorBlink: false } }}
|
||||
setValue={vi.fn()}
|
||||
running
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByText("2")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("applies the dialog's values to the terminalDefaults setting", () => {
|
||||
const setValue = vi.fn();
|
||||
render(
|
||||
<TerminalDefaultsSettings
|
||||
pluginId="ssh-terminal"
|
||||
values={{ terminalDefaults: { fontSize: 18 } }}
|
||||
setValue={setValue}
|
||||
running
|
||||
/>,
|
||||
);
|
||||
fireEvent.click(screen.getByText("terminalDefaults.manage"));
|
||||
fireEvent.change(screen.getByDisplayValue("18"), {
|
||||
target: { value: "20" },
|
||||
});
|
||||
fireEvent.click(screen.getByText("terminalDefaults.apply"));
|
||||
expect(setValue).toHaveBeenCalledWith("terminalDefaults", { fontSize: 20 });
|
||||
});
|
||||
});
|
||||
@@ -1,17 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
fromTriState,
|
||||
toTriState,
|
||||
} from "../../../src/frontend/settings/tri-state";
|
||||
|
||||
describe("tri-state", () => {
|
||||
it("keeps unset booleans distinct from false", () => {
|
||||
expect(toTriState(undefined)).toBe("inherit");
|
||||
expect(toTriState(true)).toBe("on");
|
||||
expect(toTriState(false)).toBe("off");
|
||||
|
||||
expect(fromTriState("inherit")).toBeUndefined();
|
||||
expect(fromTriState("on")).toBe(true);
|
||||
expect(fromTriState("off")).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user