Skip to content
Source
Sign inSign up
fuko/trytanstackdb.com
Open History to see the last commit

section-progress.test.ts

42 lines1.5 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { matchesAppAction } from "@/lib/app-actions";
4import type { AppActionEvent } from "@/lib/app-actions";
5​
6import { sectionsDoneBy } from "./section-progress";
7​
8const rejectedRename: AppActionEvent = {
9 type: "folder.renamed",
10 folderId: "work",
11 name: "Personal",
12 status: "rolled-back",
13};
14​
15describe("matchesAppAction", () => {
16 it("matches on every given field", () => {
17 expect(matchesAppAction({ type: "folder.renamed" }, rejectedRename)).toBe(true);
18 expect(matchesAppAction({ status: "rolled-back" }, rejectedRename)).toBe(true);
19 expect(matchesAppAction({ type: "folder.renamed", status: "confirmed" }, rejectedRename)).toBe(
20 false,
21 );
22 expect(matchesAppAction({ type: "note.edited" }, rejectedRename)).toBe(false);
23 });
24});
25​
26describe("sectionsDoneBy", () => {
27 it("maps app actions to the guide sections they complete", () => {
28 expect(sectionsDoneBy({ type: "note.opened", noteId: "n", status: "applied" })).toEqual([
29 "introduction",
30 ]);
31 expect(
32 sectionsDoneBy({ type: "folder.opened", folderId: "work", smart: false, status: "applied" }),
33 ).toEqual(["collections"]);
34 expect(
35 sectionsDoneBy({ type: "folder.opened", folderId: "all", smart: true, status: "applied" }),
36 ).toEqual(["live-queries"]);
37 expect(sectionsDoneBy({ type: "note.edited", noteId: "n", status: "applied" })).toEqual([
38 "optimistic-updates",
39 ]);
40 expect(sectionsDoneBy(rejectedRename)).toEqual(["rollbacks"]);
41 });
42});