mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
Open the predefined session chooser directly on the installed shells and SSH. The plus button opens the default shell. Split commands live in the terminal tool window's Options menu, with Settings at the bottom of the session chooser. On the Windows fixture the chooser went from nine actions to six and from 267 px to 153 px in height.
114 lines
5.6 KiB
TypeScript
114 lines
5.6 KiB
TypeScript
import type { Locator, Page } from "@playwright/test";
|
|
import { expect, stubDesktop, test } from "./fixtures";
|
|
|
|
const longName = "Production logs — inventory reconciliation and overnight deployment checks";
|
|
|
|
async function openTerminal(page: Page, width: number) {
|
|
await stubDesktop(page);
|
|
await page.evaluate(async (width) => {
|
|
const handlers = window.__ipc.handlers;
|
|
let id = 0;
|
|
handlers.term_default_shell = () => "/bin/zsh";
|
|
handlers.term_available_shells = () => ["/bin/zsh"];
|
|
handlers.term_spawn = () => ({ id: ++id, title: "zsh", pid: id });
|
|
handlers.term_resize = () => null;
|
|
handlers.term_kill = () => null;
|
|
const path = "/src/workbench/toolwindows/store.ts";
|
|
const layout = await import(path);
|
|
layout.moveToolWindow("terminal", "right");
|
|
layout.setToolWindowSize("right", width);
|
|
layout.showToolWindow("terminal", true);
|
|
}, width);
|
|
return page.getByRole("region", { name: "Terminal", exact: true });
|
|
}
|
|
|
|
async function renameTerminal(tab: Locator, name: string) {
|
|
await tab.dblclick();
|
|
const input = tab.page().getByRole("textbox", { name: "Tab name" });
|
|
await input.fill(name);
|
|
await input.press("Enter");
|
|
}
|
|
|
|
async function expectSelectedTabToFit(strip: Locator) {
|
|
const selected = strip.getByRole("tab", { selected: true });
|
|
await expect(selected).toBeVisible();
|
|
await expect
|
|
.poll(() =>
|
|
selected.evaluate((tab) => {
|
|
const clip = tab.closest('[role="tablist"]')!.getBoundingClientRect();
|
|
const slot = tab.parentElement!.getBoundingClientRect();
|
|
return slot.left >= clip.left - 1 && slot.right <= clip.right + 1;
|
|
}),
|
|
)
|
|
.toBe(true);
|
|
}
|
|
|
|
test("a narrow terminal panel keeps the selected tab's close button in view", async ({ workbench: page }) => {
|
|
const terminal = await openTerminal(page, 220);
|
|
const strip = terminal.getByRole("tablist", { name: "Terminal sessions" });
|
|
await renameTerminal(strip.getByRole("tab", { name: "Local", exact: true }), longName);
|
|
const selected = strip.getByRole("tab", { name: longName, selected: true });
|
|
await expect(selected).toBeVisible();
|
|
await expectSelectedTabToFit(strip);
|
|
await expect
|
|
.poll(() =>
|
|
selected.getByText(longName, { exact: true }).evaluate((label) => label.scrollWidth > label.clientWidth),
|
|
)
|
|
.toBe(true);
|
|
await expect(selected).toHaveAttribute("data-tooltip", new RegExp(longName));
|
|
await expect(terminal.getByRole("button", { name: "Show Hidden Tabs" })).toBeHidden();
|
|
await expect(terminal.getByRole("button", { name: "New Tab", exact: true })).toBeVisible();
|
|
await terminal.getByRole("button", { name: "New Predefined Session" }).click();
|
|
await expect(page.getByRole("menuitem", { name: "zsh", exact: true })).toBeVisible();
|
|
await page.keyboard.press("Escape");
|
|
await strip.getByRole("button", { name: "Close Tab", exact: true }).click();
|
|
await expect(terminal).toBeHidden();
|
|
});
|
|
|
|
test("terminal split tabs fit when sessions overflow and switch through the menu", async ({ workbench: page }) => {
|
|
const terminal = await openTerminal(page, 520);
|
|
const strips = terminal.getByRole("tablist", { name: "Terminal sessions" });
|
|
await strips.getByRole("tab", { name: "Local", exact: true }).click({ button: "right" });
|
|
await page.getByRole("menuitem", { name: /^Split Right/ }).click();
|
|
await expect(strips).toHaveCount(2);
|
|
const header = terminal.locator("header").nth(1);
|
|
const strip = strips.nth(1);
|
|
await header.getByRole("button", { name: "New Tab", exact: true }).click();
|
|
await renameTerminal(strip.getByRole("tab", { selected: true }), longName);
|
|
await expect(strip.getByRole("tab", { name: longName, selected: true })).toBeVisible();
|
|
await expectSelectedTabToFit(strip);
|
|
const hidden = header.getByRole("button", { name: "Show Hidden Tabs" });
|
|
await hidden.click();
|
|
await page.getByRole("menuitem", { name: "Local (2)", exact: true }).click();
|
|
await expect(strip.getByRole("tab", { name: "Local (2)", selected: true })).toBeVisible();
|
|
await expectSelectedTabToFit(strip);
|
|
await expect(header.getByRole("button", { name: "New Predefined Session" })).toBeVisible();
|
|
await hidden.click();
|
|
await page.getByRole("menuitem", { name: longName, exact: true }).click();
|
|
await expect(strip.getByRole("tab", { name: longName, selected: true })).toBeVisible();
|
|
await expectSelectedTabToFit(strip);
|
|
});
|
|
|
|
test("the terminal session chooser lists shells first and window options own the split commands", async ({
|
|
workbench: page,
|
|
}) => {
|
|
const terminal = await openTerminal(page, 520);
|
|
const chooser = terminal.getByRole("button", { name: "New Predefined Session", exact: true });
|
|
await expect(chooser).toBeVisible();
|
|
await chooser.press("Space");
|
|
const sessions = page.getByRole("menu", { name: "New Predefined Session", exact: true });
|
|
await expect(sessions.getByRole("menuitem")).toHaveText(["zsh", "SSH Session…", /^Settings/]);
|
|
await page.keyboard.press("Home");
|
|
await expect(sessions.getByRole("menuitem", { name: "zsh", exact: true })).toBeFocused();
|
|
await page.keyboard.press("Enter");
|
|
await expect(sessions).toBeHidden();
|
|
await expect(terminal.getByRole("tab", { name: "zsh", selected: true })).toBeVisible();
|
|
|
|
await terminal.getByRole("button", { name: "Options", exact: true }).click();
|
|
const options = page.getByRole("menu", { name: "Terminal options", exact: true });
|
|
await expect(options.getByRole("menuitem", { name: /^Split Down/ })).toBeVisible();
|
|
await expect(options.getByRole("menuitem", { name: /^Settings/ })).toBeVisible();
|
|
await options.getByRole("menuitem", { name: /^Split Right/ }).click();
|
|
await expect(terminal.getByRole("tablist", { name: "Terminal sessions" })).toHaveCount(2);
|
|
});
|