TypeScript
fix(web): keybindings page says to connect an environment when none is connected (#19400)
Theo Browne7c43155883dc
diff --git a/apps/web/src/components/settings/KeybindingsSettings.environment.test.tsx b/apps/web/src/components/settings/KeybindingsSettings.environment.test.tsxindex a33720e5834..d18fe69bdad 100644--- a/apps/web/src/components/settings/KeybindingsSettings.environment.test.tsx+++ b/apps/web/src/components/settings/KeybindingsSettings.environment.test.tsx@@ -7,6 +7,7 @@ import { reactHookHarness as hooks } from "../../test/reactHookHarness";const state = vi.hoisted(() => ({canOperate: false,canWriteSettings: true,+ connected: true,openEditor: vi.fn(),upsert: vi.fn(),remove: vi.fn(),@@ -57,7 +58,9 @@ vi.mock("./SettingsScopeContext", () => ({availableEditors: [],},};- return { environment, connectedEnvironments: [environment] };+ return state.connected+ ? { environment, connectedEnvironments: [environment] }+ : { environment: null, connectedEnvironments: [] };},}));@@ -104,6 +107,7 @@ describe("KeybindingsSettings editor permission", () => {hooks.reset();state.canOperate = false;state.canWriteSettings = true;+ state.connected = true;state.openEditor.mockReset().mockResolvedValue({ _tag: "Success", value: undefined });state.upsert.mockReset().mockResolvedValue({ _tag: "Success", value: undefined });state.remove.mockReset().mockResolvedValue({ _tag: "Success", value: undefined });@@ -141,3 +145,30 @@ describe("KeybindingsSettings editor permission", () => {expect(openButton(renderPanel()).props.disabled).toBe(true);});});++function noticeText(panel: unknown) {+ const notice = visitElements(panel, (element) => element.type === "p");+ return notice?.props.children;+}++describe("KeybindingsSettings write notice", () => {+ beforeEach(() => {+ hooks.reset();+ state.canWriteSettings = true;+ state.connected = true;+ });++ // The hosted app has no environment until one is paired, so the editor is+ // locked for a missing connection, not a missing permission.+ it("asks for a connected environment when none is connected", () => {+ state.connected = false;+ expect(noticeText(renderPanel())).toBe("Connect an environment to change keybindings.");+ });++ it("names the permission when the connection cannot write settings", () => {+ state.canWriteSettings = false;+ expect(noticeText(renderPanel())).toBe(+ "This connection can view keybindings but cannot change them.",+ );+ });+});diff --git a/apps/web/src/components/settings/KeybindingsSettings.tsx b/apps/web/src/components/settings/KeybindingsSettings.tsxindex 1aa0dc0e9d3..cc2fc85f94f 100644--- a/apps/web/src/components/settings/KeybindingsSettings.tsx+++ b/apps/web/src/components/settings/KeybindingsSettings.tsx@@ -1502,7 +1502,9 @@ export function KeybindingsSettingsPanel() {{!canWriteSettings ? (<p className="text-xs text-muted-foreground">- This connection can view keybindings but cannot change them.+ {connectedEnvironments.length === 0+ ? "Connect an environment to change keybindings."+ : "This connection can view keybindings but cannot change them."}</p>) : null}<div inert={!canWriteSettings} className="flex flex-col gap-8">