@@ -5,8 +5,9 @@ import type ICaptureChoice from "../types/choices/ICaptureChoice";
55import type { IChoiceExecutor } from "../IChoiceExecutor" ;
66import { isFolder , openFile } from "../utilityObsidian" ;
77
8- const { setUseSelectionAsCaptureValueMock } = vi . hoisted ( ( ) => ( {
8+ const { setUseSelectionAsCaptureValueMock, setTitleMock } = vi . hoisted ( ( ) => ( {
99 setUseSelectionAsCaptureValueMock : vi . fn ( ) ,
10+ setTitleMock : vi . fn ( ) ,
1011} ) ) ;
1112
1213vi . mock ( "../formatters/captureChoiceFormatter" , ( ) => ( {
@@ -15,7 +16,9 @@ vi.mock("../formatters/captureChoiceFormatter", () => ({
1516 setUseSelectionAsCaptureValue ( value : boolean ) {
1617 setUseSelectionAsCaptureValueMock ( value ) ;
1718 }
18- setTitle ( ) { }
19+ setTitle ( value : string ) {
20+ setTitleMock ( value ) ;
21+ }
1922 setDestinationFile ( ) { }
2023 setDestinationSourcePath ( ) { }
2124 async formatContentOnly ( content : string ) {
@@ -130,6 +133,7 @@ const createExecutor = (): IChoiceExecutor => ({
130133describe ( "CaptureChoiceEngine selection-as-value resolution" , ( ) => {
131134 beforeEach ( ( ) => {
132135 setUseSelectionAsCaptureValueMock . mockClear ( ) ;
136+ setTitleMock . mockClear ( ) ;
133137 vi . mocked ( openFile ) . mockClear ( ) ;
134138 } ) ;
135139
@@ -214,6 +218,7 @@ describe("CaptureChoiceEngine selection-as-value resolution", () => {
214218describe ( "CaptureChoiceEngine capture target resolution" , ( ) => {
215219 beforeEach ( ( ) => {
216220 vi . mocked ( isFolder ) . mockReset ( ) ;
221+ setTitleMock . mockClear ( ) ;
217222 } ) ;
218223
219224 it ( "treats folder path without trailing slash as folder when folder exists" , ( ) => {
@@ -292,4 +297,40 @@ describe("CaptureChoiceEngine capture target resolution", () => {
292297
293298 expect ( result ) . toBe ( "Boards/Map.canvas" ) ;
294299 } ) ;
300+
301+ it ( "uses extensionless title for created .base/.canvas capture files" , async ( ) => {
302+ const app = createApp ( ) as any ;
303+ app . vault . read = vi . fn ( async ( ) => "" ) ;
304+
305+ const engine = new CaptureChoiceEngine (
306+ app ,
307+ { settings : { useSelectionAsCaptureValue : false } } as any ,
308+ createChoice ( {
309+ createFileIfItDoesntExist : {
310+ enabled : true ,
311+ createWithTemplate : false ,
312+ template : "" ,
313+ } ,
314+ } ) ,
315+ createExecutor ( ) ,
316+ ) ;
317+
318+ ( engine as any ) . createFileWithInput = vi . fn ( async ( path : string ) => ( {
319+ path,
320+ basename : path . split ( "/" ) . pop ( ) ?. replace ( / \. ( b a s e | c a n v a s ) $ / i, "" ) ?? "" ,
321+ extension : path . endsWith ( ".base" ) ? "base" : "canvas" ,
322+ } ) ) ;
323+
324+ await ( engine as any ) . onCreateFileIfItDoesntExist (
325+ "Boards/Kanban.base" ,
326+ "capture" ,
327+ ) ;
328+ await ( engine as any ) . onCreateFileIfItDoesntExist (
329+ "Boards/Map.canvas" ,
330+ "capture" ,
331+ ) ;
332+
333+ expect ( setTitleMock ) . toHaveBeenCalledWith ( "Kanban" ) ;
334+ expect ( setTitleMock ) . toHaveBeenCalledWith ( "Map" ) ;
335+ } ) ;
295336} ) ;
0 commit comments