Skip to content

Commit 3148d1c

Browse files
committed
test(studio): pin the menu's collapsible groups, line icons and graphite accent
Claude-Session: https://claude.ai/code/session_01Utp6CbL6Nn3scsU8yvLyU4 Co-authored-by: Claude <noreply@anthropic.com>
1 parent da5fbb7 commit 3148d1c

3 files changed

Lines changed: 214 additions & 7 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/layout': patch
4+
---
5+
6+
feat(studio): the Studio left menu is drawn as the app's menu, in Studio's own graphite
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
- **Groups collapse the way the app menu's do.** Each of the menu's groups is the app menu's collapsible group: its label is a disclosure button with a chevron, open by default, and a search opens every group it lists. A group still carries no count: a number in the Studio menu is an entry's items.
12+
- **An entry is the app menu's row.** It draws a bare line icon (no tile) before its name, at the app menu's row size; the open page's entry is the app menu's inset pill with a bar on its left edge.
13+
- **Studio's own accent.** The pill and the bar are graphite, light and dark, whatever the app's theme colour is (`STUDIO_ACCENT` in the Studio tokens); only the app's logo keeps the app's colour.
14+
- **New export: `NavigationGroupSection`** (`@object-ui/layout`), the collapsible sidebar group the app menu draws every `group` entry with. The app menu renders exactly as before.

‎ui/packages/app-shell/src/views/studio-design/StudioMenu.test.tsx‎

Lines changed: 143 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
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
@@ -28,11 +28,21 @@
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

3544
import '@testing-library/jest-dom/vitest';
45+
import type { ReactNode } from 'react';
3646
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3747
import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
3848
import { 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';
6677
import { StudioMenu, StudioMenuProvider, StudioMenuTrigger } from './StudioMenu';
6778
import { STUDIO_MENU_ADVANCED_COOKIE, STUDIO_MENU_COOKIE } from './studioMenuModel';
79+
import { STUDIO_ACCENT, STUDIO_ACCENT_HSL } from './studio-tokens';
6880

6981
const PKG = 'com.acme.app';
7082

@@ -234,13 +246,12 @@ describe('the current entry and the search', () => {
234246
});
235247

236248
describe('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(/^Data$/);
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(/^Access$/);
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(/^Data$/);
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 = /^(dark:)?\[(--[\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+
});
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#37452 — Studio's accent class spells its values literally (so
5+
* Tailwind's source scan finds the classes); this holds every value it spells
6+
* equal to the constants the rest of the code reads, in the light and the
7+
* dark theme.
8+
*/
9+
10+
import { describe, expect, it } from 'vitest';
11+
import { STUDIO_ACCENT, STUDIO_ACCENT_FOREGROUND_HSL, STUDIO_ACCENT_HSL } from './studio-tokens';
12+
13+
/** The declarations the class string makes in one theme: `[--x:a_b]` / `dark:[--x:a_b]`, underscores read as spaces. */
14+
function declarations(dark: boolean): Map<string, string> {
15+
const out = new Map<string, string>();
16+
for (const cls of STUDIO_ACCENT.split(/\s+/)) {
17+
const m = /^(dark:)?\[(--[\w-]+):(.+)\]$/.exec(cls);
18+
if (m && !!m[1] === dark) out.set(m[2], m[3].replace(/_/g, ' '));
19+
}
20+
return out;
21+
}
22+
23+
describe('STUDIO_ACCENT (objectstack#37452)', () => {
24+
it.each([
25+
['light', false],
26+
['dark', true],
27+
] as const)('%s: the accent tokens are graphite, and the foreground is the accent\'s foreground', (theme, dark) => {
28+
const decl = declarations(dark);
29+
for (const token of ['--primary', '--ring', '--sidebar-primary', '--sidebar-ring']) {
30+
expect(decl.get(token), token).toBe(STUDIO_ACCENT_HSL[theme]);
31+
}
32+
expect(decl.get('--primary-foreground')).toBe(STUDIO_ACCENT_FOREGROUND_HSL[theme]);
33+
});
34+
35+
it('graphite is a neutral: low saturation in both themes, dark in the light theme and light in the dark one', () => {
36+
const parse = (hsl: string) => hsl.split(' ').map((part) => Number.parseFloat(part));
37+
const [, sLight, lLight] = parse(STUDIO_ACCENT_HSL.light);
38+
const [, sDark, lDark] = parse(STUDIO_ACCENT_HSL.dark);
39+
expect(sLight).toBeLessThanOrEqual(12);
40+
expect(sDark).toBeLessThanOrEqual(12);
41+
expect(lLight).toBeLessThan(40);
42+
expect(lDark).toBeGreaterThan(70);
43+
});
44+
45+
it('re-derives Tailwind\'s colour tokens on the same element, so utilities read the rebound values', () => {
46+
const decl = declarations(false);
47+
for (const [color, token] of [
48+
['--color-primary', '--primary'],
49+
['--color-primary-foreground', '--primary-foreground'],
50+
['--color-ring', '--ring'],
51+
['--color-sidebar-primary', '--sidebar-primary'],
52+
['--color-sidebar-ring', '--sidebar-ring'],
53+
]) {
54+
expect(decl.get(color), color).toBe(`hsl(var(${token}))`);
55+
}
56+
});
57+
});

0 commit comments

Comments
 (0)