Skip to content

Commit 33b1330

Browse files
committed
test(app-shell): pin a served object's list title in the object page and the app header
Claude-Session: https://claude.ai/code/session_01Utp6CZywtebM5fE7KZuMEM Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9cd4254 commit 33b1330

3 files changed

Lines changed: 123 additions & 12 deletions

File tree

‎ui/packages/app-shell/src/layout/__tests__/AppHeader.servedLabels-11295.test.tsx‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,49 @@ describe('AppHeader — a served report or page is named as served (objectstack#
406406
expect(screen.getAllByText('Q3 Results').length).toBeGreaterThan(0);
407407
});
408408
});
409+
410+
/**
411+
* objectstack#30311 — a served object is named as served in the header's
412+
* title on its list route.
413+
*
414+
* A `.custom` override renamed the object, and the `/meta/object` read serves
415+
* the new name by the server's label order for an overridden item. The title
416+
* passed the served definition through the bundle's `objectPluralLabel`, whose
417+
* packaged translation of the old name won.
418+
*
419+
* Directions, written before the run: the renamed cells RED before the change
420+
* (the packaged string), GREEN after; the controls GREEN on both sides.
421+
*/
422+
describe('AppHeader — a served object is named as served (objectstack#30311)', () => {
423+
const RENAMED_OBJECT = 'Work items (renamed-30311)';
424+
const PACKAGED_OBJECT = { en: 'Task', 'zh-CN': '任务' } as const;
425+
426+
function served(object: { label?: string; pluralLabel?: string }) {
427+
const objects = world(EDITED_VIEW, EDITED_DASHBOARD).map((o) => {
428+
const { label: _label, ...rest } = o;
429+
return { ...rest, ...object };
430+
});
431+
meta.value = { ...meta.value, objects };
432+
return objects;
433+
}
434+
435+
it.each(LANGUAGES)('%s: the title draws the renamed object as served, not the packaged string', (language) => {
436+
renderAt('/apps/showcase_app/showcase_task', language, served({ label: RENAMED_OBJECT }));
437+
438+
expect(screen.getAllByText(RENAMED_OBJECT).length).toBeGreaterThan(0);
439+
expect(screen.queryAllByText(PACKAGED_OBJECT[language])).toHaveLength(0);
440+
});
441+
442+
it('zh-CN: the served plural is read first', () => {
443+
renderAt('/apps/showcase_app/showcase_task', 'zh-CN', served({ label: RENAMED_OBJECT, pluralLabel: 'All work (renamed-30311)' }));
444+
445+
expect(screen.getAllByText('All work (renamed-30311)').length).toBeGreaterThan(0);
446+
expect(screen.queryAllByText('任务')).toHaveLength(0);
447+
});
448+
449+
it('zh-CN: control — an object served with no label is named by the bundle', () => {
450+
renderAt('/apps/showcase_app/showcase_task', 'zh-CN', served({}));
451+
452+
expect(screen.getAllByText('任务').length).toBeGreaterThan(0);
453+
});
454+
});

‎ui/packages/app-shell/src/views/ObjectDataPage.listTitlePlural-11696.test.tsx‎

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,21 @@ const FIELDS = {
8181
name: { type: 'text', label: 'Name' },
8282
};
8383

84-
const OBJECTS = [
85-
{ name: 'showcase_project', label: 'Project', pluralLabel: 'Projects', fields: FIELDS },
86-
{ name: 'showcase_note', label: 'Note', fields: FIELDS },
87-
];
84+
/**
85+
* The served objects, per language: the server translates what it serves under
86+
* the request's language from the same catalog the console loads, so a zh-CN
87+
* session holds the zh-CN answer (objectstack#30311).
88+
*/
89+
const OBJECTS: Record<Lang, Array<Record<string, unknown>>> = {
90+
en: [
91+
{ name: 'showcase_project', label: 'Project', pluralLabel: 'Projects', fields: FIELDS },
92+
{ name: 'showcase_note', label: 'Note', fields: FIELDS },
93+
],
94+
'zh-CN': [
95+
{ name: 'showcase_project', label: '项目', pluralLabel: '项目清单', fields: FIELDS },
96+
{ name: 'showcase_note', label: 'Note', fields: FIELDS },
97+
],
98+
};
8899

89100
/** The catalog as the console loads it: `zh-CN` translates both scalars. */
90101
const BUNDLE: Record<Lang, Record<string, unknown>> = {
@@ -111,7 +122,7 @@ afterEach(() => {
111122
});
112123

113124
/** The `/data` page's title text for `objectName`, in `lang` (the badge excluded). */
114-
async function dataPageTitle(lang: Lang, objectName: string): Promise<string> {
125+
async function dataPageTitle(lang: Lang, objectName: string, objects = OBJECTS[lang]): Promise<string> {
115126
const i18n = createI18n({ defaultLanguage: lang, detectBrowserLanguage: false });
116127
// The instance really booted in the language under test.
117128
expect(i18n.language).toBe(lang);
@@ -130,7 +141,7 @@ async function dataPageTitle(lang: Lang, objectName: string): Promise<string> {
130141
<Routes>
131142
<Route
132143
path="/apps/:appName/:objectName/data"
133-
element={<ObjectDataPage dataSource={dataSource} objects={OBJECTS} />}
144+
element={<ObjectDataPage dataSource={dataSource} objects={objects as never} />}
134145
/>
135146
</Routes>
136147
</MemoryRouter>
@@ -156,3 +167,22 @@ describe('ObjectDataPage — the /data page is titled with the plural (objectui#
156167
expect(await dataPageTitle('en', 'showcase_note')).toBe('Note');
157168
});
158169
});
170+
171+
/**
172+
* objectstack#30311 — a served object's /data page is titled as served.
173+
* Directions, written before the run: the renamed cell RED before the change
174+
* (`项目清单`), GREEN after; the control GREEN on both sides.
175+
*/
176+
describe('ObjectDataPage — a served object’s /data page is titled as served (objectstack#30311)', () => {
177+
const renamed = (extra: Record<string, unknown>) => [{ name: 'showcase_project', fields: FIELDS, ...extra }];
178+
179+
it('zh-CN: a renamed object titles the page with the served plural, not the packaged string', async () => {
180+
const title = await dataPageTitle('zh-CN', 'showcase_project', renamed({ label: 'Venture (renamed-30311)', pluralLabel: 'Ventures (renamed-30311)' }));
181+
expect(title).toContain('Ventures (renamed-30311)');
182+
expect(title).not.toContain('项目清单');
183+
});
184+
185+
it('zh-CN: control — an object served with no label is titled by the bundle', async () => {
186+
expect(await dataPageTitle('zh-CN', 'showcase_project', renamed({}))).toContain('项目清单');
187+
});
188+
});

‎ui/packages/app-shell/src/views/ObjectView.listTitlePlural-11696.test.tsx‎

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,21 @@ const FIELDS = {
103103
/** One authored list view with no `label`, as a list whose view the author left unnamed. */
104104
const LISTVIEWS = { all: { type: 'grid', columns: ['name'] } };
105105

106-
const OBJECTS = [
107-
{ name: 'showcase_project', label: 'Project', pluralLabel: 'Projects', fields: FIELDS, listViews: LISTVIEWS },
108-
{ name: 'showcase_note', label: 'Note', fields: FIELDS, listViews: LISTVIEWS },
109-
];
106+
/**
107+
* The served objects, per language: the server translates what it serves under
108+
* the request's language from the same catalog the console loads, so a zh-CN
109+
* session holds the zh-CN answer (objectstack#30311).
110+
*/
111+
const OBJECTS: Record<Lang, Array<Record<string, unknown>>> = {
112+
en: [
113+
{ name: 'showcase_project', label: 'Project', pluralLabel: 'Projects', fields: FIELDS, listViews: LISTVIEWS },
114+
{ name: 'showcase_note', label: 'Note', fields: FIELDS, listViews: LISTVIEWS },
115+
],
116+
'zh-CN': [
117+
{ name: 'showcase_project', label: '项目', pluralLabel: '项目清单', fields: FIELDS, listViews: LISTVIEWS },
118+
{ name: 'showcase_note', label: 'Note', fields: FIELDS, listViews: LISTVIEWS },
119+
],
120+
};
110121

111122
/** The catalog as the console loads it: `zh-CN` translates both scalars. */
112123
const BUNDLE: Record<Lang, Record<string, unknown>> = {
@@ -132,7 +143,7 @@ afterEach(() => {
132143
});
133144

134145
/** The list page's title text for `objectName`, in `lang`. */
135-
async function listTitle(lang: Lang, objectName: string): Promise<string> {
146+
async function listTitle(lang: Lang, objectName: string, objects = OBJECTS[lang]): Promise<string> {
136147
const i18n = createI18n({ defaultLanguage: lang, detectBrowserLanguage: false });
137148
// The instance really booted in the language under test.
138149
expect(i18n.language).toBe(lang);
@@ -151,7 +162,7 @@ async function listTitle(lang: Lang, objectName: string): Promise<string> {
151162
<Routes>
152163
<Route
153164
path="/apps/:appName/:objectName"
154-
element={<ObjectView dataSource={dataSource} objects={OBJECTS} onEdit={() => {}} />}
165+
element={<ObjectView dataSource={dataSource} objects={objects as never} onEdit={() => {}} />}
155166
/>
156167
</Routes>
157168
</MemoryRouter>
@@ -178,3 +189,27 @@ describe('ObjectView — the list page is titled with the plural (objectui#11696
178189
expect(await listTitle('en', 'showcase_note')).toBe('Note');
179190
});
180191
});
192+
193+
/**
194+
* objectstack#30311 — a served object's list is titled as served.
195+
*
196+
* A `.custom` override renamed the object, and the `/meta/object` read serves
197+
* the new name by the server's label order for an overridden item; the title
198+
* passed it through the bundle's `objectPluralLabel`, whose packaged
199+
* translation of the old name won. Directions, written before the run: the
200+
* renamed cell RED before the change (`项目清单`), GREEN after; the control
201+
* GREEN on both sides.
202+
*/
203+
describe('ObjectView — a served object’s list is titled as served (objectstack#30311)', () => {
204+
const renamed = (extra: Record<string, unknown>) =>
205+
[{ name: 'showcase_project', fields: FIELDS, listViews: LISTVIEWS, ...extra }];
206+
207+
it('zh-CN: a renamed object titles its list with the served plural, not the packaged string', async () => {
208+
const title = await listTitle('zh-CN', 'showcase_project', renamed({ label: 'Venture (renamed-30311)', pluralLabel: 'Ventures (renamed-30311)' }));
209+
expect(title).toBe('Ventures (renamed-30311)');
210+
});
211+
212+
it('zh-CN: control — an object served with no label is titled by the bundle', async () => {
213+
expect(await listTitle('zh-CN', 'showcase_project', renamed({}))).toBe('项目清单');
214+
});
215+
});

0 commit comments

Comments
 (0)