mirror of
https://github.com/murashit/codex-panel.git
synced 2026-07-22 17:30:31 +00:00
35 lines
1.6 KiB
TypeScript
35 lines
1.6 KiB
TypeScript
import type { Vault } from "obsidian";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { createObsidianVaultMarkdownDestination } from "../../../src/shared/obsidian/vault-write-destination.obsidian";
|
|
|
|
describe("createObsidianVaultMarkdownDestination", () => {
|
|
it("uses normalized Vault paths for existence checks, folder creation, and file writes", async () => {
|
|
const vault = vaultMock(new Set(["Codex Archives/Café"]));
|
|
const destination = createObsidianVaultMarkdownDestination(vault);
|
|
|
|
await expect(destination.exists("//Codex\u00a0Archives//Cafe\u0301//")).resolves.toBe(true);
|
|
await destination.createFolder("//Codex\u00a0Archives//New//");
|
|
await destination.createMarkdownFile("//Codex\u00a0Archives//Cafe\u0301//Thread.md", "body");
|
|
|
|
expect(vault.getAbstractFileByPath).toHaveBeenCalledWith("Codex Archives/Café");
|
|
expect(vault.createFolder).toHaveBeenCalledWith("Codex Archives/New");
|
|
expect(vault.create).toHaveBeenCalledWith("Codex Archives/Café/Thread.md", "body");
|
|
});
|
|
});
|
|
|
|
function vaultMock(existingPaths: Set<string>): Vault & {
|
|
getAbstractFileByPath: ReturnType<typeof vi.fn>;
|
|
createFolder: ReturnType<typeof vi.fn>;
|
|
create: ReturnType<typeof vi.fn>;
|
|
} {
|
|
return {
|
|
getAbstractFileByPath: vi.fn((path: string) => (existingPaths.has(path) ? { path } : null)),
|
|
createFolder: vi.fn(async (path: string) => ({ path })),
|
|
create: vi.fn(async (path: string) => ({ path })),
|
|
} as unknown as Vault & {
|
|
getAbstractFileByPath: ReturnType<typeof vi.fn>;
|
|
createFolder: ReturnType<typeof vi.fn>;
|
|
create: ReturnType<typeof vi.fn>;
|
|
};
|
|
}
|