Skip to content

Commit 615a9c0

Browse files
committed
test(app-shell): pin inline locale-map view and page labels; add changeset
Claude-Session: https://claude.ai/code/session_01WVwANq56oyBZtcDWbWGfva Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4c0d827 commit 615a9c0

4 files changed

Lines changed: 441 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): a list view or interface page whose `label` is an inline locale map is named in the viewer's language, and a map view label no longer takes the Console down
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
- **View labels.** `ListViewSchema` types a view's `label` as `I18nLabel`, and the server overlays only catalog text, so a map with no `_views` catalog entry reaches the Console as authored. `viewTabLabel` returned that map untouched. The app header then rendered it as a React child on a `/view/NAME` route and threw. The header sits outside the route's error boundary, so the whole Console went blank. The object page's tab bar, the mobile view switcher and the record page's way back read the same value. `viewTabLabel` now resolves the map in the viewer's language first, so all of them draw a string. A map that resolves to no text is drawn as the object's plural label, like a view with no `label`.
11+
- **Interface list pages.** A page whose `label` is a map showed its machine name as the heading and as the record drawer's title, and a map `description` was dropped. Both now resolve in the viewer's language. The machine name is used only when no label resolves.
12+
13+
What to do: nothing. Metadata that already carries inline locale-map labels now renders as authored.
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #25901 — on a `/apps/APP/OBJECT/view/NAME` route, a view whose `label` is an
5+
* inline locale map is titled in the viewer's language.
6+
*
7+
* ## The defect
8+
*
9+
* `ListViewSchema` types a view's `label` as `I18nLabel`: a string or an
10+
* inline locale map. The server overlays only catalog text
11+
* (`translateObjectListViews`), so a map with no `_views.KEY.label` catalog
12+
* entry is served as authored. `viewTabLabel` handed it on untouched — drawn
13+
* as given on the served branch, offered to the bundle as the fallback on the
14+
* other — and the header rendered the object as a React child. The header is
15+
* mounted outside the route's error boundary, so the throw unmounted the whole
16+
* console. Measured before the change with this file's harness: both cells
17+
* below threw `Objects are not valid as a React child (found: object with keys
18+
* {en, zh-CN})` and left the body empty.
19+
*
20+
* ## The rule
21+
*
22+
* `viewTabLabel` resolves the label with `metadataText` in the viewer's
23+
* language before either branch, so every caller — this header, the tab bar,
24+
* the mobile switcher, the record page's way back — receives a string. A map
25+
* that resolves to no text counts as no label: the object's plural label.
26+
*
27+
* Harness: `AppHeader.labelLessViewTitle-12805`'s, with an empty translation
28+
* bundle so no catalog entry can stand in for the map.
29+
*
30+
* Directions, written before the run: the map cells RED before the change (the
31+
* throw), GREEN after; the empty-map cell draws the plural label.
32+
*/
33+
import '@testing-library/jest-dom/vitest';
34+
import { describe, it, expect, vi, afterEach } from 'vitest';
35+
import { render, screen, cleanup } from '@testing-library/react';
36+
37+
const route = vi.hoisted(() => ({ pathname: '/apps/showcase_app/recheck_gate/view/default' }));
38+
const meta = vi.hoisted(() => ({ value: null as any }));
39+
40+
vi.mock('react-router-dom', () => ({
41+
useLocation: () => ({ pathname: route.pathname, search: '', hash: '', state: null, key: 't' }),
42+
useParams: () => ({ appName: 'showcase_app' }),
43+
useNavigate: () => vi.fn(),
44+
useSearchParams: () => [new URLSearchParams(), vi.fn()] as const,
45+
Link: ({ children, to, ...p }: any) => <a href={String(to)} {...p}>{children}</a>,
46+
}));
47+
48+
vi.mock('@object-ui/components', async (importOriginal) => {
49+
const actual = await importOriginal<Record<string, unknown>>();
50+
const stripProps = (p: any) => {
51+
const { asChild, variant, size, align, sideOffset, onOpenChange, ...rest } = p ?? {};
52+
return rest;
53+
};
54+
const Pass = ({ children, ...p }: any) => <div {...stripProps(p)}>{children}</div>;
55+
return {
56+
...actual,
57+
Button: ({ children, asChild, variant, size, ...p }: any) => (
58+
<button type="button" {...p}>{children}</button>
59+
),
60+
DropdownMenu: Pass,
61+
DropdownMenuTrigger: Pass,
62+
DropdownMenuContent: () => null,
63+
DropdownMenuItem: () => null,
64+
DropdownMenuLabel: () => null,
65+
DropdownMenuSeparator: () => null,
66+
DropdownMenuGroup: Pass,
67+
Avatar: Pass,
68+
AvatarImage: () => null,
69+
AvatarFallback: Pass,
70+
Popover: Pass,
71+
PopoverTrigger: Pass,
72+
PopoverContent: () => null,
73+
Tabs: Pass,
74+
TabsList: Pass,
75+
TabsTrigger: ({ children }: any) => <button type="button">{children}</button>,
76+
TabsContent: Pass,
77+
cn: (...c: any[]) => c.filter(Boolean).join(' '),
78+
};
79+
});
80+
81+
vi.mock('lucide-react', () => {
82+
const Icon = () => <span />;
83+
return new Proxy({ __esModule: true } as Record<string | symbol, unknown>, {
84+
get: (target, prop) => {
85+
if (prop === 'then' || prop === '__esModule' || typeof prop === 'symbol') return target[prop];
86+
return Icon;
87+
},
88+
has: (_target, prop) => prop !== 'then',
89+
});
90+
});
91+
92+
vi.mock('@object-ui/react', async (importOriginal) => ({
93+
...(await importOriginal<Record<string, unknown>>()),
94+
useOffline: () => ({ isOnline: true }),
95+
}));
96+
vi.mock('@object-ui/collaboration', async (importOriginal) => ({
97+
...(await importOriginal<Record<string, unknown>>()),
98+
PresenceAvatars: () => null,
99+
useTenantPresence: () => [],
100+
}));
101+
vi.mock('../ModeToggle', () => ({ ModeToggle: () => null }));
102+
vi.mock('../LocaleSwitcher', () => ({ LocaleSwitcher: () => null }));
103+
vi.mock('../ConnectionStatus', () => ({ ConnectionStatus: () => null }));
104+
vi.mock('../AppSwitcher', () => ({ AppSwitcher: () => null }));
105+
vi.mock('../LocalizedSidebarTrigger', () => ({ LocalizedSidebarTrigger: () => null }));
106+
vi.mock('../PreviewBadge', () => ({ PreviewBadge: () => null }));
107+
vi.mock('../WorkspaceSwitcher', () => ({ WorkspaceSwitcher: () => null }));
108+
109+
// ONE module-scope fetch double, never torn down: the header's pollers fire and
110+
// forget, and may read after a test body returns (see the sibling suites).
111+
vi.stubGlobal(
112+
'fetch',
113+
vi.fn(async () =>
114+
new Response(JSON.stringify({ data: [], items: [], agents: [], requests: [] }), {
115+
status: 200,
116+
headers: { 'Content-Type': 'application/json' },
117+
}),
118+
),
119+
);
120+
121+
// The header reads its lists through this module; the served-view question goes
122+
// to the same context through `@object-ui/react` (provided below) — one value.
123+
vi.mock('../../providers/MetadataProvider', () => ({ useMetadata: () => meta.value }));
124+
vi.mock('../../context/NavigationContext.js', () => ({
125+
useNavigationContext: () => ({ currentAppName: 'showcase_app', recordTitle: undefined }),
126+
}));
127+
vi.mock('@object-ui/auth', async (importOriginal) => {
128+
// ONE stable identity — a fresh closure per render re-arms every
129+
// `[getAuthConfig]` effect forever (see the sibling suites).
130+
const getAuthConfig = () => Promise.resolve({ features: { multiOrgEnabled: false } });
131+
return {
132+
...(await importOriginal<Record<string, unknown>>()),
133+
useAuth: () => ({
134+
user: { id: 'u1', name: 'Zhang San', email: 'zs@example.com' },
135+
signOut: vi.fn(),
136+
isAuthEnabled: true,
137+
organizations: [],
138+
activeOrganization: null,
139+
isOrganizationsLoading: false,
140+
switchOrganization: vi.fn(),
141+
getAuthConfig,
142+
}),
143+
getUserInitials: () => 'ZS',
144+
useWorkspaceAdminStatus: () => ({ isAdmin: true, isResolved: true }),
145+
};
146+
});
147+
const fakeAdapter = { find: () => Promise.resolve({ data: [] }), getClient: () => undefined };
148+
vi.mock('../../providers/AdapterProvider', () => ({ useAdapter: () => fakeAdapter }));
149+
150+
import { I18nProvider } from '@object-ui/i18n';
151+
import { MetadataCtx } from '@object-ui/react';
152+
import { AppHeader } from '../AppHeader';
153+
154+
afterEach(cleanup);
155+
156+
const OBJECT_NAME = 'recheck_gate';
157+
const PLURAL = 'QA Gates';
158+
const SERVED_LABEL = { en: 'My gates', 'zh-CN': '我的关卡' } as const;
159+
const DERIVED_LABEL = { en: 'Derived gates', 'zh-CN': '派生关卡' } as const;
160+
161+
/** No catalog entry for any view: the map is the only text there is. */
162+
const BUNDLE = { en: {}, 'zh-CN': {} };
163+
164+
/**
165+
* The `/meta/object` answer embeds `served_map` (a served view) and
166+
* `empty_map`; the object as `MetadataProvider` merges it also carries
167+
* `derived_map`, which no server read served.
168+
*/
169+
function world() {
170+
const doc = {
171+
name: OBJECT_NAME,
172+
label: 'QA Gate',
173+
pluralLabel: PLURAL,
174+
listViews: {
175+
served_map: { type: 'grid', label: SERVED_LABEL },
176+
empty_map: { type: 'grid', label: {} },
177+
},
178+
};
179+
const objects = [{ ...doc, listViews: { ...doc.listViews, derived_map: { type: 'grid', label: DERIVED_LABEL } } }];
180+
const objectAnswer = [doc];
181+
meta.value = {
182+
apps: [],
183+
objects,
184+
dashboards: [],
185+
reports: [],
186+
pages: [],
187+
loading: false,
188+
error: null,
189+
refresh: async () => {},
190+
invalidate: () => {},
191+
ensureType: async () => [],
192+
getItem: async () => null,
193+
getItemsByType: (type: string) => (type === 'object' ? objectAnswer : []),
194+
getTypeStatus: () => 'ready',
195+
};
196+
return objects;
197+
}
198+
199+
function renderAt(pathname: string, language: 'en' | 'zh-CN', objects: any[]) {
200+
route.pathname = pathname;
201+
return render(
202+
<I18nProvider config={{ defaultLanguage: language, detectBrowserLanguage: false, resources: BUNDLE }} persistLanguage={false}>
203+
<MetadataCtx.Provider value={meta.value}>
204+
<AppHeader variant="app" appName="showcase_app" activeAppName="showcase_app" objects={objects} />
205+
</MetadataCtx.Provider>
206+
</I18nProvider>,
207+
);
208+
}
209+
210+
const LANGUAGES = ['en', 'zh-CN'] as const;
211+
212+
describe('AppHeader — a view labelled with an inline locale map is titled in the viewer\'s language (#25901)', () => {
213+
it.each(LANGUAGES)('%s: a served view', (language) => {
214+
renderAt(`/apps/showcase_app/${OBJECT_NAME}/view/served_map`, language, world());
215+
216+
expect(screen.getAllByText(SERVED_LABEL[language]).length).toBeGreaterThan(0);
217+
});
218+
219+
it.each(LANGUAGES)('%s: a view no server read served', (language) => {
220+
renderAt(`/apps/showcase_app/${OBJECT_NAME}/view/derived_map`, language, world());
221+
222+
expect(screen.getAllByText(DERIVED_LABEL[language]).length).toBeGreaterThan(0);
223+
});
224+
225+
it('a map that resolves to no text is titled by the object\'s plural label', () => {
226+
renderAt(`/apps/showcase_app/${OBJECT_NAME}/view/empty_map`, 'en', world());
227+
228+
expect(screen.getAllByText(PLURAL).length).toBeGreaterThan(0);
229+
});
230+
});
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #25901 — an interface list page whose `label` / `description` is an inline
5+
* locale map draws them in the viewer's language.
6+
*
7+
* `@objectstack/spec` types both as `I18nLabel`. The page read
8+
* `typeof page.label === 'string' ? page.label : page.name` for its heading and
9+
* its record drawer's title, and drew `page.description` only when it was a
10+
* string: a map label showed the page's machine name, a map description was
11+
* dropped. Both now go through `metadataText`, the helper the header and the
12+
* report page resolve the same values with; the machine name is the heading
13+
* only when no label resolves.
14+
*
15+
* Harness: `InterfaceListPage.packageScope-12980`'s — the real
16+
* `MetadataProvider` over a client double, in an app with no package — under a
17+
* real `I18nProvider` set to the viewer's language.
18+
*
19+
* Directions, written before the run: the map cells RED before the change (the
20+
* machine name, no description), GREEN after; the string control GREEN on
21+
* both sides.
22+
*/
23+
24+
import '@testing-library/jest-dom/vitest';
25+
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
26+
import React from 'react';
27+
import { cleanup, render, screen, waitFor } from '@testing-library/react';
28+
import { MemoryRouter, Routes, Route } from 'react-router-dom';
29+
import { AdapterCtx, useMetadata } from '@object-ui/react';
30+
import { I18nProvider } from '@object-ui/i18n';
31+
32+
import { MetadataProvider } from '../../providers/MetadataProvider';
33+
import { InterfaceListPage } from '../InterfaceListPage';
34+
import { readPageObjectScope } from '../../console/appObjectScope';
35+
36+
const OBJECTS = [{ name: 'crm_account', label: 'Accounts', fields: { name: { type: 'text', label: 'Name' } } }];
37+
const APPS = [{ name: 'crm', label: 'CRM' }];
38+
const MAP_PAGE = {
39+
name: 'accounts_page',
40+
label: { en: 'Key accounts', 'zh-CN': '重点客户' },
41+
description: { en: 'Accounts we review weekly', 'zh-CN': '每周复盘的客户' },
42+
type: 'app',
43+
interfaceConfig: { source: 'crm_account' },
44+
};
45+
const STRING_PAGE = { ...MAP_PAGE, label: 'Key accounts', description: 'Accounts we review weekly' };
46+
47+
function adapter(page: unknown) {
48+
return {
49+
clearCache: vi.fn(),
50+
getObjectSchema(this: { getClient(): any }, name: string) {
51+
return this.getClient()
52+
.meta.getItem('object', name)
53+
.then((res: any) => (res && typeof res === 'object' && 'item' in res ? res.item : res));
54+
},
55+
getClient: () => ({
56+
meta: {
57+
getItems: (type: string) => {
58+
const items = type === 'object' ? OBJECTS : type === 'app' ? APPS : type === 'page' ? [page] : [];
59+
return Promise.resolve({ type, items: structuredClone(items) });
60+
},
61+
getItem: (type: string, name: string) => {
62+
const item = (type === 'object' ? OBJECTS : []).find((o) => o.name === name);
63+
return item ? Promise.resolve({ type, name, item: structuredClone(item) }) : Promise.reject(new Error('404'));
64+
},
65+
},
66+
}),
67+
} as unknown as Parameters<typeof MetadataProvider>[0]['adapter'];
68+
}
69+
70+
function PageRoute({ page }: { page: any }) {
71+
const metadata = useMetadata();
72+
const app = (metadata.apps as any[]).find((a) => a?.name === 'crm');
73+
if (!app) return null;
74+
const { ready } = readPageObjectScope(metadata.readObjectScope!, app, page);
75+
if (!ready) return <div data-testid="route-pending" />;
76+
return <InterfaceListPage page={page as never} />;
77+
}
78+
79+
async function boot(page: any, language: 'en' | 'zh-CN') {
80+
const ds = { find: vi.fn(async () => ({ data: [], total: 0 })), getObjectSchema: vi.fn(async () => OBJECTS[0]) };
81+
render(
82+
<I18nProvider config={{ defaultLanguage: language, detectBrowserLanguage: false, resources: { en: {}, 'zh-CN': {} } }} persistLanguage={false}>
83+
<MetadataProvider adapter={adapter(page)}>
84+
<AdapterCtx.Provider value={ds as never}>
85+
<MemoryRouter initialEntries={[`/apps/crm/page/${page.name}`]}>
86+
<Routes>
87+
<Route path="/apps/:appName/page/:pageName" element={<PageRoute page={page} />} />
88+
</Routes>
89+
</MemoryRouter>
90+
</AdapterCtx.Provider>
91+
</MetadataProvider>
92+
</I18nProvider>,
93+
);
94+
await waitFor(() => expect(screen.getByTestId('interface-list-page')).toBeInTheDocument());
95+
}
96+
97+
beforeEach(() => {
98+
sessionStorage.clear();
99+
localStorage.clear();
100+
});
101+
afterEach(cleanup);
102+
103+
describe('InterfaceListPage — inline locale-map label and description (#25901)', () => {
104+
it.each([
105+
['en', 'Key accounts', 'Accounts we review weekly'],
106+
['zh-CN', '重点客户', '每周复盘的客户'],
107+
] as const)('%s: the heading and description are the map\'s text, never the machine name', async (language, label, description) => {
108+
await boot(MAP_PAGE, language);
109+
110+
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent(label);
111+
expect(screen.getByText(description)).toBeInTheDocument();
112+
expect(screen.queryByText(MAP_PAGE.name)).not.toBeInTheDocument();
113+
});
114+
115+
it('a map that resolves to no text falls back to the machine name', async () => {
116+
await boot({ ...MAP_PAGE, label: {}, description: {} }, 'en');
117+
118+
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent(MAP_PAGE.name);
119+
});
120+
121+
it('control — a string label and description are drawn as given', async () => {
122+
await boot(STRING_PAGE, 'zh-CN');
123+
124+
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Key accounts');
125+
expect(screen.getByText('Accounts we review weekly')).toBeInTheDocument();
126+
});
127+
});

0 commit comments

Comments
 (0)