mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-30 07:05:24 +00:00
feat(ssh-terminal): add toolbar position, start state, display and fade host settings
This commit is contained in:
1 parent
1fd89acd90
commit
f0d720cf05
8 files changed
+418
-28
No files matched your search
@@ -976,4 +976,63 @@ describe("TerminalToolbar Phase 1", () => {
|
||||
expect(screen.queryByRole("button", { name: "AI Assistant" })).toBeNull();
|
||||
});
|
||||
});
|
||||
describe("host toolbar settings", () => {
|
||||
const withSettings = (values: Record<string, unknown>) =>
|
||||
({
|
||||
...host,
|
||||
pluginSettings: { "ssh-terminal": values },
|
||||
}) as unknown as Host;
|
||||
|
||||
it("anchors the toolbar where the host asks", () => {
|
||||
const { container } = renderToolbar({
|
||||
host: withSettings({ terminalToolbarPosition: "top-right" }),
|
||||
});
|
||||
const toolbarHost = container.querySelector(
|
||||
"[data-terminal-toolbar-host]",
|
||||
);
|
||||
expect(toolbarHost).toHaveClass("items-start", "justify-end", "pt-2");
|
||||
expect(toolbarHost).not.toHaveClass("items-end", "justify-center");
|
||||
});
|
||||
|
||||
it("keeps a separate drag offset per anchor", () => {
|
||||
localStorage.setItem(
|
||||
"termix-terminal-toolbar-position-v2",
|
||||
JSON.stringify({ x: 0, y: -40 }),
|
||||
);
|
||||
const { container } = renderToolbar({
|
||||
host: withSettings({ terminalToolbarPosition: "top-left" }),
|
||||
});
|
||||
expect(
|
||||
container.querySelector("[data-terminal-toolbar-wide]"),
|
||||
).toHaveStyle({ transform: "translate(0px, 0px)" });
|
||||
});
|
||||
|
||||
it("starts minimized when the host asks", () => {
|
||||
renderToolbar({
|
||||
host: withSettings({ terminalToolbarStartState: "collapsed" }),
|
||||
});
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Expand toolbar" }),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Hide toolbar" })).toBeNull();
|
||||
});
|
||||
|
||||
it("uses the host display mode without overwriting the saved one", () => {
|
||||
localStorage.setItem("termix-terminal-toolbar-density", "labeled");
|
||||
renderToolbar({ host: withSettings({ terminalToolbarDisplay: "icon" }) });
|
||||
expect(screen.queryByText("Upload image")).toBeNull();
|
||||
expect(localStorage.getItem("termix-terminal-toolbar-density")).toBe(
|
||||
"labeled",
|
||||
);
|
||||
});
|
||||
|
||||
it("stays fully visible when fading is off", () => {
|
||||
const { container } = renderToolbar({
|
||||
host: withSettings({ terminalToolbarFade: false }),
|
||||
});
|
||||
const toolbar = container.querySelector("[data-terminal-toolbar-wide]");
|
||||
expect(toolbar).toHaveClass("opacity-100");
|
||||
expect(toolbar).not.toHaveClass("opacity-30");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,74 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
DEFAULT_TOOLBAR_SETTINGS,
|
||||
readToolbarSettings,
|
||||
toolbarAnchorClasses,
|
||||
} from "../../../src/frontend/terminal/toolbar-settings";
|
||||
import { toolbarPositionStorageKey } from "../../../src/frontend/terminal/toolbar-geometry";
|
||||
|
||||
const hostWith = (values: Record<string, unknown>) => ({
|
||||
pluginSettings: { "ssh-terminal": values },
|
||||
});
|
||||
|
||||
describe("readToolbarSettings", () => {
|
||||
it("falls back to defaults for a host without settings", () => {
|
||||
expect(readToolbarSettings({})).toEqual(DEFAULT_TOOLBAR_SETTINGS);
|
||||
expect(readToolbarSettings(null)).toEqual(DEFAULT_TOOLBAR_SETTINGS);
|
||||
});
|
||||
|
||||
it("reads saved values", () => {
|
||||
expect(
|
||||
readToolbarSettings(
|
||||
hostWith({
|
||||
terminalToolbarPosition: "top-left",
|
||||
terminalToolbarStartState: "collapsed",
|
||||
terminalToolbarDisplay: "expanded",
|
||||
terminalToolbarShowStatus: false,
|
||||
terminalToolbarFade: false,
|
||||
}),
|
||||
),
|
||||
).toEqual({
|
||||
anchor: "top-left",
|
||||
startCollapsed: true,
|
||||
density: "expanded",
|
||||
showStatus: false,
|
||||
fadeWhenIdle: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores unknown values", () => {
|
||||
const settings = readToolbarSettings(
|
||||
hostWith({
|
||||
terminalToolbarPosition: "middle",
|
||||
terminalToolbarDisplay: "remember",
|
||||
terminalToolbarShowStatus: "no",
|
||||
}),
|
||||
);
|
||||
expect(settings.anchor).toBe("bottom");
|
||||
expect(settings.density).toBeNull();
|
||||
expect(settings.showStatus).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("toolbar anchors", () => {
|
||||
it("maps anchors to flex placement", () => {
|
||||
expect(toolbarAnchorClasses("bottom")).toBe(
|
||||
"items-end pb-2 justify-center",
|
||||
);
|
||||
expect(toolbarAnchorClasses("top-left")).toBe(
|
||||
"items-start pt-2 justify-start pl-2",
|
||||
);
|
||||
expect(toolbarAnchorClasses("bottom-right")).toBe(
|
||||
"items-end pb-2 justify-end pr-2",
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps the original storage key for the bottom anchor", () => {
|
||||
expect(toolbarPositionStorageKey()).toBe(
|
||||
"termix-terminal-toolbar-position-v2",
|
||||
);
|
||||
expect(toolbarPositionStorageKey("top")).toBe(
|
||||
"termix-terminal-toolbar-position-v2-top",
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user