Skip to content

Commit 636671f

Browse files
committed
test: narrow new-note workflow capabilities
1 parent bdace2d commit 636671f

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

new-note-workflow.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ import { renderTagFolderTemplateVariables } from "./new-note-template";
44

55
export const NEW_NOTE_TEMPLATE_INTERACTION_ID = "new-note-template";
66

7+
/** UI capability required by the new-note template workflow. */
8+
export type NewNoteTemplateUi = Pick<UiInteractions, "pickOne">;
9+
10+
/** Vault text capability required while populating a new note. */
11+
export type NewNoteVaultTextAccess = Pick<
12+
VaultTextAccess,
13+
"readText" | "modifyText" | "appendText"
14+
>;
15+
716
/** Template identity and labels exposed to the application workflow. */
817
export interface NewNoteTemplateChoice {
918
/** Vault-relative template path. */
@@ -26,7 +35,7 @@ export function filterNewNoteTemplateChoices(
2635

2736
/** Requests one captured template by identity, returns `null` when dismissed, or `undefined` when empty. */
2837
export async function chooseNewNoteTemplate(
29-
ui: UiInteractions,
38+
ui: NewNoteTemplateUi,
3039
templates: readonly NewNoteTemplateChoice[],
3140
): Promise<NewNoteTemplateChoice | null | undefined> {
3241
if (templates.length == 0) return undefined;
@@ -44,7 +53,7 @@ export async function chooseNewNoteTemplate(
4453
/** Inputs owned by TagFolder while populating a newly created note. */
4554
export interface PopulateNewNoteOptions {
4655
/** Injectable path-based Vault text capability. */
47-
readonly vault: VaultTextAccess;
56+
readonly vault: NewNoteVaultTextAccess;
4857
/** Vault-relative path of the already created note. */
4958
readonly notePath: string;
5059
/** Selected template, or `null` to apply tags without a template. */

tests/new-note-workflow.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,34 @@ describe("new-note workflow", () => {
127127
expect(applyFrontmatterTags).toHaveBeenCalledWith(["project/client"]);
128128
expect(vault.transcript).toEqual([]);
129129
});
130+
131+
it("propagates a Vault write failure without changing the note", async () => {
132+
const writeFailure = new Error("Vault write failed");
133+
const vault = createVaultTextTestHarness({
134+
files: {
135+
[template.path]: "# {{tagName}}",
136+
"Untitled.md": "Original",
137+
},
138+
onOperation: (operation) => {
139+
if (operation.kind === "modifyText") throw writeFailure;
140+
},
141+
});
142+
143+
await expect(populateNewNote({
144+
vault: vault.vault,
145+
notePath: "Untitled.md",
146+
template,
147+
expandedTagsAll: ["project/client"],
148+
expandedTags: "#project/client",
149+
frontmatterTags: ["project/client"],
150+
useFrontmatterTags: false,
151+
applyFrontmatterTags: vi.fn(),
152+
})).rejects.toBe(writeFailure);
153+
154+
expect(vault.transcript).toEqual([
155+
{ kind: "readText", path: template.path },
156+
{ kind: "modifyText", path: "Untitled.md", content: "# project/client" },
157+
]);
158+
expect(vault.getFile("Untitled.md")).toBe("Original");
159+
});
130160
});

0 commit comments

Comments
 (0)