mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-11-13 12:13:42 +01:00
The trash button and its hotkey open a confirm dialog instead of a dropdown. Its Don't ask again checkbox saves a preference that Settings turns back on under Traffic, as Confirm before clearing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import { createStore } from "jotai";
|
|
import { beforeEach, describe, expect, test, vi } from "vite-plus/test";
|
|
import { clearFlowsAction, confirmClearFlowsAtom } from "./clearFlows";
|
|
|
|
describe("clearFlowsAction", () => {
|
|
test("asks first while the preference is on", () => {
|
|
expect(clearFlowsAction({ total: 3, locked: false, confirm: true })).toBe("confirm");
|
|
});
|
|
|
|
test("clears at once once asking is turned off", () => {
|
|
expect(clearFlowsAction({ total: 3, locked: false, confirm: false })).toBe("clear");
|
|
});
|
|
|
|
test("does nothing with none to clear or traffic locked, whatever the preference", () => {
|
|
for (const confirm of [true, false]) {
|
|
expect(clearFlowsAction({ total: 0, locked: false, confirm })).toBe("disabled");
|
|
expect(clearFlowsAction({ total: 3, locked: true, confirm })).toBe("disabled");
|
|
}
|
|
});
|
|
});
|
|
|
|
/** The preference as a new window reads it, once something shows it */
|
|
function mounted() {
|
|
const store = createStore();
|
|
const unsub = store.sub(confirmClearFlowsAtom, () => {});
|
|
const value = store.get(confirmClearFlowsAtom);
|
|
unsub();
|
|
return value;
|
|
}
|
|
|
|
describe("confirmClearFlowsAtom", () => {
|
|
let saved: Map<string, string>;
|
|
|
|
beforeEach(() => {
|
|
saved = new Map();
|
|
vi.stubGlobal("localStorage", {
|
|
getItem: (k: string) => saved.get(k) ?? null,
|
|
setItem: (k: string, v: string) => void saved.set(k, v),
|
|
removeItem: (k: string) => void saved.delete(k),
|
|
});
|
|
});
|
|
|
|
test("is on by default", () => {
|
|
expect(createStore().get(confirmClearFlowsAtom)).toBe(true);
|
|
});
|
|
|
|
test("keeps Don't ask again for later launches, until Settings turns it back on", () => {
|
|
createStore().set(confirmClearFlowsAtom, false);
|
|
expect(saved.get("confirm_clear_flows")).toBe("false");
|
|
expect(mounted()).toBe(false);
|
|
|
|
createStore().set(confirmClearFlowsAtom, true);
|
|
expect(saved.get("confirm_clear_flows")).toBe("true");
|
|
expect(mounted()).toBe(true);
|
|
});
|
|
});
|