Skip to content

Commit c5232b0

Browse files
committed
fix(control-ui): preserve token when editing ws url
1 parent 56f787e commit c5232b0

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

ui/src/ui/navigation.browser.test.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ describe("control UI routing", () => {
198198
expect(window.location.hash).toBe("");
199199
});
200200

201-
it("clears the current token when the gateway URL changes", async () => {
201+
it("keeps the current token when the gateway URL changes", async () => {
202202
const app = mountApp("/ui/overview#token=abc123");
203203
await app.updateComplete;
204204

@@ -211,7 +211,35 @@ describe("control UI routing", () => {
211211
await app.updateComplete;
212212

213213
expect(app.settings.gatewayUrl).toBe("wss://other-gateway.example/openclaw");
214-
expect(app.settings.token).toBe("");
214+
expect(app.settings.token).toBe("abc123");
215+
});
216+
217+
it("preserves a typed token while editing the gateway URL from overview", async () => {
218+
const app = mountApp("/ui/overview");
219+
await app.updateComplete;
220+
221+
const tokenInput = app.querySelector<HTMLInputElement>(
222+
'input[placeholder="OPENCLAW_GATEWAY_TOKEN"]',
223+
);
224+
expect(tokenInput).not.toBeNull();
225+
tokenInput!.value = "typed-token";
226+
tokenInput!.dispatchEvent(new Event("input", { bubbles: true }));
227+
await app.updateComplete;
228+
229+
const gatewayUrlInput = app.querySelector<HTMLInputElement>(
230+
'input[placeholder="ws://100.x.y.z:18789"]',
231+
);
232+
expect(gatewayUrlInput).not.toBeNull();
233+
gatewayUrlInput!.value = "wss://other-gateway.example/openclaw";
234+
gatewayUrlInput!.dispatchEvent(new Event("input", { bubbles: true }));
235+
await app.updateComplete;
236+
237+
const nextTokenInput = app.querySelector<HTMLInputElement>(
238+
'input[placeholder="OPENCLAW_GATEWAY_TOKEN"]',
239+
);
240+
expect(app.settings.gatewayUrl).toBe("wss://other-gateway.example/openclaw");
241+
expect(app.settings.token).toBe("typed-token");
242+
expect(nextTokenInput?.value).toBe("typed-token");
215243
});
216244

217245
it("keeps a hash token pending until the gateway URL change is confirmed", async () => {

ui/src/ui/views/overview.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ export function renderOverview(props: OverviewProps) {
208208
props.onSettingsChange({
209209
...props.settings,
210210
gatewayUrl: v,
211-
token: v.trim() === props.settings.gatewayUrl.trim() ? props.settings.token : "",
212211
});
213212
}}
214213
placeholder="ws://100.x.y.z:18789"

0 commit comments

Comments
 (0)