4cddfcf2f3
Backend Tests / Tests (other) (push) Failing after 1s
Backend Tests / Static Checks (push) Failing after 2s
Backend Tests / Tests (internal) (push) Failing after 2s
Backend Tests / Tests (server) (push) Failing after 1s
Backend Tests / Tests (store) (push) Failing after 1s
Build Canary Image / build-frontend (push) Failing after 1s
Frontend Tests / Lint (push) Failing after 1s
Build Canary Image / build-push (linux/amd64) (push) Has been skipped
Build Canary Image / build-push (linux/arm64) (push) Has been skipped
Build Canary Image / merge (push) Has been skipped
Frontend Tests / Build (push) Failing after 1s
Release Please / release-please (push) Failing after 0s
Proto Linter / Lint Protos (push) Failing after 2s
58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { cacheService } from "@/components/MemoEditor/services/cacheService";
|
|
|
|
describe("memo editor cache", () => {
|
|
beforeEach(() => {
|
|
const storage = new Map<string, string>();
|
|
vi.stubGlobal("localStorage", {
|
|
getItem: vi.fn((key: string) => storage.get(key) ?? null),
|
|
setItem: vi.fn((key: string, value: string) => storage.set(key, value)),
|
|
removeItem: vi.fn((key: string) => storage.delete(key)),
|
|
});
|
|
cacheService.clearAll();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it("stores draft content", () => {
|
|
const key = cacheService.key("users/steven", "home-memo-editor");
|
|
|
|
cacheService.saveNow(key, "- [x] Draft task");
|
|
|
|
expect(cacheService.load(key)).toBe("- [x] Draft task");
|
|
});
|
|
|
|
it("removes empty draft content instead of caching it", () => {
|
|
const key = cacheService.key("users/steven", "home-memo-editor");
|
|
|
|
cacheService.saveNow(key, "");
|
|
|
|
expect(cacheService.load(key)).toBe("");
|
|
});
|
|
|
|
it("loads content from previously structured draft entries", () => {
|
|
const key = cacheService.key("users/steven", "home-memo-editor");
|
|
localStorage.setItem(key, JSON.stringify({ kind: "memos.editor-cache", version: 1, content: "- [ ] migrated task" }));
|
|
|
|
expect(cacheService.load(key)).toBe("- [ ] migrated task");
|
|
});
|
|
|
|
it("keeps raw JSON markdown drafts intact", () => {
|
|
const key = cacheService.key("users/steven", "home-memo-editor");
|
|
const jsonDraft = '{"content":"not a cache envelope"}';
|
|
localStorage.setItem(key, jsonDraft);
|
|
|
|
expect(cacheService.load(key)).toBe(jsonDraft);
|
|
});
|
|
|
|
it("keeps structured-looking drafts without a supported version intact", () => {
|
|
const key = cacheService.key("users/steven", "home-memo-editor");
|
|
const jsonDraft = JSON.stringify({ kind: "memos.editor-cache", content: "not a supported envelope" });
|
|
localStorage.setItem(key, jsonDraft);
|
|
|
|
expect(cacheService.load(key)).toBe(jsonDraft);
|
|
});
|
|
});
|