1414 * 5. Focus order: the toggle, then the search, then the entries.
1515 *
1616 * objectstack#37201 — the two tiers (ADR-0084, amended 2026-11-25):
17- * 6. Group labels are muted, with no count and no link; an entry's muted
18- * number is its items; an empty 常用 type is dimmed, numberless, a link.
17+ * 6. Group labels carry no count and no link; an entry's muted number is
18+ * its items; an empty 常用 type is dimmed, numberless, a link.
1919 * 7. The 「高级」 fold: closed by default, remembered under
2020 * `studio_menu_advanced`, open by itself on one of its pages without
2121 * writing the cookie, ignored by the search, a button with
2828 * opens the area's type directory and is current there. CONTROL: a 高级
2929 * type the package holds none of is still not in the fold.
3030 *
31+ * objectstack#37452 — drawn as the app's menu:
32+ * 11. A group is the app menu's collapsible group: its label is a disclosure
33+ * button, open by default; closing it hides its entries; a search opens
34+ * every group it lists.
35+ * 12. An entry draws a bare line icon before its name; the current entry is
36+ * the primitive's active row (the pill and left bar).
37+ * 13. The selected entry is tinted by Studio's graphite accent whatever the
38+ * app's theme colour is.
39+ *
3140 * The provider, the sidebar primitive and the router are real; only the
3241 * metadata reads are doubled.
3342 */
3443
3544import '@testing-library/jest-dom/vitest' ;
45+ import type { ReactNode } from 'react' ;
3646import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
3747import { cleanup , fireEvent , render , screen , waitFor , within } from '@testing-library/react' ;
3848import { MemoryRouter , Route , Routes , useLocation } from 'react-router-dom' ;
@@ -63,8 +73,10 @@ vi.mock('../metadata-admin/useMetadata', async (importOriginal) => {
6373 } ;
6474} ) ;
6575
76+ import { useAppShellBranding } from '@object-ui/layout' ;
6677import { StudioMenu , StudioMenuProvider , StudioMenuTrigger } from './StudioMenu' ;
6778import { STUDIO_MENU_ADVANCED_COOKIE , STUDIO_MENU_COOKIE } from './studioMenuModel' ;
79+ import { STUDIO_ACCENT , STUDIO_ACCENT_HSL } from './studio-tokens' ;
6880
6981const PKG = 'com.acme.app' ;
7082
@@ -234,13 +246,12 @@ describe('the current entry and the search', () => {
234246} ) ;
235247
236248describe ( 'the group labels (objectstack#37201)' , ( ) => {
237- it ( 'are muted headings: no count, no link, not focusable ' , ( ) => {
249+ it ( 'carry no count and no link: the label is the group\'s name ' , ( ) => {
238250 renderAt ( `/studio/${ PKG } /data` ) ;
239251 const group = screen . getByTestId ( 'studio-menu-group-data' ) ;
240252 const label = group . querySelector ( '[data-sidebar="group-label"]' ) ! ;
241253 expect ( label ) . toHaveTextContent ( / ^ D a t a $ / ) ;
242- expect ( label ) . toHaveClass ( 'text-muted-foreground' ) ;
243- expect ( label . querySelector ( 'a, button, [tabindex]' ) ) . toBeNull ( ) ;
254+ expect ( label . querySelector ( 'a' ) ) . toBeNull ( ) ;
244255 expect ( label . closest ( 'a' ) ) . toBeNull ( ) ;
245256 } ) ;
246257
@@ -407,7 +418,7 @@ describe('~org and ~all draw no fold (objectstack#37201)', () => {
407418 it . each ( [
408419 [ '~org' , '/studio/~org/metadata/flow?source=runtime' ] ,
409420 [ '~all' , '/studio/~all/metadata' ] ,
410- ] ) ( '%s: its entries flat, in the table\'s order, under muted labels' , ( segment , path ) => {
421+ ] ) ( '%s: its entries flat, in the table\'s order, under their groups\' labels' , ( segment , path ) => {
411422 renderAt ( path , segment ) ;
412423 expect ( screen . queryByTestId ( 'studio-menu-advanced-toggle' ) ) . toBeNull ( ) ;
413424 expect ( screen . queryByTestId ( 'studio-menu-advanced' ) ) . toBeNull ( ) ;
@@ -418,7 +429,7 @@ describe('~org and ~all draw no fold (objectstack#37201)', () => {
418429 'studio-menu-entry-environment' ,
419430 ] ) ;
420431 for ( const a of within ( security ) . getAllByRole ( 'link' ) ) expect ( a ) . toBeVisible ( ) ;
421- expect ( security . querySelector ( '[data-sidebar="group-label"]' ) ) . toHaveClass ( 'text-muted-foreground' ) ;
432+ expect ( security . querySelector ( '[data-sidebar="group-label"]' ) ) . toHaveTextContent ( / ^ A c c e s s $ / ) ;
422433 expect ( screen . getByTestId ( 'studio-menu-entry-orgFlows' ) ) . toBeVisible ( ) ;
423434 // objectstack#37211 — no count above Organization flows (it read "0 types" over the group's one entry).
424435 const automation = screen . getByTestId ( 'studio-menu-group-automation' ) ;
@@ -486,3 +497,128 @@ describe('全部类型 All types (objectstack#37360, ADR-0084 amended 2026-11-25
486497 expect ( screen . queryByTestId ( 'studio-menu-all-types' ) ) . toBeNull ( ) ;
487498 } ) ;
488499} ) ;
500+
501+ describe ( 'drawn as the app\'s menu (objectstack#37452)' , ( ) => {
502+ const groupLabel = ( testId : string ) =>
503+ screen . getByTestId ( testId ) . querySelector < HTMLElement > ( '[data-sidebar="group-label"]' ) ! ;
504+
505+ it ( 'a group\'s label is the app menu\'s disclosure button: open by default, closing it hides its entries' , ( ) => {
506+ renderAt ( `/studio/${ PKG } /data` ) ;
507+ const label = groupLabel ( 'studio-menu-group-data' ) ;
508+ expect ( label . tagName ) . toBe ( 'BUTTON' ) ;
509+ expect ( label ) . toHaveAccessibleName ( 'Data' ) ;
510+ expect ( label ) . toHaveAttribute ( 'aria-expanded' , 'true' ) ;
511+ // The group's list is named by its label.
512+ expect ( entry ( 'type:object' ) . closest ( 'ul' ) ) . toHaveAttribute ( 'aria-labelledby' , label . id ) ;
513+ expect ( entry ( 'type:object' ) ) . toBeVisible ( ) ;
514+
515+ fireEvent . click ( label ) ;
516+ expect ( label ) . toHaveAttribute ( 'aria-expanded' , 'false' ) ;
517+ expect ( screen . queryByTestId ( 'studio-menu-entry-type:object' ) ) . toBeNull ( ) ;
518+ // CONTROL: the other groups stay open.
519+ expect ( entry ( 'type:flow' ) ) . toBeVisible ( ) ;
520+ // No count is drawn on a closed group: a number in this menu is an entry's items.
521+ expect ( label ) . toHaveTextContent ( / ^ D a t a $ / ) ;
522+
523+ fireEvent . click ( label ) ;
524+ expect ( entry ( 'type:object' ) ) . toBeVisible ( ) ;
525+ } ) ;
526+
527+ it ( 'a search lists its matches in a group the author closed' , ( ) => {
528+ renderAt ( `/studio/${ PKG } /data` ) ;
529+ fireEvent . click ( groupLabel ( 'studio-menu-group-automation' ) ) ;
530+ expect ( screen . queryByTestId ( 'studio-menu-entry-type:flow' ) ) . toBeNull ( ) ;
531+ fireEvent . change ( screen . getByTestId ( 'studio-menu-search' ) , { target : { value : 'flow' } } ) ;
532+ expect ( entry ( 'type:flow' ) ) . toBeVisible ( ) ;
533+ } ) ;
534+
535+ it ( 'an entry draws a bare line icon before its name, on the app menu\'s row' , ( ) => {
536+ renderAt ( `/studio/${ PKG } /data` ) ;
537+ for ( const key of [ 'type:object' , 'type:flow' , 'type:permission' ] ) {
538+ const icon = screen . getByTestId ( `studio-menu-icon-${ key } ` ) ;
539+ expect ( icon . tagName . toLowerCase ( ) ) . toBe ( 'svg' ) ;
540+ expect ( icon ) . toHaveAttribute ( 'aria-hidden' , 'true' ) ;
541+ // No tile: the icon is the row's own child, the first one.
542+ expect ( icon . parentElement ) . toBe ( entry ( key ) ) ;
543+ expect ( entry ( key ) . firstElementChild ) . toBe ( icon ) ;
544+ expect ( entry ( key ) ) . toHaveAttribute ( 'data-sidebar' , 'menu-button' ) ;
545+ }
546+ // A type and an entry that is not one each draw an icon, the fold's too.
547+ fireEvent . click ( fold ( ) ) ;
548+ expect ( screen . getByTestId ( 'studio-menu-icon-type:hook' ) . tagName . toLowerCase ( ) ) . toBe ( 'svg' ) ;
549+ expect ( screen . getByTestId ( 'studio-menu-icon-owd' ) . tagName . toLowerCase ( ) ) . toBe ( 'svg' ) ;
550+ } ) ;
551+
552+ it ( 'the current entry is the primitive\'s active row (the pill and its left bar), and only it' , ( ) => {
553+ renderAt ( `/studio/${ PKG } /metadata/flow?package=${ PKG } ` ) ;
554+ expect ( entry ( 'type:flow' ) ) . toHaveAttribute ( 'data-active' , 'true' ) ;
555+ expect ( entry ( 'type:object' ) ) . toHaveAttribute ( 'data-active' , 'false' ) ;
556+ // Its count is not muted: it reads with the selected name.
557+ expect ( screen . getByTestId ( 'studio-menu-count-type:flow' ) ) . not . toHaveClass ( 'text-muted-foreground' ) ;
558+ } ) ;
559+
560+ describe ( 'the selected entry is tinted by Studio\'s graphite whatever the app\'s theme colour is' , ( ) => {
561+ const ROOT_TOKENS = [ '--primary' , '--primary-foreground' , '--ring' , '--sidebar-primary' , '--sidebar-ring' , '--accent' , '--accent-foreground' ] ;
562+
563+ function Branded ( { children } : { children : ReactNode } ) {
564+ // A non-default app theme: a rose primary, written on the page root by the app shell's own hook.
565+ useAppShellBranding ( { primaryColor : '#e11d48' } ) ;
566+ return < > { children } </ > ;
567+ }
568+
569+ afterEach ( ( ) => {
570+ for ( const token of ROOT_TOKENS ) document . documentElement . style . removeProperty ( token ) ;
571+ for ( const token of [ '--brand-primary' , '--brand-primary-hsl' ] ) document . documentElement . style . removeProperty ( token ) ;
572+ } ) ;
573+
574+ /** The declarations a class string makes: `[--x:a_b]` and `dark:[--x:a_b]`, underscores read as spaces. */
575+ function declarations ( classes : string , dark : boolean ) : Map < string , string > {
576+ const out = new Map < string , string > ( ) ;
577+ for ( const cls of classes . split ( / \s + / ) ) {
578+ const m = / ^ ( d a r k : ) ? \[ ( - - [ \w - ] + ) : ( .+ ) \] $ / . exec ( cls ) ;
579+ if ( m && ! ! m [ 1 ] === dark ) out . set ( m [ 2 ] , m [ 3 ] . replace ( / _ / g, ' ' ) ) ;
580+ }
581+ return out ;
582+ }
583+
584+ it ( 'every theme token the app\'s branding writes on the page root is rebound to graphite over the selected entry, light and dark' , ( ) => {
585+ render (
586+ < MemoryRouter initialEntries = { [ `/studio/${ PKG } /metadata/flow?package=${ PKG } ` ] } >
587+ < Branded >
588+ < Routes >
589+ < Route path = "*" element = { < Shell segment = { PKG } /> } />
590+ </ Routes >
591+ </ Branded >
592+ </ MemoryRouter > ,
593+ ) ;
594+ // CONTROL: the app's theme is not the default — its colour is on the page root.
595+ const root = document . documentElement . style ;
596+ const written = [ ...Array . from ( { length : root . length } , ( _ , i ) => root . item ( i ) ) ] . filter (
597+ // `--brand-*` are the hook's hex aliases; no sidebar or menu class reads them.
598+ ( token ) => token . startsWith ( '--' ) && ! token . startsWith ( '--brand-' ) ,
599+ ) ;
600+ expect ( written ) . toContain ( '--primary' ) ;
601+ expect ( root . getPropertyValue ( '--primary' ) . trim ( ) ) . not . toBe ( STUDIO_ACCENT_HSL . light ) ;
602+
603+ // The selected entry is the active row, and it sits inside Studio's accent scope.
604+ const selected = entry ( 'type:flow' ) ;
605+ expect ( selected ) . toHaveAttribute ( 'data-active' , 'true' ) ;
606+ const scope = selected . closest < HTMLElement > ( '[data-studio-accent]' ) ;
607+ expect ( scope ) . not . toBeNull ( ) ;
608+ for ( const cls of STUDIO_ACCENT . split ( / \s + / ) ) expect ( scope ) . toHaveClass ( cls ) ;
609+ // Nothing between the scope and the entry writes a theme token back.
610+ for ( let el : HTMLElement | null = selected ; el && el !== scope ; el = el . parentElement ) {
611+ for ( const token of written ) expect ( el . style . getPropertyValue ( token ) , `${ token } on ${ el . tagName } ` ) . toBe ( '' ) ;
612+ }
613+
614+ const light = declarations ( STUDIO_ACCENT , false ) ;
615+ const dark = declarations ( STUDIO_ACCENT , true ) ;
616+ for ( const token of written ) {
617+ expect ( light . has ( token ) , `${ token } rebound in the light theme` ) . toBe ( true ) ;
618+ expect ( dark . has ( token ) , `${ token } rebound in the dark theme` ) . toBe ( true ) ;
619+ }
620+ expect ( light . get ( '--primary' ) ) . toBe ( STUDIO_ACCENT_HSL . light ) ;
621+ expect ( dark . get ( '--primary' ) ) . toBe ( STUDIO_ACCENT_HSL . dark ) ;
622+ } ) ;
623+ } ) ;
624+ } ) ;
0 commit comments