Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 86ef0c7

Browse files
os-justinclaude
andauthored
test(app-shell): pin the two already-honest studio-design consumers on an empty registry, and the populated contrast (#8619)
The three repairs objectui#6846 asks for — the Data pillar field rail that swallowed a field click, the actions pane that rendered a bare label, and the Interfaces canvas that blamed the roadmap — already landed on main in #7120 (#6795 part C), each with its own empty-registry pin. What #7120 deliberately left unpinned are the two consumers its measurement found already honest: - ObjectSettingsPanel prints "No default object inspector registered." in the Basics section and keeps rendering the sections that do not read the registry; - ObjectHooksPanel falls back to the generic SchemaForm, and that form edits and saves the hook. Both are pinned here with the same shape as the sibling pins: the registries are asserted empty FIRST, with a control that must hit, and the assertion names the specific visible controls rather than "something rendered". The populated contrast pins the wrong fix on this axis — an empty-state branch that fires whenever the lookup is falsy and swallows the populated path: with the builtin inspectors registered, a field click opens the real ObjectFieldInspector, Actions mounts the real ActionDefaultInspector, Hooks mounts the curated HookDefaultInspector (not the generic form), Settings mounts the real ObjectDefaultInspector, and none of the empty-state sentences appears. Test only; the changeset declares no release. Claude-Session: https://claude.ai/code/session_01YBWFb5YgMU5dw8p2VKj16S Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7b43319 commit 86ef0c7

4 files changed

Lines changed: 426 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
---
3+
4+
Pin the two studio-design consumers that were already honest on an empty
5+
metadata registry — `ObjectSettingsPanel` ("No default object inspector
6+
registered.") and `ObjectHooksPanel` (a working generic `SchemaForm`) — and
7+
add the populated-registry contrast for the Data pillar's four consumers, so a
8+
future refactor cannot move either into the silent class, and an over-eager
9+
empty-state branch cannot swallow the populated path (objectui#6846). Test
10+
only; no package is released by this change.
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectui#6846 — the Data pillar's four registry consumers on a POPULATED
5+
* registry: the contrast half of the empty-registry pins.
6+
*
7+
* ## The wrong fix this file exists to catch
8+
*
9+
* The empty-state repairs (#7120) and pins (#7120 + this card) all say what
10+
* a consumer must show when its registry read returns `undefined`. The
11+
* plausible wrong fix on that axis is an empty-state branch that fires
12+
* whenever the lookup is falsy in some wider sense — a guard inverted, a
13+
* `!!` dropped, a branch reordered — so that "the empty case now speaks"
14+
* while every populated screen goes blank or shows the notice. None of the
15+
* empty-registry files can see that: their registries are empty by
16+
* construction. So this file registers the builtin inspectors FIRST, proves
17+
* they are there, and pins that with them present:
18+
*
19+
* - a field click opens the REAL `ObjectFieldInspector`;
20+
* - Actions mounts the REAL `ActionDefaultInspector`;
21+
* - Hooks mounts the curated `HookDefaultInspector`, not the generic form;
22+
* - Settings mounts the REAL `ObjectDefaultInspector`;
23+
*
24+
* and that none of the empty-state sentences appears anywhere on screen.
25+
* Each case asserts a control only the real editor renders BEFORE it asserts
26+
* the notice's absence, so a blank screen reds on the positive, not on an
27+
* absence that a blank screen would satisfy.
28+
*
29+
* The fifth consumer, the Interfaces canvas, has its populated contrast in
30+
* {@link file://./StudioDesignSurface.designerRegistryPartial.test.tsx}.
31+
*
32+
* ## Why a separate file
33+
*
34+
* The registries are plain `Map`s — module state shared by every test in a
35+
* file. Splitting empty from populated is what lets each file assert its own
36+
* precondition instead of depending on test order. Same convention as the
37+
* `designerRegistryMissing` / `designerRegistryPartial` pair.
38+
*/
39+
40+
import '@testing-library/jest-dom/vitest';
41+
import * as React from 'react';
42+
import { describe, it, expect, vi, afterEach } from 'vitest';
43+
import { render, screen, fireEvent, cleanup, waitFor, within } from '@testing-library/react';
44+
import { MemoryRouter } from 'react-router-dom';
45+
46+
const objectDef = {
47+
name: 'showcase_task',
48+
label: 'Task',
49+
fields: [{ name: 'title', label: 'Title', type: 'text' }],
50+
actions: [{ name: 'send_email', label: 'Send Email', type: 'quick' }],
51+
};
52+
53+
const hook = {
54+
name: 'guard_hook',
55+
label: 'Guard',
56+
object: 'showcase_task',
57+
events: ['beforeInsert'],
58+
handler: 'guard_fn',
59+
};
60+
61+
const mockClient = {
62+
save: vi.fn(async () => ({})),
63+
list: vi.fn(async (type: string) => {
64+
if (type === 'object') return [{ name: 'showcase_task', label: 'Task' }];
65+
if (type === 'hook') return [hook];
66+
return [];
67+
}),
68+
listDrafts: vi.fn(async () => []),
69+
layered: vi.fn(async () => ({ effective: objectDef, code: objectDef })),
70+
getDraft: vi.fn(async () => null),
71+
// The curated hook editor resolves the bound object's field catalog through
72+
// `useObjectFields` -> `client.get`.
73+
get: vi.fn(async () => null),
74+
};
75+
76+
vi.mock('../metadata-admin/useMetadata', async (importOriginal) => {
77+
const mod = await importOriginal<typeof import('../metadata-admin/useMetadata')>();
78+
return { ...mod, useMetadataClient: () => mockClient, useMetadataTypes: () => ({ entries: [] }) };
79+
});
80+
81+
vi.mock('./packages-io', async (importOriginal) => {
82+
const mod = await importOriginal<typeof import('./packages-io')>();
83+
return { ...mod, fetchPackages: vi.fn(async () => []) };
84+
});
85+
86+
// objectui#5813 — the advanced tabs live in a Radix DropdownMenu; this file
87+
// measures which editor mounts, not radix's open/close machinery, so the menu
88+
// renders as plain passthroughs (same convention as DataPillar.panelGate).
89+
type Passthrough = { children?: React.ReactNode };
90+
vi.mock('@object-ui/components', async (importOriginal) => {
91+
const mod = await importOriginal<typeof import('@object-ui/components')>();
92+
return {
93+
...mod,
94+
DropdownMenu: (p: Passthrough) => <div>{p.children}</div>,
95+
DropdownMenuTrigger: (p: Passthrough) => <div>{p.children}</div>,
96+
DropdownMenuContent: (p: Passthrough) => <div>{p.children}</div>,
97+
DropdownMenuItem: (p: Passthrough & { onSelect?: () => void }) => (
98+
<button type="button" onClick={() => p.onSelect?.()}>{p.children}</button>
99+
),
100+
};
101+
});
102+
103+
vi.mock('@object-ui/react', async (importOriginal) => {
104+
const mod = await importOriginal<typeof import('@object-ui/react')>();
105+
return { ...mod, useAdapter: () => ({}) };
106+
});
107+
108+
import { DataPillar } from './StudioDesignSurface';
109+
import { registerBuiltinInspectors } from '../metadata-admin/inspectors';
110+
import { listMetadataInspectorTypes, getMetadataInspector } from '../metadata-admin/inspector-registry';
111+
import { getMetadataDefaultInspector } from '../metadata-admin/default-inspector-registry';
112+
113+
// The populated precondition — registered here, proved in every test below.
114+
registerBuiltinInspectors();
115+
116+
/** The four empty-state sentences the Data pillar's consumers can show. */
117+
const EMPTY_STATE_SENTENCES = [
118+
'No field inspector is registered in this session, so this field’s properties cannot be edited here.',
119+
'No action editor is registered in this session, so this action’s properties cannot be edited here.',
120+
'No default object inspector registered.',
121+
'No metadata designers are registered in this session',
122+
];
123+
124+
afterEach(cleanup);
125+
126+
/**
127+
* Assert the registries really are populated — stated, not assumed, so an
128+
* assertion below cannot pass for the wrong reason (a builtin that silently
129+
* stopped registering would otherwise turn every case here into an
130+
* empty-registry case that happens to render).
131+
*/
132+
function assertRegistriesPopulated(): void {
133+
expect(listMetadataInspectorTypes()).toContain('object');
134+
expect(getMetadataInspector('object')).toBeTypeOf('function');
135+
expect(getMetadataDefaultInspector('object')).toBeTypeOf('function');
136+
expect(getMetadataDefaultInspector('action')).toBeTypeOf('function');
137+
expect(getMetadataDefaultInspector('hook')).toBeTypeOf('function');
138+
}
139+
140+
function expectNoEmptyStateSentence(): void {
141+
const text = document.body.textContent ?? '';
142+
for (const sentence of EMPTY_STATE_SENTENCES) expect(text).not.toContain(sentence);
143+
}
144+
145+
function renderPillar() {
146+
render(
147+
<MemoryRouter initialEntries={['/studio/com.example.showcase/data']}>
148+
<DataPillar packageId="com.example.showcase" />
149+
</MemoryRouter>,
150+
);
151+
}
152+
153+
describe('Data pillar consumers with the registries POPULATED (#6846 contrast)', () => {
154+
it('a field click opens the real field inspector, not the missing-inspector notice', async () => {
155+
assertRegistriesPopulated();
156+
renderPillar();
157+
158+
fireEvent.click(await screen.findByRole('button', { name: 'Form' }));
159+
const card = (await screen.findByText('Title')).closest('.cursor-grab') as HTMLElement;
160+
expect(card).toBeTruthy();
161+
fireEvent.click(card);
162+
163+
const rail = await waitFor(() => {
164+
const el = document.querySelector('aside');
165+
expect(el).toBeTruthy();
166+
return el as HTMLElement;
167+
});
168+
expect(rail).toHaveTextContent('Field properties');
169+
// `ObjectFieldInspector`'s own API-name control, carrying the field's name.
170+
expect(await within(rail).findByDisplayValue('title')).toBeInTheDocument();
171+
expectNoEmptyStateSentence();
172+
});
173+
174+
it('Actions mounts the real action editor, not the missing-editor notice', async () => {
175+
assertRegistriesPopulated();
176+
renderPillar();
177+
178+
fireEvent.click(await screen.findByRole('button', { name: 'Actions' }));
179+
// `ActionDefaultInspector`'s Name control, carrying the action's identifier.
180+
expect(await screen.findByDisplayValue('send_email')).toBeInTheDocument();
181+
expectNoEmptyStateSentence();
182+
});
183+
184+
it('Hooks mounts the curated hook editor, not the generic form', async () => {
185+
assertRegistriesPopulated();
186+
renderPillar();
187+
188+
fireEvent.click(await screen.findByRole('button', { name: 'Hooks' }));
189+
fireEvent.click(await screen.findByText('Guard'));
190+
// Controls only `HookDefaultInspector` renders…
191+
expect(await screen.findByTestId('hook-name')).toBeInTheDocument();
192+
expect(screen.getByTestId('hook-body-source')).toBeInTheDocument();
193+
// …and none the generic `SchemaForm` would have synthesised from the
194+
// hook's keys (the empty-registry pin asserts this one is PRESENT).
195+
expect(screen.queryByLabelText('Handler')).toBeNull();
196+
expectNoEmptyStateSentence();
197+
});
198+
199+
it('Settings mounts the real object inspector, not the missing-inspector notice', async () => {
200+
assertRegistriesPopulated();
201+
renderPillar();
202+
203+
fireEvent.click(await screen.findByRole('button', { name: 'Settings' }));
204+
// `ObjectDefaultInspector`'s Name control, carrying the object's name.
205+
expect(await screen.findByTestId('object-name-input')).toHaveValue('showcase_task');
206+
expect(screen.getByTestId('object-access-posture')).toBeInTheDocument();
207+
expectNoEmptyStateSentence();
208+
});
209+
});
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectui#6846 — the Hooks panel on an EMPTY default-inspector registry.
5+
*
6+
* The second of the two consumers #7120 (#6795 part C) measured as already
7+
* honest and deliberately left unpinned: with `getMetadataDefaultInspector('hook')`
8+
* undefined the panel falls back to the generic `SchemaForm`, which synthesises
9+
* a control per top-level key of the selected hook. That is a working editor,
10+
* not an empty state — so the pin has to prove it WORKS, not merely that
11+
* something rendered: an edit in the generic form dirties the panel, enables
12+
* its own Save, and the save writes the edited value through.
13+
*
14+
* "Something rendered" would pass on the hook's bare label — exactly the shape
15+
* of the `ObjectActionsPanel` defect the card repaired — which is why the
16+
* assertions below name the generic form's controls and drive one of them.
17+
*
18+
* The populated contrast, where the curated `HookDefaultInspector` mounts and
19+
* the generic form must NOT, is
20+
* {@link file://./DataPillar.designerRegistryPopulated.test.tsx}.
21+
*
22+
* ⚠️ This file must never register a designer — its subject is the empty
23+
* branch, and the registries are module state shared by every test in a file.
24+
* Emptiness is asserted FIRST, with a control that must hit.
25+
*/
26+
27+
import '@testing-library/jest-dom/vitest';
28+
import * as React from 'react';
29+
import { describe, it, expect, vi, afterEach } from 'vitest';
30+
import { render, screen, fireEvent, cleanup, waitFor } from '@testing-library/react';
31+
32+
const hook = {
33+
name: 'guard_hook',
34+
label: 'Guard',
35+
object: 'showcase_task',
36+
events: ['beforeInsert'],
37+
handler: 'guard_fn',
38+
};
39+
40+
const mockClient = {
41+
list: vi.fn(async () => [hook]),
42+
listDrafts: vi.fn(async () => []),
43+
getDraft: vi.fn(async () => null),
44+
get: vi.fn(async () => null),
45+
save: vi.fn(async () => ({})),
46+
};
47+
48+
vi.mock('../metadata-admin/useMetadata', async (importOriginal) => {
49+
const mod = await importOriginal<typeof import('../metadata-admin/useMetadata')>();
50+
return { ...mod, useMetadataClient: () => mockClient };
51+
});
52+
53+
import { ObjectHooksPanel } from './ObjectHooksPanel';
54+
import { listMetadataPreviewTypes } from '../metadata-admin/preview-registry';
55+
import { listMetadataInspectorTypes } from '../metadata-admin/inspector-registry';
56+
import { getMetadataDefaultInspector } from '../metadata-admin/default-inspector-registry';
57+
import { getStudioCanvasPreview } from './studio-canvas-preview';
58+
59+
afterEach(() => {
60+
cleanup();
61+
mockClient.save.mockClear();
62+
});
63+
64+
/** Same shape as the sibling pins: a control that MUST hit, then the zeros. */
65+
function assertRegistriesEmptyWithControl(): void {
66+
expect(getStudioCanvasPreview('object')).toBeTypeOf('function'); // control — MUST hit
67+
expect(listMetadataPreviewTypes()).toEqual([]);
68+
expect(listMetadataInspectorTypes()).toEqual([]);
69+
expect(getMetadataDefaultInspector('hook')).toBeUndefined();
70+
expect(getMetadataDefaultInspector('object')).toBeUndefined();
71+
expect(getMetadataDefaultInspector('action')).toBeUndefined();
72+
}
73+
74+
describe('ObjectHooksPanel — no curated hook editor registered (#6846)', () => {
75+
it('falls back to the generic SchemaForm, and that form edits and saves the hook', async () => {
76+
assertRegistriesEmptyWithControl();
77+
78+
render(<ObjectHooksPanel objectName="showcase_task" packageId="com.example.showcase" />);
79+
fireEvent.click(await screen.findByText('Guard'));
80+
81+
// The generic form: one labelled control per top-level key of the hook,
82+
// carrying the hook's own values. These labels are synthesised from the
83+
// keys, which is what makes them the generic form's signature.
84+
const handler = await screen.findByLabelText('Handler');
85+
expect(handler).toHaveValue('guard_fn');
86+
expect(screen.getByLabelText('Name')).toHaveValue('guard_hook');
87+
// The curated editor is NOT what rendered — its controls carry test ids
88+
// the generic form never produces.
89+
expect(screen.queryByTestId('hook-name')).toBeNull();
90+
// Nothing on screen promises recovery, and nothing calls this an empty
91+
// state — it is an editor.
92+
expect(document.body.textContent ?? '').not.toMatch(/loading|try again/i);
93+
94+
// "Working": an edit in the generic form dirties the panel and enables
95+
// its own Save…
96+
const save = screen.getByRole('button', { name: /Save/i });
97+
expect(save).toBeDisabled();
98+
fireEvent.change(handler, { target: { value: 'guard_fn_v2' } });
99+
await waitFor(() => expect(save).toBeEnabled());
100+
// …and Save writes the edited value through, as a draft of THIS hook.
101+
fireEvent.click(save);
102+
await waitFor(() => expect(mockClient.save).toHaveBeenCalledTimes(1));
103+
expect(mockClient.save).toHaveBeenCalledWith(
104+
'hook',
105+
'guard_hook',
106+
expect.objectContaining({ handler: 'guard_fn_v2' }),
107+
{ mode: 'draft', packageId: 'com.example.showcase' },
108+
);
109+
});
110+
});

0 commit comments

Comments
 (0)