Files
OpenHands/__tests__/utils/local-storage.test.ts
T
Hiep Le dd744b13f6 feat: cloud backend support with multi-backend selector and SaaS proxy routing (#145)
* feat: multi-backend support with cloud SaaS proxy routing

* feat: route conversation export through cloud proxy on cloud backends

* fix: route conversation delete through cloud proxy on cloud backends

* fix: forward settings diffs verbatim through cloud proxy save

* fix: surface cloud-aware settings sub-pages and gate local-only routes

* fix: route secrets settings through cloud proxy on cloud backends

* fix: route conversation stop runtime through cloud proxy on cloud backends

* fix: re-expose planning agent UI for cloud backends and route plan file reads through cloud proxy

* fix: route Display Cost runtime fetch through cloud proxy and ungate local metrics without session API key

* fix: handle WAITING_FOR_SANDBOX task status from cloud backends to prevent UI crash

* fix: re-expose Public Share in conversation menu for cloud backends

* fix: redirect to home when switching backends from a conversation page

* fix: hide cloud orgs the API key can't access in backend selector

* feat: support running multiple local agent-servers with shared persistence

* fix: lint

* fix: failing tests
2026-05-08 01:17:40 +07:00

92 lines
2.8 KiB
TypeScript

import { describe, it, expect, beforeEach } from "vitest";
import {
LOCAL_STORAGE_KEYS,
LoginMethod,
setLoginMethod,
getLoginMethod,
clearLoginData,
} from "#/utils/local-storage";
describe("local-storage utilities", () => {
beforeEach(() => {
localStorage.clear();
});
describe("Login method utilities", () => {
describe("setLoginMethod", () => {
it("stores the login method in local storage", () => {
setLoginMethod(LoginMethod.GITHUB);
expect(localStorage.getItem(LOCAL_STORAGE_KEYS.LOGIN_METHOD)).toBe(
"github",
);
});
it("stores different login methods correctly", () => {
setLoginMethod(LoginMethod.GITLAB);
expect(localStorage.getItem(LOCAL_STORAGE_KEYS.LOGIN_METHOD)).toBe(
"gitlab",
);
setLoginMethod(LoginMethod.BITBUCKET);
expect(localStorage.getItem(LOCAL_STORAGE_KEYS.LOGIN_METHOD)).toBe(
"bitbucket",
);
setLoginMethod(LoginMethod.AZURE_DEVOPS);
expect(localStorage.getItem(LOCAL_STORAGE_KEYS.LOGIN_METHOD)).toBe(
"azure_devops",
);
setLoginMethod(LoginMethod.BITBUCKET_DATA_CENTER);
expect(localStorage.getItem(LOCAL_STORAGE_KEYS.LOGIN_METHOD)).toBe(
"bitbucket_data_center",
);
});
it("overwrites previous login method", () => {
setLoginMethod(LoginMethod.GITHUB);
setLoginMethod(LoginMethod.GITLAB);
expect(localStorage.getItem(LOCAL_STORAGE_KEYS.LOGIN_METHOD)).toBe(
"gitlab",
);
});
});
describe("getLoginMethod", () => {
it("returns null when no login method is set", () => {
expect(getLoginMethod()).toBeNull();
});
it("returns the stored login method", () => {
localStorage.setItem(LOCAL_STORAGE_KEYS.LOGIN_METHOD, "github");
expect(getLoginMethod()).toBe(LoginMethod.GITHUB);
});
it("returns correct login method for all types", () => {
localStorage.setItem(LOCAL_STORAGE_KEYS.LOGIN_METHOD, "gitlab");
expect(getLoginMethod()).toBe(LoginMethod.GITLAB);
localStorage.setItem(LOCAL_STORAGE_KEYS.LOGIN_METHOD, "bitbucket");
expect(getLoginMethod()).toBe(LoginMethod.BITBUCKET);
localStorage.setItem(LOCAL_STORAGE_KEYS.LOGIN_METHOD, "azure_devops");
expect(getLoginMethod()).toBe(LoginMethod.AZURE_DEVOPS);
});
});
describe("clearLoginData", () => {
it("removes the login method from local storage", () => {
setLoginMethod(LoginMethod.GITHUB);
expect(getLoginMethod()).toBe(LoginMethod.GITHUB);
clearLoginData();
expect(getLoginMethod()).toBeNull();
});
it("does not throw when no login method is set", () => {
expect(() => clearLoginData()).not.toThrow();
});
});
});
});