11import { afterEach , describe , expect , it , vi } from 'vitest'
22import { computed , defineComponent , h , ref , watchEffect , type Ref } from 'vue'
3+ import type { RouteLocationRaw } from 'vue-router'
34import { mockNuxtImport , mountSuspended } from '@nuxt/test-utils/runtime'
45import { downloadPackageTarball } from '~/utils/package-download'
56import type {
@@ -49,7 +50,7 @@ async function captureCommandPalette(options?: {
4950 npmUser ?: string | null
5051 atprotoHandle ?: string | null
5152 packageContext ?: CommandPalettePackageContext | null
52- versionUrlPattern ?: string
53+ versionRoute ?: ( version : string ) => RouteLocationRaw
5354 contextCommands ?: CommandPaletteContextCommandInput [ ]
5455} ) {
5556 const groupedCommands = ref < CommandPaletteCommandGroup [ ] > ( [ ] ) as Ref < CommandPaletteCommandGroup [ ] >
@@ -76,10 +77,7 @@ async function captureCommandPalette(options?: {
7677 if ( options ?. packageContext ) {
7778 setPackageContext ( options . packageContext )
7879 useCommandPalettePackageCommands ( ( ) => options . packageContext ?? null )
79- useCommandPaletteVersionCommands (
80- ( ) => options . packageContext ?? null ,
81- ( ) => options . versionUrlPattern ,
82- )
80+ useCommandPaletteVersionCommands ( ( ) => options . packageContext ?? null , options . versionRoute )
8381 } else {
8482 clearPackageContext ( )
8583 }
@@ -232,6 +230,14 @@ describe('useCommandPaletteCommands', () => {
232230 expect ( flatCommands . value . find ( command => command . id === 'package-diff' ) ) . toBeTruthy ( )
233231 expect ( flatCommands . value . find ( command => command . id === 'package-download' ) ) . toBeTruthy ( )
234232 expect ( flatCommands . value . find ( command => command . id === 'package-main' ) ?. to ) . toBeTruthy ( )
233+ expect ( flatCommands . value . find ( command => command . id === 'package-timeline' ) ?. to ) . toEqual ( {
234+ name : 'timeline' ,
235+ params : {
236+ org : undefined ,
237+ packageName : 'vue' ,
238+ version : '3.4.0' ,
239+ } ,
240+ } )
235241 expect ( groupedCommands . value . at ( - 1 ) ?. id ) . toBe ( 'versions' )
236242 expect ( groupedCommands . value . at ( - 1 ) ?. items [ 0 ] ?. id ) . toBe ( 'version:3.4.0' )
237243 expect ( groupedCommands . value . at ( - 1 ) ?. items [ 0 ] ?. active ) . toBe ( true )
@@ -345,7 +351,7 @@ describe('useCommandPaletteCommands', () => {
345351 wrapper . unmount ( )
346352 } )
347353
348- it ( 'keeps version navigation on the current surface when a version URL pattern is provided' , async ( ) => {
354+ it ( 'keeps version navigation on the current surface when a version route builder is provided' , async ( ) => {
349355 const { wrapper, flatCommands, routePath } = await captureCommandPalette ( {
350356 route : '/package-code/vue/v/3.4.2/src/index.ts' ,
351357 packageContext : {
@@ -354,7 +360,7 @@ describe('useCommandPaletteCommands', () => {
354360 latestVersion : '4.0.0' ,
355361 versions : [ '4.0.0' , '3.5.0' , '3.4.2' ] ,
356362 } ,
357- versionUrlPattern : ' /package-code/vue/v/{version}/src/index.ts' ,
363+ versionRoute : version => ` /package-code/vue/v/$ {version } /src/index.ts` ,
358364 } )
359365
360366 const versionCommand = flatCommands . value . find ( command => command . id === 'version:3.5.0' )
@@ -513,6 +519,14 @@ describe('useCommandPaletteCommands', () => {
513519 path : [ '@scope' , 'pkg' , 'v' , '1.0.0' ] ,
514520 } ,
515521 } )
522+ expect ( flatCommands . value . find ( command => command . id === 'package-timeline' ) ?. to ) . toEqual ( {
523+ name : 'timeline' ,
524+ params : {
525+ org : '@scope' ,
526+ packageName : 'pkg' ,
527+ version : '1.0.0' ,
528+ } ,
529+ } )
516530
517531 wrapper . unmount ( )
518532 } )
0 commit comments