| 111 | }; |
| 112 | |
| 113 | export const createTestNote = (params: { |
| 114 | uri: string; |
| 115 | title?: string; |
| 116 | links?: Array<{ slug: string; definitionUrl?: string } | { to: string }>; |
| 117 | tags?: string[]; |
| 118 | aliases?: string[]; |
| 119 | sections?: string[]; |
| 120 | root?: URI; |
| 121 | type?: string; |
| 122 | properties?: Record<string, unknown>; |
| 123 | }): Resource => { |
| 124 | const root = params.root ?? URI.file('/'); |
| 125 | return { |
| 126 | uri: root.resolve(params.uri), |
| 127 | type: params.type ?? 'note', |
| 128 | properties: params.properties ?? {}, |
| 129 | title: params.title ?? strToUri(params.uri).getBasename(), |
| 130 | sections: |
| 131 | params.sections?.map(label => ({ |
| 132 | label, |
| 133 | level: 1, |
| 134 | range: Range.create(0, 0, 1, 0), |
| 135 | })) ?? [], |
| 136 | blocks: [], |
| 137 | tags: |
| 138 | params.tags?.map(t => ({ |
| 139 | label: t, |
| 140 | range: Range.create(0, 0, 0, 0), |
| 141 | })) ?? [], |
| 142 | aliases: |
| 143 | params.aliases?.map(a => ({ |
| 144 | title: a, |
| 145 | range: Range.create(0, 0, 0, 0), |
| 146 | })) ?? [], |
| 147 | links: params.links |
| 148 | ? params.links.map((link, index) => { |
| 149 | const range = Range.create( |
| 150 | position.start.line + index, |
| 151 | position.start.character, |
| 152 | position.start.line + index, |
| 153 | position.end.character |
| 154 | ); |
| 155 | return 'slug' in link |
| 156 | ? { |
| 157 | type: 'wikilink', |
| 158 | range: range, |
| 159 | rawText: `[[${link.slug}]]`, |
| 160 | isEmbed: false, |
| 161 | definition: link.definitionUrl |
| 162 | ? { |
| 163 | label: link.slug, |
| 164 | url: link.definitionUrl, |
| 165 | range: Range.create(0, 0, 0, 0), |
| 166 | } |
| 167 | : link.slug, |
| 168 | } |
| 169 | : { |
| 170 | type: 'link', |