Skip to content

Commit 691a0bc

Browse files
feat(studio): the left menu is drawn as the app's menu, in Studio's own graphite (#37478)
repo:objectstack#5 · os-bill · session_01Utp6CbL6Nn3scsU8yvLyU4 <!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgTC1DCWJ4MisoLdbUU1V1sb)_ Fixes #37452 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:Studio 左侧菜单改成和前端应用菜单一样——分组标题可以点开收起,每一项前面是不带底色的线条图标,当前页是浅灰胶囊加左侧竖条,选中色用 Studio 自己的石墨色,不再跟着应用的主题色变;前端应用菜单本身看起来不变。 - 为什么做:App Studio 改版第一阶段的第一张卡,让 Studio 的导航和前端长得一样,并给后续几张卡准备好 Studio 专用的石墨色。 - 出错会怎样:做 Studio 的人可能看到菜单分组收起后找不到某一项(点分组标题就能展开,搜索时分组会自动展开),或选中色不对;只是样式与折叠,撤回这个改动就恢复原样,不涉及数据。 - 要你做什么:无。 ## What changes - **Groups collapse the way the app menu's do.** The collapsible group the app menu draws for every `group` entry is now an exported component, `NavigationGroupSection` with its props type `NavigationGroupSectionProps` (`@object-ui/layout`, a published package, hence `Clause-②: yes (widening)`; listed in the package README), and the app menu renders through it with the same output as before. Studio's menu draws each of its groups with it: the label is the disclosure button with the chevron, open by default. While a search lists matches, every listed group is drawn open, chevron turned down, and a click on its label is not taken; the author's choice comes back when the search is cleared. In the phone drawer the label is the app menu's 44 px tap target. A Studio group still carries no count (ADR-0084, amended: a number in this menu is an entry's items), so the closed-group count is optional and Studio passes none. - **An entry is the app menu's row.** Default `SidebarMenuButton` size (was `sm`), a bare line icon before the name with no tile (the maintainer's 「可以不要背景」), the muted item count at the right; the selected entry's count is not muted. Each listed type has its own icon (a module-local map in `StudioMenu.tsx`; an unmapped type draws its group's icon); entries that are not a type draw one per kind. The group label no longer draws a group icon, matching mockup 1. - **Studio's own accent.** `studio-tokens.ts` gains `STUDIO_ACCENT_HSL` / `STUDIO_ACCENT_FOREGROUND_HSL` (graphite, light and dark) and `STUDIO_ACCENT`, a class string that rebinds every theme token the app's branding writes on the page root: `--primary`, `--primary-foreground`, `--ring`, `--sidebar-primary`, `--sidebar-ring` to graphite, and `--accent` / `--accent-foreground` (written from the app's `accentColor`) to a faint graphite tint (`STUDIO_ACCENT_TINT_HSL`), since in this theme `--accent` is the hover tint, not a strong colour. It re-derives Tailwind's `--color-*` from them on the same element. The menu wraps its header and body in it, so the front end's existing selected-row rule (the pill and its 2 px left bar, which read the theme's primary) draws graphite in Studio, docked or in the phone drawer, whatever the app's theme colour is. Mounting the accent on the whole Studio root is left to the later card that owns the surface. - Untouched, as ruled: the sidebar primitive, `StudioDesignSurface.tsx`, the top bar. ## Tests - `StudioMenu.test.tsx`, a new top-level describe: the group label is a disclosure button, open by default, closing it hides only its entries and draws no count; a search lists matches in a group the author closed with its chevron turned down, a click during the search is not taken (on a closed group and on an open one), and clearing it restores the author's choice; in the phone drawer the label is 44 px (`min-h-[44px]`), docked it is not; each entry draws a bare line icon as the row's first child; the current entry is the primitive's active row and only it; with a non-default app theme applied through the app shell's own branding hook (a rose primary and an amber accent on the page root, the control), every theme token the hook wrote is rebound to graphite, light and dark, on an ancestor of the selected entry, with nothing in between writing one back. - `studio-tokens.test.ts` (new): the literal class string's values equal the constants in both themes (the accent pair included), graphite is a neutral, the hover tint is faint, and the `--color-*` tokens are re-derived. - Existing pins updated where this card made them false: the two StudioMenu group-label assertions (a label was "a muted heading, not focusable"), and the Access-segment pin's glyph check in `StudioDesignSurface.accessSegment-12452.test.tsx` (the shield moved from the group label to the permission-set entry). ## Acceptance notes - **Read first** (by risk): `ui/packages/layout/src/NavigationRenderer.tsx` (the extracted `NavigationGroupSection`; the app menu's `group` arm now renders through it and must draw the same DOM), `ui/packages/app-shell/src/views/studio-design/studio-tokens.ts` (`STUDIO_ACCENT`), `ui/packages/app-shell/src/views/studio-design/StudioMenu.tsx` (the accent wrapper and the group sections). - **File-surface note:** the claim's surface did not name `StudioDesignSurface.accessSegment-12452.test.tsx`; its glyph assertion pinned the group-label icon this card removes, so it is updated here (test only; the component file is untouched). The seat ratified it (L1 7186198980) and extended the surface to `ui/packages/layout/README.md`. - The command palette's Studio groups still draw each type item with its group's icon, so the menu and the palette now draw different icons for a type, and the `studioMenuData.ts` header's "the two draw the same types, icons and names" is no longer true for icons. Neither file was in this card's surface. Carrier: #37424. - On a package, a search draws the groups flat (outside the 高级 fold), so clearing the search remounts the tiered groups open: a group the author closed before searching comes back open. On `~org` / `~all` the closed state survives a search (pinned). - Real-browser check (Chromium, 1440x900 at 2x, light and dark, head 803afb6): readings and screenshots are in the final-head comment on this PR. ## Verification Two-minute check: open any Studio page under an app with a non-default theme colour (for example a rose `primaryColor`). Expected: the left menu's group headers have a chevron and collapse on click, every entry has a line icon with no tile, and the open page's entry is a grey pill with a dark graphite bar on its left (light grey in dark mode), not the app's colour. <details><summary>Local runs (head 803afb6)</summary> - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/app-shell/src/views/studio-design/StudioMenu.test.tsx packages/app-shell/src/views/studio-design/studio-tokens.test.ts packages/app-shell/src/views/studio-design/StudioDesignSurface.accessSegment-12452.test.tsx packages/layout/` under the verify lock (head 453b097): `Test Files 53 passed (53)`, `Tests 448 passed (448)`; StudioMenu and studio-tokens on 803afb6: `Tests 40 passed (40)`. - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/app-shell/src/views/studio-design/ packages/app-shell/src/layout/ packages/app-shell/src/views/__tests__/` (head 41fc38d): `Tests 1 failed / 4659 passed`; the one failure was the Access-segment glyph pin, updated in bca58d4 and green since (4 of 4). - `pnpm --filter @object-ui/layout type-check`, `pnpm --filter @object-ui/layout build`, `pnpm --filter @object-ui/app-shell build` (on b1dc4ad), `pnpm --filter @object-ui/app-shell type-check` (includes the test project; re-run on 803afb6): exit 0. - `pnpm exec eslint` on the six changed UI files: 0 errors; no new warning in the Studio files. - `dispatch-gates --commands` derived 38 commands for this diff; all 38 exit 0 on 803afb6; `--ran` reconciliation with exit codes: 38 derived, 38 run, 0 NOT-MEASURED (a derived zero). - `pnpm check:new-line-citations`: 0 new citations. </details> <details><summary>Ablations (each mutation landed and restored by `scripts/ablation-replace.mjs`, blob back to HEAD, `git diff HEAD` empty)</summary> - On b1dc4ad, the accent wrapper without `STUDIO_ACCENT`: the graphite-under-a-non-default-theme test goes red (1 failed / 32 passed). - On 803afb6: `open={open || searching}` to `open={open}`: the search test red (1 failed / 39 passed); back to the old shape `open={open} forceOpen={searching}`: red on the chevron's `rotate-90`; `onOpenChange` always `setOpen`: "a click on an open group's label during a search is not taken" red; `isMobile={false}`: the 44 px tap-target test red; the accent pair dropped from `STUDIO_ACCENT`: the light-theme tokens test and the every-theme-token test red. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CbL6Nn3scsU8yvLyU4)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent e0b0471 commit 691a0bc

8 files changed

Lines changed: 656 additions & 148 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-②: yes (widening)
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; a search opens every group it lists, chevron included, and holds it open; in the phone drawer the label is the app menu's 44 px tap target. 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); the app's `accentColor` no longer reaches anything under that class either: its hover tint is a faint graphite. Only the app's logo keeps the app's colour.
14+
- **New exports: `NavigationGroupSection` and its props type `NavigationGroupSectionProps`** (`@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/StudioDesignSurface.accessSegment-12452.test.tsx‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
* read on the menu:
1313
*
1414
* 1. The menu's Access group holds the permission-set entry, a real router
15-
* link, with no "More" trigger anywhere; the group carries the shield glyph,
16-
* the Data group's is not it.
15+
* link, with no "More" trigger anywhere; that entry carries the shield
16+
* glyph, the Data group's object entry does not (objectstack#37452: a
17+
* group's label draws no glyph, each entry draws its own line icon).
1718
* 2. With the Access pillar's address open (under any package id) — which
1819
* lands on the list of sets since objectstack#36905 — that entry is the
1920
* current page and carries the active state; with Data open it carries
@@ -30,7 +31,7 @@ import * as React from 'react';
3031
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
3132
import { render, screen, cleanup, within } from '@testing-library/react';
3233
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
33-
import { ShieldCheck } from 'lucide-react';
34+
import { Shield } from 'lucide-react';
3435

3536
const PKG = 'com.acme.app';
3637

@@ -208,9 +209,9 @@ function renderAt(path: string) {
208209
const menu = () => screen.getByTestId('studio-menu');
209210
const entry = (testId: string) => within(menu()).getByTestId(testId);
210211

211-
/** The markup of lucide's own `ShieldCheck`, the Access group's glyph. */
212+
/** The markup of lucide's own `Shield`, the permission-set entry's glyph. */
212213
function shieldMarkup(): string {
213-
const { container, unmount } = render(<ShieldCheck />);
214+
const { container, unmount } = render(<Shield />);
214215
const markup = container.querySelector('svg')!.innerHTML;
215216
unmount();
216217
return markup;
@@ -230,8 +231,8 @@ describe('Studio menu: Access is a group of its own, and More is gone (objectui#
230231
expect(screen.queryByTestId('studio-nav-more')).toBeNull();
231232
expect(screen.queryByTestId('studio-pillar-nav')).toBeNull();
232233
const shield = shieldMarkup();
233-
expect(group.querySelector('svg')!.innerHTML).toBe(shield);
234-
expect(within(menu()).getByTestId('studio-menu-group-data').querySelector('svg')!.innerHTML).not.toBe(shield);
234+
expect(within(group).getByTestId(PERMISSION_ENTRY).querySelector('svg')!.innerHTML).toBe(shield);
235+
expect(entry(OBJECT_ENTRY).querySelector('svg')!.innerHTML).not.toBe(shield);
235236
});
236237

237238
it.each(['app.objectstack.hotcrm', PKG])('with Access open in %s, the permission-set entry is the current page', async (pkg) => {

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

Lines changed: 186 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,23 @@
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, chevron included, and holds it open; in the phone
35+
* drawer the label is the app menu's 44 px tap target.
36+
* 12. An entry draws a bare line icon before its name; the current entry is
37+
* the primitive's active row (the pill and left bar).
38+
* 13. The selected entry is tinted by Studio's graphite accent whatever the
39+
* app's theme colours are: every theme token the app's branding writes
40+
* (primary and accent) is rebound over it.
41+
*
3142
* The provider, the sidebar primitive and the router are real; only the
3243
* metadata reads are doubled.
3344
*/
3445

3546
import '@testing-library/jest-dom/vitest';
47+
import type { ReactNode } from 'react';
3648
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3749
import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
3850
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
@@ -63,8 +75,10 @@ vi.mock('../metadata-admin/useMetadata', async (importOriginal) => {
6375
};
6476
});
6577

78+
import { useAppShellBranding } from '@object-ui/layout';
6679
import { StudioMenu, StudioMenuProvider, StudioMenuTrigger } from './StudioMenu';
6780
import { STUDIO_MENU_ADVANCED_COOKIE, STUDIO_MENU_COOKIE } from './studioMenuModel';
81+
import { STUDIO_ACCENT, STUDIO_ACCENT_HSL } from './studio-tokens';
6882

6983
const PKG = 'com.acme.app';
7084

@@ -234,13 +248,12 @@ describe('the current entry and the search', () => {
234248
});
235249

236250
describe('the group labels (objectstack#37201)', () => {
237-
it('are muted headings: no count, no link, not focusable', () => {
251+
it('carry no count and no link: the label is the group\'s name', () => {
238252
renderAt(`/studio/${PKG}/data`);
239253
const group = screen.getByTestId('studio-menu-group-data');
240254
const label = group.querySelector('[data-sidebar="group-label"]')!;
241255
expect(label).toHaveTextContent(/^Data$/);
242-
expect(label).toHaveClass('text-muted-foreground');
243-
expect(label.querySelector('a, button, [tabindex]')).toBeNull();
256+
expect(label.querySelector('a')).toBeNull();
244257
expect(label.closest('a')).toBeNull();
245258
});
246259

@@ -407,7 +420,7 @@ describe('~org and ~all draw no fold (objectstack#37201)', () => {
407420
it.each([
408421
['~org', '/studio/~org/metadata/flow?source=runtime'],
409422
['~all', '/studio/~all/metadata'],
410-
])('%s: its entries flat, in the table\'s order, under muted labels', (segment, path) => {
423+
])('%s: its entries flat, in the table\'s order, under their groups\' labels', (segment, path) => {
411424
renderAt(path, segment);
412425
expect(screen.queryByTestId('studio-menu-advanced-toggle')).toBeNull();
413426
expect(screen.queryByTestId('studio-menu-advanced')).toBeNull();
@@ -418,7 +431,7 @@ describe('~org and ~all draw no fold (objectstack#37201)', () => {
418431
'studio-menu-entry-environment',
419432
]);
420433
for (const a of within(security).getAllByRole('link')) expect(a).toBeVisible();
421-
expect(security.querySelector('[data-sidebar="group-label"]')).toHaveClass('text-muted-foreground');
434+
expect(security.querySelector('[data-sidebar="group-label"]')).toHaveTextContent(/^Access$/);
422435
expect(screen.getByTestId('studio-menu-entry-orgFlows')).toBeVisible();
423436
// objectstack#37211 — no count above Organization flows (it read "0 types" over the group's one entry).
424437
const automation = screen.getByTestId('studio-menu-group-automation');
@@ -486,3 +499,169 @@ describe('全部类型 All types (objectstack#37360, ADR-0084 amended 2026-11-25
486499
expect(screen.queryByTestId('studio-menu-all-types')).toBeNull();
487500
});
488501
});
502+
503+
describe('drawn as the app\'s menu (objectstack#37452)', () => {
504+
const groupLabel = (testId: string) =>
505+
screen.getByTestId(testId).querySelector<HTMLElement>('[data-sidebar="group-label"]')!;
506+
507+
it('a group\'s label is the app menu\'s disclosure button: open by default, closing it hides its entries', () => {
508+
renderAt(`/studio/${PKG}/data`);
509+
const label = groupLabel('studio-menu-group-data');
510+
expect(label.tagName).toBe('BUTTON');
511+
expect(label).toHaveAccessibleName('Data');
512+
expect(label).toHaveAttribute('aria-expanded', 'true');
513+
// The group's list is named by its label.
514+
expect(entry('type:object').closest('ul')).toHaveAttribute('aria-labelledby', label.id);
515+
expect(entry('type:object')).toBeVisible();
516+
517+
fireEvent.click(label);
518+
expect(label).toHaveAttribute('aria-expanded', 'false');
519+
expect(screen.queryByTestId('studio-menu-entry-type:object')).toBeNull();
520+
// CONTROL: the other groups stay open.
521+
expect(entry('type:flow')).toBeVisible();
522+
// No count is drawn on a closed group: a number in this menu is an entry's items.
523+
expect(label).toHaveTextContent(/^Data$/);
524+
525+
fireEvent.click(label);
526+
expect(entry('type:object')).toBeVisible();
527+
});
528+
529+
// On ~all the groups are drawn flat with and without a search, so the
530+
// group the author closed is the same group the search lists into.
531+
it('a search lists its matches in a group the author closed', () => {
532+
renderAt('/studio/~all/metadata', '~all');
533+
const label = groupLabel('studio-menu-group-security');
534+
fireEvent.click(label);
535+
expect(label).toHaveAttribute('aria-expanded', 'false');
536+
expect(screen.queryByTestId('studio-menu-entry-type:position')).toBeNull();
537+
fireEvent.change(screen.getByTestId('studio-menu-search'), { target: { value: 'position' } });
538+
expect(entry('type:position')).toBeVisible();
539+
expect(groupLabel('studio-menu-group-security')).toHaveAttribute('aria-expanded', 'true');
540+
// Drawn open, chevron included: the chevron is turned down as on any open group.
541+
const chevron = () => groupLabel('studio-menu-group-security').querySelector('svg')!;
542+
expect(chevron()).toHaveClass('rotate-90');
543+
// A click while the search holds it open changes nothing.
544+
fireEvent.click(groupLabel('studio-menu-group-security'));
545+
expect(groupLabel('studio-menu-group-security')).toHaveAttribute('aria-expanded', 'true');
546+
expect(chevron()).toHaveClass('rotate-90');
547+
expect(entry('type:position')).toBeVisible();
548+
// The author's choice is kept: clearing the search closes it again.
549+
fireEvent.change(screen.getByTestId('studio-menu-search'), { target: { value: '' } });
550+
expect(screen.queryByTestId('studio-menu-entry-type:position')).toBeNull();
551+
expect(chevron()).not.toHaveClass('rotate-90');
552+
});
553+
554+
it('a click on an open group\'s label during a search is not taken: the group is still open once the search is cleared', () => {
555+
renderAt('/studio/~all/metadata', '~all');
556+
fireEvent.change(screen.getByTestId('studio-menu-search'), { target: { value: 'position' } });
557+
fireEvent.click(groupLabel('studio-menu-group-security'));
558+
expect(groupLabel('studio-menu-group-security')).toHaveAttribute('aria-expanded', 'true');
559+
fireEvent.change(screen.getByTestId('studio-menu-search'), { target: { value: '' } });
560+
expect(groupLabel('studio-menu-group-security')).toHaveAttribute('aria-expanded', 'true');
561+
expect(entry('type:position')).toBeVisible();
562+
});
563+
564+
it('in the phone drawer a group\'s label is the app menu\'s 44 px tap target; CONTROL: docked it is not', async () => {
565+
setWidth(390);
566+
renderAt(`/studio/${PKG}/data`);
567+
fireEvent.click(toggle());
568+
const drawer = await screen.findByRole('dialog');
569+
const label = within(drawer).getByTestId('studio-menu-group-data').querySelector('[data-sidebar="group-label"]')!;
570+
expect(label).toHaveClass('min-h-[44px]');
571+
cleanup();
572+
setWidth(1280);
573+
renderAt(`/studio/${PKG}/data`);
574+
expect(groupLabel('studio-menu-group-data')).not.toHaveClass('min-h-[44px]');
575+
});
576+
577+
it('an entry draws a bare line icon before its name, on the app menu\'s row', () => {
578+
renderAt(`/studio/${PKG}/data`);
579+
for (const key of ['type:object', 'type:flow', 'type:permission']) {
580+
const icon = screen.getByTestId(`studio-menu-icon-${key}`);
581+
expect(icon.tagName.toLowerCase()).toBe('svg');
582+
expect(icon).toHaveAttribute('aria-hidden', 'true');
583+
// No tile: the icon is the row's own child, the first one.
584+
expect(icon.parentElement).toBe(entry(key));
585+
expect(entry(key).firstElementChild).toBe(icon);
586+
expect(entry(key)).toHaveAttribute('data-sidebar', 'menu-button');
587+
}
588+
// A type and an entry that is not one each draw an icon, the fold's too.
589+
fireEvent.click(fold());
590+
expect(screen.getByTestId('studio-menu-icon-type:hook').tagName.toLowerCase()).toBe('svg');
591+
expect(screen.getByTestId('studio-menu-icon-owd').tagName.toLowerCase()).toBe('svg');
592+
});
593+
594+
it('the current entry is the primitive\'s active row (the pill and its left bar), and only it', () => {
595+
renderAt(`/studio/${PKG}/metadata/flow?package=${PKG}`);
596+
expect(entry('type:flow')).toHaveAttribute('data-active', 'true');
597+
expect(entry('type:object')).toHaveAttribute('data-active', 'false');
598+
// Its count is not muted: it reads with the selected name.
599+
expect(screen.getByTestId('studio-menu-count-type:flow')).not.toHaveClass('text-muted-foreground');
600+
});
601+
602+
describe('the selected entry is tinted by Studio\'s graphite whatever the app\'s theme colour is', () => {
603+
const ROOT_TOKENS = ['--primary', '--primary-foreground', '--ring', '--sidebar-primary', '--sidebar-ring', '--accent', '--accent-foreground'];
604+
605+
function Branded({ children }: { children: ReactNode }) {
606+
// A non-default app theme: a rose primary and an amber accent, written on the page root by the app shell's own hook.
607+
useAppShellBranding({ primaryColor: '#e11d48', accentColor: '#f59e0b' });
608+
return <>{children}</>;
609+
}
610+
611+
afterEach(() => {
612+
for (const token of ROOT_TOKENS) document.documentElement.style.removeProperty(token);
613+
for (const token of ['--brand-primary', '--brand-primary-hsl', '--brand-accent', '--brand-accent-hsl']) document.documentElement.style.removeProperty(token);
614+
});
615+
616+
/** The declarations a class string makes: `[--x:a_b]` and `dark:[--x:a_b]`, underscores read as spaces. */
617+
function declarations(classes: string, dark: boolean): Map<string, string> {
618+
const out = new Map<string, string>();
619+
for (const cls of classes.split(/\s+/)) {
620+
const m = /^(dark:)?\[(--[\w-]+):(.+)\]$/.exec(cls);
621+
if (m && !!m[1] === dark) out.set(m[2], m[3].replace(/_/g, ' '));
622+
}
623+
return out;
624+
}
625+
626+
it('every theme token the app\'s branding writes on the page root is rebound to graphite over the selected entry, light and dark', () => {
627+
render(
628+
<MemoryRouter initialEntries={[`/studio/${PKG}/metadata/flow?package=${PKG}`]}>
629+
<Branded>
630+
<Routes>
631+
<Route path="*" element={<Shell segment={PKG} />} />
632+
</Routes>
633+
</Branded>
634+
</MemoryRouter>,
635+
);
636+
// CONTROL: the app's theme is not the default — its colour is on the page root.
637+
const root = document.documentElement.style;
638+
const written = [...Array.from({ length: root.length }, (_, i) => root.item(i))].filter(
639+
// `--brand-*` are the hook's hex aliases; no sidebar or menu class reads them.
640+
(token) => token.startsWith('--') && !token.startsWith('--brand-'),
641+
);
642+
expect(written).toContain('--primary');
643+
expect(written).toContain('--accent');
644+
expect(root.getPropertyValue('--primary').trim()).not.toBe(STUDIO_ACCENT_HSL.light);
645+
646+
// The selected entry is the active row, and it sits inside Studio's accent scope.
647+
const selected = entry('type:flow');
648+
expect(selected).toHaveAttribute('data-active', 'true');
649+
const scope = selected.closest<HTMLElement>('[data-studio-accent]');
650+
expect(scope).not.toBeNull();
651+
for (const cls of STUDIO_ACCENT.split(/\s+/)) expect(scope).toHaveClass(cls);
652+
// Nothing between the scope and the entry writes a theme token back.
653+
for (let el: HTMLElement | null = selected; el && el !== scope; el = el.parentElement) {
654+
for (const token of written) expect(el.style.getPropertyValue(token), `${token} on ${el.tagName}`).toBe('');
655+
}
656+
657+
const light = declarations(STUDIO_ACCENT, false);
658+
const dark = declarations(STUDIO_ACCENT, true);
659+
for (const token of written) {
660+
expect(light.has(token), `${token} rebound in the light theme`).toBe(true);
661+
expect(dark.has(token), `${token} rebound in the dark theme`).toBe(true);
662+
}
663+
expect(light.get('--primary')).toBe(STUDIO_ACCENT_HSL.light);
664+
expect(dark.get('--primary')).toBe(STUDIO_ACCENT_HSL.dark);
665+
});
666+
});
667+
});

0 commit comments

Comments
 (0)