@@ -15,6 +15,7 @@ import { createLogger } from '@sim/logger'
1515import { getErrorMessage } from '@sim/utils/errors'
1616import { sleep } from '@sim/utils/helpers'
1717import { isRecordLike } from '@sim/utils/object'
18+ import { escapeRegExp } from '@sim/utils/string'
1819
1920/** Bounded production measurements: no builds, writes to services, or corpus crawling. */
2021const logger = createLogger ( 'DocsReadinessBenchmark' , { logLevel : 'INFO' } )
@@ -1014,17 +1015,35 @@ async function tabControl(
10141015 control : { scenario : string ; label : string ; choice : RegExp }
10151016) {
10161017 await measure ( profile , route , repetition , control . scenario , async ( ) => {
1017- const list = run . page . getByRole ( 'tablist' , { name : control . label , exact : true } )
1018- const tab = list . getByRole ( 'tab' , { name : control . choice } ) . filter ( { visible : true } ) . first ( )
1018+ const list = run . page . getByRole ( 'tablist' , {
1019+ name : control . label ,
1020+ exact : true ,
1021+ includeHidden : true ,
1022+ } )
1023+ const tab = list . getByRole ( 'tab' , { name : control . choice , includeHidden : true } ) . first ( )
10191024 if ( ! ( await tab . count ( ) ) )
10201025 return {
10211026 status : 'unavailable' ,
10221027 error : `No matching ${ control . label } tab on this baseline.` ,
10231028 }
1024- const choices = await list . getByRole ( 'tab' ) . count ( )
1025- await tab . scrollIntoViewIfNeeded ( )
1029+ const choices = await list . getByRole ( 'tab' , { includeHidden : true } ) . count ( )
1030+ const presentation = ( await tab . isVisible ( ) ) ? 'tabs' : 'menu'
1031+ let trigger = tab
1032+ if ( presentation === 'menu' ) {
1033+ const picker = run . page . getByRole ( 'button' , {
1034+ name : new RegExp ( `^${ escapeRegExp ( control . label ) } :` ) ,
1035+ } )
1036+ if ( ! ( await picker . isVisible ( ) ) )
1037+ return {
1038+ status : 'unavailable' ,
1039+ error : `No visible ${ control . label } control on this baseline.` ,
1040+ }
1041+ await picker . click ( )
1042+ trigger = run . page . getByRole ( 'menuitemradio' , { name : control . choice } ) . first ( )
1043+ }
1044+ await trigger . scrollIntoViewIfNeeded ( )
10261045 const start = performance . now ( )
1027- await tab . click ( )
1046+ await trigger . click ( )
10281047 await expect ( tab ) . toHaveAttribute ( 'aria-selected' , 'true' )
10291048 const id = await tab . getAttribute ( 'aria-controls' )
10301049 if ( ! id ) throw new Error ( 'Tab has no linked content' )
@@ -1036,6 +1055,7 @@ async function tabControl(
10361055 feedbackMs : choices > 1 ? performance . now ( ) - start : undefined ,
10371056 data : {
10381057 choices,
1058+ presentation,
10391059 selected : await tab . textContent ( ) ,
10401060 contentLength : ( await panel . textContent ( ) ) ?. length ,
10411061 applicableTransition : choices > 1 ,
@@ -1117,11 +1137,13 @@ async function apiControls(
11171137 if ( ! ( await button . count ( ) ) )
11181138 return { status : 'unavailable' , error : 'No named request-copy button on this baseline.' }
11191139 const selected = run . page
1120- . getByRole ( 'tablist' , { name : 'Request language' , exact : true } )
1121- . getByRole ( 'tab' , { selected : true } )
1140+ . getByRole ( 'tablist' , { name : 'Request language' , exact : true , includeHidden : true } )
1141+ . getByRole ( 'tab' , { selected : true , includeHidden : true } )
11221142 const id = await selected . getAttribute ( 'aria-controls' )
11231143 if ( ! id ) throw new Error ( 'Selected request has no panel' )
1124- const expected = await run . page . locator ( `[id="${ id } "] code` ) . textContent ( )
1144+ const panel = run . page . locator ( `[id="${ id } "]` )
1145+ await panel . waitFor ( { state : 'visible' } )
1146+ const expected = await panel . locator ( 'code' ) . textContent ( )
11251147 await button . scrollIntoViewIfNeeded ( )
11261148 const start = performance . now ( )
11271149 await button . click ( )
0 commit comments