@@ -10,7 +10,12 @@ import {
10
10
showInEditor ,
11
11
} from '../../test/test-utils-vscode' ;
12
12
import { fromVsCodeUri } from '../../utils/vsc-utils' ;
13
- import { CREATE_NOTE_COMMAND } from './create-note' ;
13
+ import { CREATE_NOTE_COMMAND , createNote } from './create-note' ;
14
+ import { Location } from '../../core/model/location' ;
15
+ import { Range } from '../../core/model/range' ;
16
+ import { ResourceLink } from '../../core/model/note' ;
17
+ import { MarkdownResourceProvider } from '../../core/services/markdown-provider' ;
18
+ import { createMarkdownParser } from '../../core/services/markdown-parser' ;
14
19
15
20
describe ( 'create-note command' , ( ) => {
16
21
afterEach ( ( ) => {
@@ -194,8 +199,14 @@ describe('factories', () => {
194
199
describe ( 'forPlaceholder' , ( ) => {
195
200
it ( 'adds the .md extension to notes created for placeholders' , async ( ) => {
196
201
await closeEditors ( ) ;
202
+ const link : ResourceLink = {
203
+ type : 'wikilink' ,
204
+ rawText : '[[my-placeholder]]' ,
205
+ range : Range . create ( 0 , 0 , 0 , 0 ) ,
206
+ isEmbed : false ,
207
+ } ;
197
208
const command = CREATE_NOTE_COMMAND . forPlaceholder (
198
- 'my-placeholder' ,
209
+ Location . forObjectWithRange ( URI . file ( '' ) , link ) ,
199
210
'.md'
200
211
) ;
201
212
await commands . executeCommand ( command . name , command . params ) ;
@@ -204,5 +215,41 @@ describe('factories', () => {
204
215
expect ( doc . uri . path ) . toMatch ( / m y - p l a c e h o l d e r .m d $ / ) ;
205
216
expect ( doc . getText ( ) ) . toMatch ( / ^ # m y - p l a c e h o l d e r / ) ;
206
217
} ) ;
218
+
219
+ it ( 'replaces the original placeholder based on the new note identifier (#1327)' , async ( ) => {
220
+ await closeEditors ( ) ;
221
+ const templateA = await createFile (
222
+ `---
223
+ foam_template:
224
+ name: 'Example Template'
225
+ description: 'An example for reproducing a bug'
226
+ filepath: '$FOAM_SLUG-world.md'
227
+ ---` ,
228
+ [ '.foam' , 'templates' , 'template-a.md' ]
229
+ ) ;
230
+
231
+ const noteA = await createFile ( `this is my [[hello]]` ) ;
232
+
233
+ const parser = createMarkdownParser ( ) ;
234
+ const res = parser . parse ( noteA . uri , noteA . content ) ;
235
+
236
+ const command = CREATE_NOTE_COMMAND . forPlaceholder (
237
+ Location . forObjectWithRange ( noteA . uri , res . links [ 0 ] ) ,
238
+ '.md' ,
239
+ {
240
+ templatePath : templateA . uri . path ,
241
+ }
242
+ ) ;
243
+ const results : Awaited < ReturnType < typeof createNote > > =
244
+ await commands . executeCommand ( command . name , command . params ) ;
245
+ expect ( results . didCreateFile ) . toBeTruthy ( ) ;
246
+ expect ( results . uri . path . endsWith ( 'hello-world.md' ) ) . toBeTruthy ( ) ;
247
+
248
+ const newNoteDoc = window . activeTextEditor . document ;
249
+ expect ( newNoteDoc . uri . path ) . toMatch ( / h e l l o - w o r l d .m d $ / ) ;
250
+
251
+ const { doc } = await showInEditor ( noteA . uri ) ;
252
+ expect ( doc . getText ( ) ) . toEqual ( `this is my [[hello-world]]` ) ;
253
+ } ) ;
207
254
} ) ;
208
255
} ) ;
0 commit comments