(frontmatterByPath: FrontmatterMap, sortOrderField = "tasknotes_manual_order")
| 36 | } |
| 37 | |
| 38 | function createPlugin(frontmatterByPath: FrontmatterMap, sortOrderField = "tasknotes_manual_order") { |
| 39 | const processFrontMatter = jest.fn(async (file: TFile, updater: (frontmatter: any) => void) => { |
| 40 | const frontmatter = frontmatterByPath[file.path]; |
| 41 | if (!frontmatter) { |
| 42 | throw new Error(`Missing frontmatter for ${file.path}`); |
| 43 | } |
| 44 | updater(frontmatter); |
| 45 | }); |
| 46 | |
| 47 | return { |
| 48 | settings: { |
| 49 | fieldMapping: { |
| 50 | sortOrder: sortOrderField, |
| 51 | }, |
| 52 | }, |
| 53 | app: { |
| 54 | vault: { |
| 55 | getMarkdownFiles: jest.fn(() => Object.keys(frontmatterByPath).map((path) => new TFile(path))), |
| 56 | getAbstractFileByPath: jest.fn((path: string) => ( |
| 57 | Object.prototype.hasOwnProperty.call(frontmatterByPath, path) ? new TFile(path) : null |
| 58 | )), |
| 59 | }, |
| 60 | metadataCache: { |
| 61 | getFileCache: jest.fn((file: TFile) => ({ |
| 62 | frontmatter: frontmatterByPath[file.path], |
| 63 | })), |
| 64 | }, |
| 65 | fileManager: { |
| 66 | processFrontMatter, |
| 67 | }, |
| 68 | }, |
| 69 | } as any; |
| 70 | } |
| 71 | |
| 72 | describe("sortOrderUtils", () => { |
| 73 | it("writes the configured sort-order field when applying a plan", async () => { |
no outgoing calls
no test coverage detected