Skip to content

Commit 5c76b35

Browse files
committed
test(app-shell): pin the lazily registered Studio canvas default
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5ousB2MKFUbJFc3Hwp
1 parent 237660a commit 5c76b35

2 files changed

Lines changed: 59 additions & 5 deletions

File tree

‎ui/packages/app-shell/src/console/__tests__/openPathObjectReaders-12811.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const OBJECTS_READERS: Record<string, { kind: Kind; why: string }> = {
126126
kind: 'off',
127127
why: "Studio: the object's view labels New view refuses to reuse, the read the list-view panel made before the switcher moved into the header (objectstack#30046)",
128128
},
129-
'packages/app-shell/src/views/studio-design/studio-canvas-preview.tsx': { kind: 'off', why: 'Studio' },
129+
'packages/app-shell/src/views/studio-design/studio-object-records-canvas.tsx': { kind: 'off', why: 'Studio' },
130130
'packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx': {
131131
kind: 'off',
132132
why: "Studio: the Data pillar's Form tab asks selectRecordFormView which form view the app opens, over the served objects (objectstack#30057)",

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

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ import {
3030
StudioObjectRecordsCanvas,
3131
} from './studio-canvas-preview';
3232
import type { StudioCanvasListView } from './studio-canvas-preview';
33+
// The grid's own module: the registry above holds it behind a lazy wrapper of
34+
// the same name (objectstack#33582), so the grid's behaviour is pinned on the
35+
// module's component, and the wrapper by the lazy-registration block below.
36+
import { StudioObjectRecordsCanvas as ObjectRecordsCanvas } from './studio-object-records-canvas';
3337

3438
describe('studio-canvas-preview registry', () => {
3539
it('ships a built-in default for `object` (the records grid)', () => {
@@ -104,7 +108,7 @@ describe('navEntryListTarget — the runtime reading of an object entry (objectu
104108
});
105109
});
106110

107-
describe('StudioObjectRecordsCanvas — renders the entry it is open on (objectui#11774)', () => {
111+
describe('the default object canvas — renders the entry it is open on (objectui#11774)', () => {
108112
/** Stands in for `plugin-view`'s `object-view`, recording the schema it is handed. */
109113
function ObjectViewRecorder({ schema }: { schema: Record<string, unknown> }) {
110114
return <pre data-testid="object-view-schema">{JSON.stringify(schema)}</pre>;
@@ -134,7 +138,7 @@ describe('StudioObjectRecordsCanvas — renders the entry it is open on (objectu
134138
render(
135139
<MetadataCtx.Provider value={METADATA}>
136140
<StudioCanvasNavEntryContext.Provider value={entry}>
137-
<StudioObjectRecordsCanvas type="object" name="showcase_task" draft={{}} />
141+
<ObjectRecordsCanvas type="object" name="showcase_task" draft={{}} />
138142
</StudioCanvasNavEntryContext.Provider>
139143
</MetadataCtx.Provider>,
140144
);
@@ -177,7 +181,7 @@ describe('StudioObjectRecordsCanvas — renders the entry it is open on (objectu
177181
* it is editing: the panel's buffer, handed over through
178182
* `StudioCanvasListViewContext` (beside the published props, like the entry).
179183
*/
180-
describe('StudioObjectRecordsCanvas — shows the list view its panel edits (objectui#11823)', () => {
184+
describe('the default object canvas — shows the list view its panel edits (objectui#11823)', () => {
181185
function ObjectViewRecorder({ schema }: { schema: Record<string, unknown> }) {
182186
return <pre data-testid="object-view-schema">{JSON.stringify(schema)}</pre>;
183187
}
@@ -212,7 +216,7 @@ describe('StudioObjectRecordsCanvas — shows the list view its panel edits (obj
212216
<MetadataCtx.Provider value={METADATA}>
213217
<StudioCanvasNavEntryContext.Provider value={entry}>
214218
<StudioCanvasListViewContext.Provider value={edited}>
215-
<StudioObjectRecordsCanvas type="object" name="showcase_task" draft={{}} />
219+
<ObjectRecordsCanvas type="object" name="showcase_task" draft={{}} />
216220
</StudioCanvasListViewContext.Provider>
217221
</StudioCanvasNavEntryContext.Provider>
218222
</MetadataCtx.Provider>,
@@ -254,3 +258,53 @@ describe('StudioObjectRecordsCanvas — shows the list view its panel edits (obj
254258
});
255259
});
256260
});
261+
262+
/**
263+
* objectstack#33582 — the registered `object` default is a lazy wrapper of the
264+
* grid's module, not the module's component: the registry module is imported
265+
* by the package entry at load, so a by-value default held the grid and the
266+
* designer strings in the console's eager closure. Drawn through the registry,
267+
* as `StudioDesignSurface` draws it, the wrapper shows its loading line, then
268+
* the grid with the schema the module's own component renders.
269+
*/
270+
describe('the registered object default loads the grid on first draw (objectstack#33582)', () => {
271+
function ObjectViewRecorder({ schema }: { schema: Record<string, unknown> }) {
272+
return <pre data-testid="object-view-schema">{JSON.stringify(schema)}</pre>;
273+
}
274+
const METADATA: MetadataContextValue = {
275+
apps: [],
276+
objects: [{ name: 'showcase_task', label: 'Task' }],
277+
dashboards: [],
278+
reports: [],
279+
pages: [],
280+
loading: false,
281+
error: null,
282+
refresh: async () => {},
283+
invalidate: () => {},
284+
ensureType: async () => [],
285+
getItem: async () => null,
286+
getItemsByType: () => [],
287+
};
288+
289+
beforeAll(() => {
290+
ComponentRegistry.register('object-view', ObjectViewRecorder as never, { namespace: 'plugin-view' });
291+
});
292+
afterEach(cleanup);
293+
294+
it('the default is the wrapper, not the grid module\'s own component', () => {
295+
expect(getStudioCanvasPreview('object')).toBe(StudioObjectRecordsCanvas);
296+
expect(StudioObjectRecordsCanvas).not.toBe(ObjectRecordsCanvas);
297+
});
298+
299+
it('drawn through the registry, it loads and draws the grid', async () => {
300+
const Canvas = getStudioCanvasPreview('object')!;
301+
render(
302+
<MetadataCtx.Provider value={METADATA}>
303+
<Canvas type="object" name="showcase_task" draft={{}} />
304+
</MetadataCtx.Provider>,
305+
);
306+
const grid = await screen.findByTestId('object-view-schema');
307+
expect(JSON.parse(grid.textContent ?? 'null')).toEqual({ type: 'object-view', objectName: 'showcase_task' });
308+
expect(screen.queryByText('Loading studio canvas…')).toBeNull();
309+
});
310+
});

0 commit comments

Comments
 (0)