|
1 | 1 | import { _add_explicit_edges_typed_link } from "src/graph/builders/explicit/typed_link"; |
2 | 2 | import { TFile } from "obsidian"; |
3 | | -import { describe, test } from "vitest"; |
| 3 | +import { describe, expect, test } from "vitest"; |
4 | 4 | import { make_all_files, make_plugin, mock_file } from "./helpers"; |
5 | 5 |
|
6 | 6 | function mock_tfile(path: string): TFile { |
@@ -111,3 +111,74 @@ describe("typed_link builder — Obsidian branch", () => { |
111 | 111 | }); |
112 | 112 | }); |
113 | 113 |
|
| 114 | +// ---- Body inline-field branch ---- |
| 115 | + |
| 116 | +/** Build a plugin whose cachedRead returns `body` for any file. */ |
| 117 | +function inline_plugin(body: string) { |
| 118 | + return make_plugin( |
| 119 | + { edge_fields: ["up", "down", "same"].map((l) => ({ label: l })) }, |
| 120 | + [], |
| 121 | + undefined, |
| 122 | + { cachedRead: async () => body }, |
| 123 | + ); |
| 124 | +} |
| 125 | + |
| 126 | +describe("typed_link builder — body inline fields", () => { |
| 127 | + test.each([ |
| 128 | + ["plain", "down:: [[Convolutions]]"], |
| 129 | + ["list marker", "- down:: [[Convolutions]]"], |
| 130 | + ["space before ::", "down :: [[Convolutions]]"], |
| 131 | + ["paren wrapper", "- (down:: [[Convolutions]])"], |
| 132 | + ["paren wrapper, no space", "- (down::[[Convolutions]])"], |
| 133 | + ["bracket wrapper", "- [down:: [[Convolutions]]]"], |
| 134 | + ])("detects inline field — %s", async (_label, line) => { |
| 135 | + const files = [mock_file("a.md", { links: [{ line: 0, link: "Convolutions" }] })]; |
| 136 | + const r = await _add_explicit_edges_typed_link( |
| 137 | + inline_plugin(line), |
| 138 | + make_all_files(files), |
| 139 | + ); |
| 140 | + expect(r.edges, `no edge for: ${line}`).toHaveLength(1); |
| 141 | + expect(r.edges[0]!.edge_type, line).toBe("down"); |
| 142 | + expect(r.edges[0]!.target).toBe("Convolutions.md"); |
| 143 | + }); |
| 144 | + |
| 145 | + test("field not in edge_fields → no edge", async (t) => { |
| 146 | + const files = [mock_file("a.md", { links: [{ line: 0, link: "X" }] })]; |
| 147 | + const r = await _add_explicit_edges_typed_link( |
| 148 | + inline_plugin("(unknown:: [[X]])"), |
| 149 | + make_all_files(files), |
| 150 | + ); |
| 151 | + t.expect(r.edges).toHaveLength(0); |
| 152 | + }); |
| 153 | + |
| 154 | + test("blockquote-wrapped field at line start", async (t) => { |
| 155 | + const line = "> [up:: [[Note]]]"; |
| 156 | + const files = [ |
| 157 | + mock_file("a.md", { |
| 158 | + links: [{ line: 0, col: line.indexOf("[[Note]]"), link: "Note" }], |
| 159 | + }), |
| 160 | + ]; |
| 161 | + const r = await _add_explicit_edges_typed_link( |
| 162 | + inline_plugin(line), |
| 163 | + make_all_files(files), |
| 164 | + ); |
| 165 | + expect(r.edges).toHaveLength(1); |
| 166 | + expect(r.edges[0]!.edge_type).toBe("up"); |
| 167 | + }); |
| 168 | + |
| 169 | + test("wrapped field mid-sentence (not at line start)", async (t) => { |
| 170 | + const line = "This other note is a child of (up:: [[Note]])."; |
| 171 | + const files = [ |
| 172 | + mock_file("a.md", { |
| 173 | + links: [{ line: 0, col: line.indexOf("[[Note]]"), link: "Note" }], |
| 174 | + }), |
| 175 | + ]; |
| 176 | + const r = await _add_explicit_edges_typed_link( |
| 177 | + inline_plugin(line), |
| 178 | + make_all_files(files), |
| 179 | + ); |
| 180 | + expect(r.edges).toHaveLength(1); |
| 181 | + expect(r.edges[0]!.edge_type).toBe("up"); |
| 182 | + }); |
| 183 | +}); |
| 184 | + |
0 commit comments