Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 74 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/frontend/terminal/TerminalTabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export function TerminalTabContent({
}: TabProps) {
const tab = tabRecord as unknown as TerminalTabRecord;
const host = hostRecord as unknown as Host | undefined;
// Saved shell hosts use string IDs; quick-connect hosts are not editable.
const savedHostId = /^[1-9]\d*$/.test(String(host?.id))
? Number(host?.id)
: NaN;
// editHost is on the shell from Termix 26.10.6.
const editHost = (shell as { editHost?: (hostId: number) => void }).editHost;
const { t } = useTranslation();
Expand Down Expand Up @@ -151,8 +155,8 @@ export function TerminalTabContent({
: undefined
}
onEditHost={
editHost && typeof host?.id === "number"
? () => editHost(host!.id as number)
editHost && Number.isSafeInteger(savedHostId)
? () => editHost(savedHostId)
: undefined
}
host={host}
Expand Down
49 changes: 47 additions & 2 deletions tests/frontend/terminal/TerminalTabContent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ afterEach(() => {
captured.props = [];
});

function renderTab(inSplit?: boolean, data?: Record<string, unknown>) {
function renderTab(
inSplit?: boolean,
data?: Record<string, unknown>,
options: { id?: number | string; editHost?: (id: number) => void } = {},
) {
const props = {
tab: {
id: "t1",
Expand All @@ -41,7 +45,7 @@ function renderTab(inSplit?: boolean, data?: Record<string, unknown>) {
label: "web-01",
data,
},
host: { id: "1", name: "web-01", ip: "10.0.0.1", port: 22 },
host: { id: options.id ?? "1", name: "web-01", ip: "10.0.0.1", port: 22 },
sshHost: { id: 1 },
label: "web-01",
isVisible: true,
Expand All @@ -52,6 +56,7 @@ function renderTab(inSplit?: boolean, data?: Record<string, unknown>) {
closeTab: vi.fn(),
renameTab: vi.fn(),
openTab: vi.fn(),
editHost: options.editHost,
},
} as unknown as TabProps;
render(<TerminalTabContent {...props} />);
Expand Down Expand Up @@ -82,3 +87,43 @@ describe("TerminalTabContent in a split", () => {
expect(captured.props.at(-1)?.executeCommand).toBeUndefined();
});
});

describe("TerminalTabContent host editing", () => {
it.each([7, "7"])(
"opens the existing host editor for saved ID %j",
async (id) => {
const editHost = vi.fn();
renderTab(undefined, undefined, { id, editHost });
await waitFor(() => expect(captured.props.length).toBeGreaterThan(0));
const edit = captured.props.at(-1)?.onEditHost;
expect(edit).toBeTypeOf("function");
(edit as () => void)();
expect(editHost).toHaveBeenCalledWith(7);
},
);

it.each([
"quick-connect-7",
"7suffix",
"",
"1e2",
"0x7",
" 7",
0,
-7,
1.5,
Number.MAX_SAFE_INTEGER + 1,
])("does not offer editing for unsaved or invalid ID %j", async (id) => {
const editHost = vi.fn();
renderTab(undefined, undefined, { id, editHost });
await waitFor(() => expect(captured.props.length).toBeGreaterThan(0));
expect(captured.props.at(-1)?.onEditHost).toBeUndefined();
expect(editHost).not.toHaveBeenCalled();
});

it("does not offer editing when the shell does not support it", async () => {
renderTab(undefined, undefined, { id: 7 });
await waitFor(() => expect(captured.props.length).toBeGreaterThan(0));
expect(captured.props.at(-1)?.onEditHost).toBeUndefined();
});
});