Files
ihasmail/web/src/lib/input/__tests__/swipe.test.ts
T
jcoffey-dev bd6a605d61 Group six more clusters out of web/src/lib
Takes the flat module count from 66 to 42, continuing what admin/ and
calendar/ started.

  lib/mailbox/  archiveDate, emptyFolder, folderMove, labelTree,
                mailboxName, mailboxRoute
  lib/sieve/    sieve, sieveApply, sieveFolders
  lib/input/    keyboard, swipe, touch, listSelection, dropUpload
  lib/notify/   notify, webpush, webpushEnable
  lib/sw/       swCache, swFacts, staleBuild
  lib/text/     html, markdown, text, emlName

FOUR THINGS THE FILENAMES GET WRONG, each checked by reading the file
rather than trusting what it is called:

  - appFolder is not a mailbox. It is the `ihasmail` folder in JMAP
    *Files*, where the client keeps signature images and synced settings.
    It stays flat.
  - format holds no formatting of text. It re-exports the date and clock
    formatters, so it belongs with dates/datetime, not with text/.
  - preview is the file viewer deciding what it can show without
    downloading, and source is where to point someone asking for this
    instance's AGPL source. Neither is about text.
  - notify is not Web Push. It is the tab title, the favicon badge and
    the new-mail sound -- in-app notification, which is why it sits with
    webpush rather than under sw/ with the service worker's own concerns.

threadScroll stays flat too: it decides where a conversation opens, which
is view state rather than a gesture, and input/ is honest only if
everything in it interprets something the reader did.

No behavior change. Almost every reference was on the @/ alias; eight
relative imports in files that did not move, or that moved away from a
sibling, needed rewriting by hand.
2026-09-15 23:17:50 -07:00

64 lines
3.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { SWIPE_CHOICES, describeSwipe, type SwipeAction } from "../swipe";
/**
* A swipe names what it is about to do on a colored strip the reader sees for
* about a third of a second before letting go. These check that the name is
* true in the folder it is being read in — which is the whole reason the
* descriptor exists rather than a fixed label per setting.
*/
const inbox = { role: "inbox", unread: false, starred: false };
describe("describeSwipe", () => {
it("offers nothing for a direction turned off", () => {
expect(describeSwipe("none", inbox)).toBe(null);
});
it("refuses to archive out of the archive", () => {
expect(describeSwipe("archive", { ...inbox, role: "archive" })).toBe(null);
expect(describeSwipe("archive", inbox)).toMatchObject({ label: "Archive", removes: true });
});
it("says out loud that a delete from Deleted Items is permanent", () => {
expect(describeSwipe("delete", inbox)?.label).toBe("Delete");
expect(describeSwipe("delete", { ...inbox, role: "trash" })?.label).toBe("Delete forever");
});
it("turns the spam action around inside the junk folder", () => {
expect(describeSwipe("spam", inbox)).toMatchObject({ label: "Report spam", icon: "spam" });
expect(describeSwipe("spam", { ...inbox, role: "junk" })).toMatchObject({ label: "Not spam", icon: "not-spam" });
});
it("has no opinion on whether your own mail is spam", () => {
expect(describeSwipe("spam", { ...inbox, role: "drafts" })).toBe(null);
expect(describeSwipe("spam", { ...inbox, role: "sent" })).toBe(null);
});
it("names the state a toggle is about to set, and carries it", () => {
expect(describeSwipe("read", { ...inbox, unread: true })).toMatchObject({ label: "Mark as read", icon: "read", on: true });
expect(describeSwipe("read", { ...inbox, unread: false })).toMatchObject({ label: "Mark as unread", icon: "unread", on: false });
expect(describeSwipe("star", { ...inbox, starred: false })).toMatchObject({ label: "Add star", on: true });
expect(describeSwipe("star", { ...inbox, starred: true })).toMatchObject({ label: "Remove star", on: false });
});
it("brings a row home for the actions that open something instead", () => {
// The row has to be back under the finger before the folder picker covers
// the list, or it is still hanging half-open when the picker closes again.
expect(describeSwipe("move", inbox)).toMatchObject({ label: "Move to…", removes: false });
for (const action of ["archive", "delete", "spam"] as const) {
expect(describeSwipe(action, inbox)?.removes).toBe(true);
}
});
it("can describe everything the settings picker offers", () => {
// A choice the picker offers and the list cannot describe is a direction
// that silently does nothing — the one failure nobody would report.
for (const { value } of SWIPE_CHOICES) {
const d = describeSwipe(value as SwipeAction, inbox);
if (value === "none") expect(d).toBe(null);
else expect(d?.label).toBeTruthy();
}
});
});