Файли
openidea/src/features/debugger/__tests__/watchStorage.test.ts
T
Mansur Akhmadiтаmansur-akhmadi 3dd5c75fa0 feat(debugger): Remove All Watches in the Variables view's context menu (#4647)
A watch row's context menu in the Variables view gets Remove All Watches next to Remove Watch; it empties the project's stored watch list. Verified with debugger and locale vitest and typecheck; main merged in (locale conflict resolved).

Co-authored-by: mansur-akhmadi <[email protected]>
2026-11-20 10:15:56 +08:00

67 рядки
1.9 KiB
TypeScript

import { beforeEach, describe, expect, it } from "vitest";
import { addWatch, loadWatches, removeAllWatches, useDebug } from "../state";
const SHARED = "openidea.debugger.watches";
const of = (root: string) => `${SHARED}:${root}`;
const watches = () => useDebug.getState().watches;
beforeEach(() => {
localStorage.clear();
loadWatches(null);
});
describe("watch storage", () => {
it("loads a project's own watches", () => {
localStorage.setItem(of("/a"), '["x"]');
loadWatches("/a");
expect(watches()).toEqual(["x"]);
});
it("starts a project from the shared list once", () => {
localStorage.setItem(SHARED, '["legacy"]');
loadWatches("/b");
expect(watches()).toEqual(["legacy"]);
expect(localStorage.getItem(of("/b"))).toBe('["legacy"]');
expect(localStorage.getItem(SHARED)).toBe('["legacy"]');
});
it("keeps projects apart", () => {
loadWatches("/a");
addWatch("y");
loadWatches("/b");
expect(watches()).not.toContain("y");
loadWatches("/a");
expect(watches()).toContain("y");
});
it("an emptied list stays empty", () => {
localStorage.setItem(SHARED, '["legacy"]');
localStorage.setItem(of("/a"), "[]");
loadWatches("/a");
expect(watches()).toEqual([]);
});
it("Remove All Watches empties the project's stored list", () => {
localStorage.setItem(SHARED, '["legacy"]');
loadWatches("/a");
addWatch("x");
addWatch("y");
loadWatches("/b");
addWatch("z");
loadWatches("/a");
removeAllWatches();
expect(watches()).toEqual([]);
expect(localStorage.getItem(of("/a"))).toBe("[]");
loadWatches("/a");
expect(watches()).toEqual([]);
loadWatches("/b");
expect(watches()).toEqual(["legacy", "z"]);
});
it("without a project nothing is stored", () => {
loadWatches(null);
addWatch("z");
expect(localStorage.length).toBe(0);
});
});