@@ -7,6 +7,7 @@ import { createEventEmitter } from 'devframe/utils/events'
77import { createSharedState } from 'devframe/utils/shared-state'
88import { describe , expect , it , vi } from 'vitest'
99import { nextTick , ref } from 'vue'
10+ import { useStandaloneDefaultDock } from '../utils/useStandaloneDefaultDock'
1011import { createDocksContext } from './context'
1112import { executeSetupScript } from './setup-script'
1213
@@ -430,3 +431,71 @@ describe('dock group command activation', () => {
430431 ] )
431432 } )
432433} )
434+
435+ describe ( 'standalone initial dock' , ( ) => {
436+ async function fixture ( entries : DevframeDockEntry [ ] ) {
437+ const { rpc, sharedStates, trust } = createStubRpc ( )
438+ const context = await createDocksContext ( 'standalone' , rpc )
439+ sharedStates . get ( HUB_EVENTS . sharedState . docks ) ! . push ( entries )
440+ const trusted = ref ( false )
441+ const stop = useStandaloneDefaultDock ( context , trusted )
442+ return {
443+ context,
444+ stop,
445+ async connect ( ) {
446+ trust ( )
447+ trusted . value = true
448+ await flushRestore ( )
449+ } ,
450+ async publish ( next : DevframeDockEntry [ ] ) {
451+ sharedStates . get ( HUB_EVENTS . sharedState . docks ) ! . push ( next )
452+ await flushRestore ( )
453+ } ,
454+ }
455+ }
456+
457+ it ( 'skips a hidden wrapper and activates the first visible dock through its client script' , async ( ) => {
458+ expect . assertions ( 3 )
459+ const { context, connect, stop } = await fixture ( [
460+ { id : 'wrapper' , title : 'Wrapper' , icon : 'ph:box' , type : 'iframe' , url : '/devframe/' , when : 'false' } ,
461+ gitEntry ,
462+ ] )
463+ expect ( context . docks . selectedId ) . toBeNull ( )
464+ await connect ( )
465+ expect ( context . docks . selectedId ) . toBe ( 'git' )
466+ expect ( executeSetupScript ) . toHaveBeenCalledWith ( gitEntry , expect . anything ( ) )
467+ stop ( )
468+ } )
469+
470+ it ( 'waits for an eligible entry without running actions or selecting a built-in fallback' , async ( ) => {
471+ expect . assertions ( 2 )
472+ const { context, connect, publish, stop } = await fixture ( [
473+ { id : 'command' , title : 'Command' , icon : 'ph:play' , type : 'action' , action : { importFrom : '/command.js' } } ,
474+ ] )
475+ await connect ( )
476+ expect ( context . docks . selectedId ) . toBeNull ( )
477+ await publish ( [ gitEntry ] )
478+ expect ( context . docks . selectedId ) . toBe ( 'git' )
479+ stop ( )
480+ } )
481+
482+ it ( 'keeps an existing selection when the catalog changes' , async ( ) => {
483+ expect . assertions ( 1 )
484+ const { context, connect, publish, stop } = await fixture ( [ gitEntry ] )
485+ await connect ( )
486+ await publish ( [ { ...gitEntry , id : 'new-first' } , gitEntry ] )
487+ expect ( context . docks . selectedId ) . toBe ( 'git' )
488+ stop ( )
489+ } )
490+
491+ it ( 'uses normal group routing to open a visible member' , async ( ) => {
492+ expect . assertions ( 1 )
493+ const { context, connect, stop } = await fixture ( [
494+ { id : 'tools' , title : 'Tools' , icon : 'ph:folder' , type : 'group' } ,
495+ { ...gitEntry , groupId : 'tools' } ,
496+ ] )
497+ await connect ( )
498+ expect ( context . docks . selectedId ) . toBe ( 'git' )
499+ stop ( )
500+ } )
501+ } )
0 commit comments