88 addDays ,
99 daysBetween ,
1010 findAdjacentEntry ,
11+ getAdjacentWeekInput ,
1112 resolveAnchor ,
1213 stripTime ,
1314} from '../../actions/navigation' ;
@@ -29,7 +30,14 @@ async function seedEntry(base: string, year: number, month: number, day: number,
2930async function buildCtrl ( tmpBase : string ) : Promise < { ctrl : J . Util . Ctrl ; logger : TestLogger } > {
3031 const config = vscode . workspace . getConfiguration ( 'journal' ) ;
3132 await config . update ( 'base' , tmpBase , vscode . ConfigurationTarget . Workspace ) ;
32- const refreshed = vscode . workspace . getConfiguration ( 'journal' ) ;
33+ // On CI the config write is async; poll until the value is visible.
34+ const deadline = Date . now ( ) + 3000 ;
35+ let refreshed : vscode . WorkspaceConfiguration ;
36+ do {
37+ refreshed = vscode . workspace . getConfiguration ( 'journal' ) ;
38+ if ( refreshed . get < string > ( 'base' ) === tmpBase ) { break ; }
39+ await new Promise < void > ( r => setTimeout ( r , 50 ) ) ;
40+ } while ( Date . now ( ) < deadline ) ;
3341 const ctrl = new J . Util . Ctrl ( refreshed ) ;
3442 const logger = new TestLogger ( false ) ;
3543 ctrl . logger = logger ;
@@ -365,4 +373,65 @@ suite('Issue #144 — Open Previous / Open Next navigation', () => {
365373 assert . ok ( prev === null || prev === undefined , `expected null at start of history, got ${ prev } ` ) ;
366374 } ) ;
367375 } ) ;
376+
377+ suite ( 'getAdjacentWeekInput (#200)' , ( ) => {
378+ let originalBase : string | undefined ;
379+ let tmpBase : string ;
380+ let ctrl : J . Util . Ctrl ;
381+
382+ setup ( async ( ) => {
383+ const config = vscode . workspace . getConfiguration ( 'journal' ) ;
384+ originalBase = config . get < string > ( 'base' ) ;
385+ tmpBase = path . join ( os . tmpdir ( ) , `issue200-week-${ Date . now ( ) } ` ) ;
386+ await vscode . workspace . fs . createDirectory ( vscode . Uri . file ( tmpBase ) ) ;
387+ ( { ctrl } = await buildCtrl ( tmpBase ) ) ;
388+ } ) ;
389+
390+ teardown ( async ( ) => {
391+ const config = vscode . workspace . getConfiguration ( 'journal' ) ;
392+ await config . update ( 'base' , originalBase , vscode . ConfigurationTarget . Workspace ) ;
393+ try { await vscode . workspace . fs . delete ( vscode . Uri . file ( tmpBase ) , { recursive : true } ) ; } catch { /* ignore */ }
394+ await vscode . commands . executeCommand ( 'workbench.action.closeAllEditors' ) ;
395+ } ) ;
396+
397+ async function seedWeeklyFile ( base : string , year : number , week : number ) : Promise < string > {
398+ const yearDir = vscode . Uri . file ( path . join ( base , String ( year ) . padStart ( 4 , '0' ) ) ) ;
399+ await vscode . workspace . fs . createDirectory ( yearDir ) ;
400+ const file = vscode . Uri . file ( path . join ( base , String ( year ) . padStart ( 4 , '0' ) , `week_${ week } .md` ) ) ;
401+ await vscode . workspace . fs . writeFile ( file , new TextEncoder ( ) . encode ( `# Week ${ week } \n` ) ) ;
402+ return file . fsPath ;
403+ }
404+
405+ test ( 'T1: editor=undefined returns undefined' , async ( ) => {
406+ const result = await getAdjacentWeekInput ( undefined , ctrl , 'next' ) ;
407+ assert . strictEqual ( result , undefined ) ;
408+ } ) ;
409+
410+ test ( 'T2: non-weekly day file returns undefined' , async ( ) => {
411+ const dayPath = await seedEntry ( tmpBase , 2026 , 5 , 16 ) ;
412+ const doc = await vscode . workspace . openTextDocument ( vscode . Uri . file ( dayPath ) ) ;
413+ const editor = await vscode . window . showTextDocument ( doc ) ;
414+ const result = await getAdjacentWeekInput ( editor , ctrl , 'next' ) ;
415+ assert . strictEqual ( result , undefined ) ;
416+ } ) ;
417+
418+ test ( 'T3: weekly file + direction next → week+1' , async ( ) => {
419+ const weeklyPath = await seedWeeklyFile ( tmpBase , 2026 , 20 ) ;
420+ const doc = await vscode . workspace . openTextDocument ( vscode . Uri . file ( weeklyPath ) ) ;
421+ const editor = await vscode . window . showTextDocument ( doc ) ;
422+ const diag = `tmpBase=${ tmpBase } base=${ ctrl . config . getBasePath ( ) } weeksPat=${ ctrl . config . getWeeksFilePatternRaw ( ) } uri=${ editor . document . uri . fsPath } ` ;
423+ const result = await getAdjacentWeekInput ( editor , ctrl , 'next' ) ;
424+ assert . ok ( result , `expected an Input back [${ diag } ]` ) ;
425+ assert . strictEqual ( result ! . week , 21 ) ;
426+ } ) ;
427+
428+ test ( 'T4: weekly file + direction previous → week-1' , async ( ) => {
429+ const weeklyPath = await seedWeeklyFile ( tmpBase , 2026 , 20 ) ;
430+ const doc = await vscode . workspace . openTextDocument ( vscode . Uri . file ( weeklyPath ) ) ;
431+ const editor = await vscode . window . showTextDocument ( doc ) ;
432+ const result = await getAdjacentWeekInput ( editor , ctrl , 'previous' ) ;
433+ assert . ok ( result , 'expected an Input back' ) ;
434+ assert . strictEqual ( result ! . week , 19 ) ;
435+ } ) ;
436+ } ) ;
368437} ) ;
0 commit comments