Files
ihasmail/web/src/store/__tests__/app-folder-hidden.test.ts
T
jcoffey-dev 0a9218f622 Keep settings with the account, not the browser
Every setting lived in localStorage, so none of them travelled between
devices. The sharpest edge is the default identity: with none set the
address that sorts first wins, so mail goes out from an address the
recipient may not recognise -- and someone who sets it at work finds it
unset at home, with nothing to say so. Reported in #54.

They now live in a settings.json in the account's own JMAP Files, beside
the signature images already kept there. ihasmail itself stays stateless:
no volume, no database, nothing to back up separately, and the settings
are covered by whatever backs up the mail store.

localStorage stays as a cache rather than the source of truth, so the
first frame is painted from it and the file corrects it a moment later.
A private window has no cache and shows defaults for that one frame,
which is the trade for not gating the whole app on a network round trip.

Not everything should follow the account. A list-pane width picked on a
27" monitor is wrong on a laptop, and the notification toggles track a
permission the browser grants per-device, so claiming it elsewhere would
be a lie. Those stay local, written as a list of exceptions so that a
setting added later syncs by default -- which is what adding one almost
always means.

Writes are coalesced: update() fires on every frame of a splitter drag,
so a change waits 3s and the newest value wins. A tab going away flushes
first, as does signing out, so a setting changed seconds before either
is not lost.

The ihasmail folder is now hidden from the Files view, contents and all.
Hiding the folder alone would have been worse than showing it: the tree
attaches a node whose parent is missing to the root, so the signature
images would have spilled into the top level as if the user had put them
there. Those images have been visible since signatures shipped.

Requires 0.16 -- FileNode/query cannot see directories before that. On
0.15 settings stay local exactly as they were.

Verified against the mock end to end: folder create, blob upload, node
create, read back, update, re-read. Not yet exercised against the live
0.16.19.
2026-08-26 08:19:57 -07:00

54 lines
2.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { withoutAppFolder } from "../files";
import type { FileNode } from "@/jmap/types";
/**
* The `ihasmail` folder holds signature images and the synced settings file.
* They are real nodes in the account — that is what makes them travel — but
* they are the client's housekeeping, so Files does not show them.
*
* Hiding the folder alone is worse than showing it: the tree attaches a node
* whose parent is missing to the root, so the signature images would spill out
* into the top level looking like the user's own files.
*/
const node = (id: string, name: string, parentId: string | null, nodeType: "file" | "directory"): FileNode =>
({ id, name, parentId, nodeType, size: null, blobId: null, type: null }) as unknown as FileNode;
describe("hiding the client's folder", () => {
it("removes the folder and everything in it", () => {
const nodes = [
node("f1", "ihasmail", null, "directory"),
node("f2", "signature-1.html", "f1", "file"),
node("f3", "settings.json", "f1", "file"),
node("d1", "Documents", null, "directory"),
node("d2", "notes.txt", "d1", "file"),
];
expect(withoutAppFolder(nodes).map((n) => n.id)).toEqual(["d1", "d2"]);
});
it("removes nested contents, not just direct children", () => {
const nodes = [
node("f1", "ihasmail", null, "directory"),
node("f2", "images", "f1", "directory"),
node("f3", "logo.png", "f2", "file"),
];
expect(withoutAppFolder(nodes)).toEqual([]);
});
it("leaves a folder of the same name that the user made inside another", () => {
const nodes = [node("d1", "Projects", null, "directory"), node("d2", "ihasmail", "d1", "directory")];
expect(withoutAppFolder(nodes).map((n) => n.id)).toEqual(["d1", "d2"]);
});
it("leaves a top-level file that happens to be called ihasmail", () => {
const nodes = [node("x1", "ihasmail", null, "file")];
expect(withoutAppFolder(nodes).map((n) => n.id)).toEqual(["x1"]);
});
it("returns the list untouched when there is no such folder", () => {
const nodes = [node("d1", "Documents", null, "directory")];
expect(withoutAppFolder(nodes)).toBe(nodes);
});
});