@@ -3,7 +3,8 @@ import type { DataBrowserContext, PaneDefinition } from 'pane-registry'
33import { sym } from 'rdflib'
44import { solidLogicSingleton } from 'solid-logic'
55import { filterAvailablePanes } from '../../../src/login/login'
6- import { getRelevantPanes } from '../../../src/lib/file-explorer/relevant-panes'
6+ import ns from '../../../src/lib/ns'
7+ import { getPreferredPane , getRelevantPanes } from '../../../src/lib/file-explorer/relevant-panes'
78
89vi . mock ( '../../../src/login/login' , ( ) => ( {
910 filterAvailablePanes : vi . fn ( )
@@ -128,3 +129,52 @@ describe('getRelevantPanes', () => {
128129 await expect ( getRelevantPanes ( subject , createContext ( [ createPane ( 'first' ) ] ) ) ) . rejects . toBe ( error )
129130 } )
130131} )
132+
133+ describe ( 'getPreferredPane' , ( ) => {
134+ function contextWithMintClass ( mintClass ?: string ) : DataBrowserContext {
135+ const store = Object . create ( solidLogicSingleton . store )
136+ store . any = vi . fn ( ( candidate , predicate ) => {
137+ if ( mintClass && candidate . sameTerm ( subject ) && predicate . sameTerm ( ns . ui ( 'mintClass' ) ) ) {
138+ return sym ( mintClass )
139+ }
140+ return undefined
141+ } )
142+ return {
143+ dom : document ,
144+ getOutliner : ( ) => undefined ,
145+ session : {
146+ logic : solidLogicSingleton ,
147+ store,
148+ paneRegistry : {
149+ list : [ ] ,
150+ paneForIcon : { } ,
151+ paneForPredicate : { } ,
152+ register : vi . fn ( ) ,
153+ byName : ( ) => null
154+ }
155+ }
156+ }
157+ }
158+
159+ it ( 'prefers the pane matching a resource mint class over a focus request' , ( ) => {
160+ const mintClass = sym ( 'https://schema.example/PhotoAlbum' )
161+ const focus = createPane ( 'focus' , { shouldGetFocus : ( ) => true } )
162+ const minted = createPane ( 'album' , { mintClass } )
163+
164+ expect ( getPreferredPane ( subject , contextWithMintClass ( mintClass . uri ) , [ focus , minted ] ) ) . toBe ( minted )
165+ } )
166+
167+ it ( 'uses a focus request when no relevant pane matches the mint class' , ( ) => {
168+ const focus = createPane ( 'focus' , { shouldGetFocus : ( ) => true } )
169+ const other = createPane ( 'other' , { mintClass : sym ( 'https://schema.example/Other' ) } )
170+
171+ expect ( getPreferredPane ( subject , contextWithMintClass ( 'https://schema.example/PhotoAlbum' ) , [ other , focus ] ) ) . toBe ( focus )
172+ } )
173+
174+ it ( 'falls back to registry order when no pane requests focus' , ( ) => {
175+ const first = createPane ( 'first' )
176+ const second = createPane ( 'second' )
177+
178+ expect ( getPreferredPane ( subject , contextWithMintClass ( ) , [ first , second ] ) ) . toBe ( first )
179+ } )
180+ } )
0 commit comments