Skip to content

Commit 90f2b1c

Browse files
fix(console): one neutral sentence for an object you cannot open on every object route, and a translated filter empty state (#34950)
🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WGufzgwLiKcfujYUug7sPs Fixes #34740 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:控制台四条对象路由(列表、data、记录、新建)在对象打不开时统一显示同一句中性文案「对象"X"不存在,或者您无权访问它。」,11 种语言一致;列表筛选器空选项不再写死英文「No options」,改读语言包(中文「暂无可选项」)。 - 为什么改:服务端对无读权限的对象和不存在的名字回答完全一样(裁决 6787890900),但控制台原句断言「不存在」,而且分散在两个 key 上;中文界面里还漏着英文筛选空态。 - 风险与回滚:只改文案与 key 指向,退役 `empty.objectNotFoundDescription`(无其他调用方);`packageDisabled` 分支与列表提示不变。回滚即 revert 本 PR。 - 先看:`ui/packages/app-shell/src/views/RecordFormPage.tsx`(新建页改 key 并加 testid)、`ui/packages/i18n/src/locales/en.ts`(改写一句、删一句)、`ui/packages/plugin-list/src/UserFilters.tsx`(空态走 `tt()`)。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/app-shell/src/views/objectRouteAbsence-34740.test.tsx packages/plugin-list/src/__tests__/UserFilters.emptyOptionsLocale-34740.test.tsx`,预期全部通过(8 + 5 个用例)。 - 需要你做的:无,席位落地。 ## What changes **One key for all four object routes (ruling A of the claim amendment).** I pointed the record and create faces at the single key, and did not reword both keys: - `RecordDetailView` and `RecordFormPage` now draw `console.objectView.objectNotFoundDescription` (param `objectName`). That is the key the list face (`ObjectNotFoundState`) and the data face (`ObjectDataPage`) already drew. - The key is reworded, in all 11 packs, to a sentence that neither asserts nor reveals existence. en: `The object "NAME" does not exist, or you do not have access to it.` zh-Hans: `对象"NAME"不存在,或者您无权访问它。` zh-Hant is regenerated by `gen:zh-hant`. - `empty.objectNotFoundDescription` is retired from all 11 packs. It has no other caller. - The en eager pack changes by -136 raw bytes (one line deleted, one value +4 chars). - The `packageDisabled` arm, the list hint and both title keys are unchanged. - `ObjectDataPage` and `RecordFormPage` gain `data-testid="object-not-found"` on that face, the testid the other two faces already carry. **Filter empty state.** The popover for a chip whose field has no options now reads `tt('fields.options.empty', 'No options available')`. This is an existing eager key that all 11 locales carry (zh-Hans 暂无可选项). Its meaning is "this field has no options", which `lookup.noOptions` does not match: that key is the search-miss wording. The empty state gains `data-testid="filter-options-empty-FIELD"`. ## Tests - New `ui/packages/app-shell/src/views/objectRouteAbsence-34740.test.tsx` covers the list, data and create routes in en and zh-CN. Each case renders a withheld object (`crm_lead`, absent from a served list that holds a readable sibling) and a missing name, and checks that both read the pack sentence and are byte-identical once the name is removed. It also has a premise cell that pins the wording and checks the retired key is absent. - New block `RecordDetailView.objectRouteAbsence-34740` in `RecordDetailView.harness.test.tsx` covers the record route, en and zh-CN. - New `UserFilters.emptyOptionsLocale-34740.test.tsx` covers en, zh-CN, the no-provider fallback, and a control with options. - Updated tests: - `NotFoundState.test.tsx`: the new en sentence. - `user-filter-arity-spec-parity.test.tsx`: its two absence checks now use the new testid. The old text query would have passed vacuously. - `de-quote-pairing-3876.test.ts`: fixed keys 20 to 19, spans 22 to 21, paired spans and the count identity 119 to 118, each with a history line. - `residue-namespaces-3546.test.tsx`: dropped the three style pins on the retired key. Its sibling `empty.interfacePageSourceMissing` keeps the same pins. <details><summary>Ablations (each mutation proven on disk by scripts/ablation-replace.mjs, each restore proven by blob == HEAD and an empty git diff HEAD)</summary> - Record face put back on `empty.objectNotFoundDescription`: the harness block shows 2 failed. Both cells were RED. - Create face put back: `objectRouteAbsence-34740` shows 2 failed / 6 passed (both create cells RED). - en sentence put back to "does not exist in the current configuration": 1 failed / 7 passed. Only the premise cell went RED. The route cells read the sentence from the pack, so they follow it, and the test header now says so. - Filter literal put back (`{'No options'}`): 3 failed / 2 passed. The en, zh-CN and no-provider cells were RED; the control stayed green. The first attempt used the replacement text `No options`, which is a substring of the new fallback. The tool refused it (count 3 to 3) and that run was void. </details> <details><summary>Test and type-check readings, head b3b165f</summary> - `pnpm --dir ui exec vitest run packages/plugin-list/ packages/i18n/`: Test Files 277 passed, Tests 3767 passed / 13 skipped. - app-shell, narrowed (declared): 25 files that render the four faces or name the keys or testid, 271 tests passed. I stopped the full-package run at 43 minutes on the shared box. CI's Test UI runs it in full. - `pnpm --dir ui exec vitest run scripts/`: 171 files passed / 2 skipped, 5077 tests passed. - type-check exit 0 with 0 TS errors for `@object-ui/app-shell`, `@object-ui/plugin-list` and `@object-ui/i18n`. </details> ## Acceptance notes - The record and create faces now show one sentence. The old second sentence ("Check your configuration or navigate back…") is gone. Both faces keep their Back button. The list face keeps its own hint. - `de-quote-pairing-3876.test.ts` pins de-pack span counts (now 118). Open PRs that share the locale files merge cleanly with this one (overlap-check). A sibling that adds or removes a German quoted span moves that number, and whichever lands second rebases it. - Eager closure: the gzipped `i18n-locale-en` reading is NOT MEASURED locally, because it needs the Console build that Build & E2E UI runs. The raw en pack delta is -136 bytes. ## Verification Live readings on a CRM example rig: a private backend port, plus the Console Vite dev server from this branch's `ui/`. The user is a member with no read on any `crm_*` object. The metadata describe answers `404 RESOURCE_NOT_FOUND` for both `crm_lead` and `nonexistent_thing`. BEFORE means the base source restored into the tree; AFTER means this head. <details><summary>en</summary> | route | before | after | |---|---|---| | list (both names) | The object "NAME" does not exist in the current configuration. + hint | The object "NAME" does not exist, or you do not have access to it. + hint | | data (both names) | The object "NAME" does not exist in the current configuration. | The object "NAME" does not exist, or you do not have access to it. | | record (both names) | Object "NAME" definition missing. Check your configuration or navigate back to select a valid object. | The object "NAME" does not exist, or you do not have access to it. | | create (both names) | Object "NAME" definition missing. Check your configuration or navigate back to select a valid object. | The object "NAME" does not exist, or you do not have access to it. | | filter popover, field without options | No options | No options available | </details> <details><summary>zh-CN</summary> | route | before | after | |---|---|---| | list (both names) | 对象"NAME"在当前配置中不存在。 + 提示 | 对象"NAME"不存在,或者您无权访问它。 + 提示 | | data (both names) | 对象"NAME"在当前配置中不存在。 | 对象"NAME"不存在,或者您无权访问它。 | | record (both names) | 对象 “NAME” 的定义不存在。请检查配置或返回选择有效的对象。 | 对象"NAME"不存在,或者您无权访问它。 | | create (both names) | 对象 “NAME” 的定义不存在。请检查配置或返回选择有效的对象。 | 对象"NAME"不存在,或者您无权访问它。 | | filter popover, field without options | No options | 暂无可选项 | </details> <details><summary>Gates (local subset, final head b3b165f)</summary> - `dispatch-gates --commands`: 41 families derived and 41 run. 40 exited 0. `check:test-source-alias` first went red on the new test's dynamic `@objectstack/lint` reach; it is fixed by a collection-time import and now exits 0. - `--ran` reconciliation: 41 derived, 41 run, 0 NOT-MEASURED, 0 UNRUN. - `ui` i18n gates exited 0: `check:i18n-keys`, `check:i18n-drift`, `check:i18n-dead-keys`, `check:new-line-citations`. - overlap-check: VERDICT clean exit 0 against origin/main c6ecd1f and 6 open heads. </details> <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzgwLiKcfujYUug7sPs --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent fb5c42d commit 90f2b1c

23 files changed

Lines changed: 429 additions & 45 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/plugin-list': patch
4+
'@object-ui/i18n': patch
5+
'@object-ui/console': patch
6+
---
7+
8+
fix(console): every object route words an object you cannot open the same neutral way, and the list filter's empty state is translated
9+
10+
Clause-②: no
11+
Metadata-protocol: none
12+
13+
The server answers an object you cannot read exactly like a name that does not exist, so the console never tells them apart. But the sentence it drew still said the object does not exist. That sentence was spread over two keys: one for the list and data routes, and another, longer one for the record and create routes. All four routes now draw one key, `console.objectView.objectNotFoundDescription`, and it says what is true in both cases: "The object "NAME" does not exist, or you do not have access to it." It is translated in all eleven built-in languages (zh-Hans: 对象"NAME"不存在,或者您无权访问它。). `empty.objectNotFoundDescription` is retired from every pack. The list route's hint and the disabled-package sentence are unchanged.
14+
15+
A list's dropdown filter for a field with no options showed a hard-coded English "No options", even in a Chinese console. It now reads the pack's `fields.options.empty` ("No options available", 暂无可选项), the same key the form's options empty state uses.

‎ui/packages/app-shell/src/components/__tests__/NotFoundState.test.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ describe('the unknown-object state offers a way back to Home', () => {
5151
renderObjectNotFound();
5252
const state = screen.getByTestId('object-not-found');
5353
expect(state).toHaveTextContent('Object Not Found');
54-
expect(state).toHaveTextContent('The object "no_such_object" does not exist in the current configuration.');
54+
// objectstack-ai/objectstack#34740: neutral on existence — an object the
55+
// reader cannot read is answered exactly like a missing name.
56+
expect(state).toHaveTextContent('The object "no_such_object" does not exist, or you do not have access to it.');
5557

5658
fireEvent.click(screen.getByRole('button', { name: 'Back to home' }));
5759
expect(await screen.findByRole('heading', { name: 'Home page' })).toBeInTheDocument();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ export function ObjectDataPage({ dataSource, objects }: any) {
539539

540540
if (!objectDef) {
541541
return (
542-
<div className="h-full flex items-center justify-center p-8">
542+
<div className="h-full flex items-center justify-center p-8" data-testid="object-not-found">
543543
<Empty>
544544
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted">
545545
<Database className="h-6 w-6 text-muted-foreground" />

‎ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { MemoryRouter, Route, Routes, BrowserRouter } from 'react-router-dom';
5151
import { RelatedCountStore } from '@object-ui/components';
5252
import { ComponentRegistry } from '@object-ui/core';
5353
import { I18nProvider, LocalizationProvider, createI18n } from '@object-ui/i18n';
54+
import { builtInLocales } from '@object-ui/i18n/locales';
5455
import { PermissionProvider, MePermissionsProvider, type MePermissionsResponse, type MePermissionsAuthenticatedResponse } from '@object-ui/permissions';
5556
import { MetadataCtx } from '@object-ui/react';
5657
import { PageSchema as SpecPageSchema } from '@objectstack/spec/ui';
@@ -2723,3 +2724,90 @@ describe('RecordDetailView.recordPagePlacesNoComponent-32478', () => {
27232724
expect(screen.queryByTestId('record-page-places-no-component')).toBeNull();
27242725
});
27252726
});
2727+
2728+
// ── RecordDetailView.objectRouteAbsence-34740 ───────────────────────────────
2729+
2730+
/**
2731+
* objectstack-ai/objectstack#34740 — the record route answers an object the
2732+
* reader cannot open with the same neutral sentence as the list, data and create
2733+
* routes (`objectRouteAbsence-34740.test.tsx`): `console.objectView.objectNotFoundDescription`,
2734+
* which neither asserts nor reveals whether the object exists. The server leaves
2735+
* a withheld object out of the served list exactly as it leaves out a missing
2736+
* name (ruling 6787890900), so both reach this view as absence.
2737+
*/
2738+
describe('RecordDetailView.objectRouteAbsence-34740', () => {
2739+
restoreAfterBlock();
2740+
2741+
const READABLE = { name: 'crm_account', label: 'Account', fields: { name: { type: 'text', label: 'Name' } } };
2742+
const WITHHELD = 'crm_lead';
2743+
const MISSING = 'no_such_object';
2744+
type Lang = 'en' | 'zh-CN';
2745+
const PACK: Record<Lang, 'en' | 'zh-Hans'> = { en: 'en', 'zh-CN': 'zh-Hans' };
2746+
2747+
function sentence(lang: Lang, objectName: string): string {
2748+
const pack = builtInLocales[PACK[lang]] as { console: { objectView: { objectNotFoundDescription: string } } };
2749+
return pack.console.objectView.objectNotFoundDescription.replace('{{objectName}}', objectName);
2750+
}
2751+
2752+
const metadata = {
2753+
objects: [READABLE], pages: [], loading: false, error: null,
2754+
refresh: async () => {}, invalidate: () => {},
2755+
ensureType: async () => [], getItem: async () => null, getItemsByType: () => [],
2756+
} as never;
2757+
2758+
async function faceText(lang: Lang, objectName: string): Promise<string> {
2759+
const ds = {
2760+
find: vi.fn(async () => ({ data: [], total: 0, hasMore: false, pageSize: 50 })),
2761+
findOne: vi.fn(async () => null),
2762+
create: vi.fn(async () => ({})),
2763+
update: vi.fn(async () => ({})),
2764+
delete: vi.fn(async () => ({})),
2765+
getObjectSchema: async () => null,
2766+
};
2767+
const i18n = createI18n({ defaultLanguage: lang, detectBrowserLanguage: false });
2768+
expect(i18n.language).toBe(lang);
2769+
render(
2770+
<I18nProvider instance={i18n} persistLanguage={false}>
2771+
<MemoryRouter initialEntries={[`/apps/crm/${objectName}/record/r1`]}>
2772+
<MetadataCtx.Provider value={metadata}>
2773+
<NavigationProvider>
2774+
<Routes>
2775+
<Route
2776+
path="/apps/:appName/:objectName/record/:recordId"
2777+
element={<RecordDetailView dataSource={ds as never} objects={[READABLE] as never} onEdit={() => {}} />}
2778+
/>
2779+
</Routes>
2780+
</NavigationProvider>
2781+
</MetadataCtx.Provider>
2782+
</MemoryRouter>
2783+
</I18nProvider>,
2784+
);
2785+
const text = (await screen.findByTestId('object-not-found')).textContent ?? '';
2786+
cleanup();
2787+
return text;
2788+
}
2789+
2790+
beforeAll(() => {
2791+
Object.defineProperty(window, 'innerWidth', { configurable: true, value: 1280 });
2792+
});
2793+
2794+
beforeEach(() => {
2795+
vi.stubGlobal('fetch', vi.fn(async () => ({
2796+
ok: true, status: 200, json: async () => ({ data: [] }), text: async () => '{}',
2797+
})) as never);
2798+
});
2799+
2800+
afterEach(() => {
2801+
cleanup();
2802+
vi.unstubAllGlobals();
2803+
vi.restoreAllMocks();
2804+
});
2805+
2806+
it.each(['en', 'zh-CN'] as const)('%s: a withheld object and a missing name read the same sentence', async (lang) => {
2807+
const withheld = await faceText(lang, WITHHELD);
2808+
const missing = await faceText(lang, MISSING);
2809+
expect(withheld).toContain(sentence(lang, WITHHELD));
2810+
expect(missing).toContain(sentence(lang, MISSING));
2811+
expect(withheld.replaceAll(WITHHELD, 'NAME')).toBe(missing.replaceAll(MISSING, 'NAME'));
2812+
});
2813+
});

‎ui/packages/app-shell/src/views/RecordDetailView.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4472,7 +4472,7 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
44724472
testId="object-not-found"
44734473
icon={Database}
44744474
title={t('empty.objectNotFound')}
4475-
description={t('empty.objectNotFoundDescription', { name: objectName })}
4475+
description={t('console.objectView.objectNotFoundDescription', { objectName })}
44764476
actions={<BackToHomeButton testId="object-not-found-home" />}
44774477
/>
44784478
);

‎ui/packages/app-shell/src/views/RecordFormPage.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,14 @@ export function RecordFormPage({ mode }: RecordFormPageProps) {
364364

365365
if (!objectDef) {
366366
return (
367-
<div className="flex h-full items-center justify-center p-4">
367+
<div className="flex h-full items-center justify-center p-4" data-testid="object-not-found">
368368
<Empty>
369369
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted">
370370
<Database className="h-6 w-6 text-muted-foreground" />
371371
</div>
372372
<EmptyTitle>{t('empty.objectNotFound')}</EmptyTitle>
373373
<EmptyDescription>
374-
{t('empty.objectNotFoundDescription', { name: objectName })}
374+
{t('console.objectView.objectNotFoundDescription', { objectName })}
375375
</EmptyDescription>
376376
<div className="mt-4">
377377
<Button variant="outline" onClick={() => navigate(baseUrl)}>
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectstack-ai/objectstack#34740 — every object route answers an object the
11+
* reader cannot open with ONE sentence that neither asserts nor reveals whether
12+
* the object exists.
13+
*
14+
* The server leaves an object the caller cannot read out of every schema list
15+
* and answers a describe of it as an absent name (ruling 6787890900, amending
16+
* ADR-0106), so the console receives both cases as the same absence. Each
17+
* route's face draws `console.objectView.objectNotFoundDescription` ("does not
18+
* exist, or you do not have access to it"). The record route's face, the fourth,
19+
* is pinned in `RecordDetailView.harness.test.tsx` under the same issue number.
20+
*
21+
* Two names per route: `crm_lead`, an object the server withheld (absent from the
22+
* served list while a readable sibling is present), and `no_such_object`, a name
23+
* that exists nowhere. Both, in en and zh-CN, must read the same sentence with
24+
* only the name changed.
25+
*
26+
* The route cells read the sentence from the pack, so they pin which key each
27+
* face draws and that both names read alike; the premise cell pins the wording.
28+
* Measured: the create face put back on `empty.objectNotFoundDescription` reds
29+
* both create cells (that key is gone, so the raw key renders); the en sentence
30+
* put back to "does not exist in the current configuration" reds the premise
31+
* cell and leaves the route cells green.
32+
*/
33+
34+
import '@testing-library/jest-dom/vitest';
35+
import * as React from 'react';
36+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
37+
import { render, cleanup, screen } from '@testing-library/react';
38+
import { MemoryRouter, Routes, Route } from 'react-router-dom';
39+
import { createI18n, I18nProvider } from '@object-ui/i18n';
40+
import { builtInLocales } from '@object-ui/i18n/locales';
41+
42+
vi.mock('@object-ui/permissions', async (importOriginal) => {
43+
const actual = await importOriginal<typeof import('@object-ui/permissions')>();
44+
return {
45+
...actual,
46+
usePermissions: () => ({
47+
check: () => ({ allowed: true }),
48+
checkField: () => true,
49+
getFieldPermissions: () => [],
50+
getRowFilter: () => undefined,
51+
getObjectApiOperations: () => undefined,
52+
roles: [],
53+
isLoaded: false,
54+
hasCapabilities: () => true,
55+
can: () => true,
56+
cannot: () => false,
57+
}),
58+
useFieldPermissions: () => ({ canRead: () => true, canWrite: () => true, permissions: [] }),
59+
};
60+
});
61+
62+
vi.mock('@object-ui/auth', async (importOriginal) => ({
63+
...(await importOriginal<Record<string, unknown>>()),
64+
useAuth: () => ({ user: { id: 'u1', name: 'Ada' }, activeOrganization: null, getAuthConfig: async () => ({ features: {} }) }),
65+
useWorkspaceAdminStatus: () => ({ isAdmin: false, isResolved: true }),
66+
createAuthenticatedFetch: () => vi.fn(),
67+
}));
68+
69+
vi.mock('./RecordDetailView', () => ({ RecordDetailView: () => null }));
70+
vi.mock('./CreateViewDialog', () => ({ CreateViewDialog: () => null }));
71+
vi.mock('@object-ui/plugin-form', async (importOriginal) => ({
72+
...(await importOriginal<Record<string, unknown>>()),
73+
ObjectForm: () => <div data-testid="object-form" />,
74+
}));
75+
vi.mock('./metadata-admin/useMetadata', () => ({ useMetadataClient: () => ({}) }));
76+
77+
/** The served list: the readable sibling only. `crm_lead` was withheld by the server. */
78+
const READABLE = { name: 'crm_account', label: 'Account', fields: { name: { type: 'text', label: 'Name' } } };
79+
const SERVED = [READABLE];
80+
vi.mock('../providers/MetadataProvider', () => ({ useMetadata: () => ({ objects: SERVED, loading: false }) }));
81+
vi.mock('../providers/AdapterProvider', () => ({ useAdapter: () => null }));
82+
83+
// `ObjectView` reaches a dynamic `import('@objectstack/lint')`: pay its load at
84+
// collection, never inside a case's clocked window (`check:test-source-alias`).
85+
import '@objectstack/lint';
86+
import { ObjectView } from './ObjectView';
87+
import { ObjectDataPage } from './ObjectDataPage';
88+
import { RecordFormPage } from './RecordFormPage';
89+
import { ExpressionProvider } from '../providers/ExpressionProvider';
90+
91+
type Lang = 'en' | 'zh-CN';
92+
const PACK: Record<Lang, 'en' | 'zh-Hans'> = { en: 'en', 'zh-CN': 'zh-Hans' };
93+
const WITHHELD = 'crm_lead';
94+
const MISSING = 'no_such_object';
95+
96+
/** The one sentence, from the pack the reader's language loads. */
97+
function sentence(lang: Lang, objectName: string): string {
98+
const pack = builtInLocales[PACK[lang]] as { console: { objectView: { objectNotFoundDescription: string } } };
99+
return pack.console.objectView.objectNotFoundDescription.replace('{{objectName}}', objectName);
100+
}
101+
102+
const dataSource = {
103+
find: vi.fn(async () => ({ data: [], total: 0 })),
104+
findOne: vi.fn(async () => null),
105+
create: vi.fn(async () => ({})),
106+
update: vi.fn(async () => ({})),
107+
delete: vi.fn(async () => ({})),
108+
getObjectSchema: vi.fn(async () => null),
109+
} as never;
110+
111+
const ROUTES = {
112+
list: { path: '/apps/:appName/:objectName', url: (o: string) => `/apps/crm/${o}`,
113+
element: () => <ObjectView dataSource={dataSource} objects={SERVED} onEdit={() => {}} /> },
114+
data: { path: '/apps/:appName/:objectName/data', url: (o: string) => `/apps/crm/${o}/data`,
115+
element: () => <ObjectDataPage dataSource={dataSource} objects={SERVED} /> },
116+
create: { path: '/apps/:appName/:objectName/new', url: (o: string) => `/apps/crm/${o}/new`,
117+
element: () => <RecordFormPage mode="create" /> },
118+
} as const;
119+
120+
/** The absent-object face's text on `route` for `objectName`, in `lang`. */
121+
async function faceText(route: keyof typeof ROUTES, lang: Lang, objectName: string): Promise<string> {
122+
const i18n = createI18n({ defaultLanguage: lang, detectBrowserLanguage: false });
123+
expect(i18n.language).toBe(lang);
124+
const r = ROUTES[route];
125+
render(
126+
<I18nProvider instance={i18n} persistLanguage={false}>
127+
<ExpressionProvider user={{ id: 'u1', name: 'Ada', profile: 'member' }}>
128+
<MemoryRouter initialEntries={[r.url(objectName)]}>
129+
<Routes>
130+
<Route path={r.path} element={r.element()} />
131+
</Routes>
132+
</MemoryRouter>
133+
</ExpressionProvider>
134+
</I18nProvider>,
135+
);
136+
const face = await screen.findByTestId('object-not-found', {}, { timeout: 5000 });
137+
const text = face.textContent ?? '';
138+
cleanup();
139+
return text;
140+
}
141+
142+
beforeEach(() => {
143+
vi.stubGlobal('fetch', vi.fn(async () => new Response(JSON.stringify({ data: [] }), {
144+
status: 200, headers: { 'content-type': 'application/json' },
145+
})));
146+
});
147+
148+
afterEach(() => {
149+
cleanup();
150+
vi.unstubAllGlobals();
151+
vi.clearAllMocks();
152+
});
153+
154+
describe('objectRouteAbsence-34740 — one neutral sentence on the list, data and create routes', () => {
155+
it('the premise: the sentence names both readings, in both packs, and no other face key is left', () => {
156+
expect(sentence('en', 'x')).toBe('The object "x" does not exist, or you do not have access to it.');
157+
expect(sentence('zh-CN', 'x')).toBe('对象"x"不存在,或者您无权访问它。');
158+
for (const pack of ['en', 'zh-Hans'] as const) {
159+
expect((builtInLocales[pack] as { empty: Record<string, unknown> }).empty.objectNotFoundDescription).toBeUndefined();
160+
}
161+
});
162+
163+
for (const route of Object.keys(ROUTES) as Array<keyof typeof ROUTES>) {
164+
for (const lang of ['en', 'zh-CN'] as const) {
165+
it(`${route} · ${lang}: a withheld object and a missing name read the same sentence`, async () => {
166+
const withheld = await faceText(route, lang, WITHHELD);
167+
const missing = await faceText(route, lang, MISSING);
168+
expect(withheld).toContain(sentence(lang, WITHHELD));
169+
expect(missing).toContain(sentence(lang, MISSING));
170+
// Byte-identical once the name is taken out: nothing on the face tells the two apart.
171+
expect(withheld.replaceAll(WITHHELD, 'NAME')).toBe(missing.replaceAll(MISSING, 'NAME'));
172+
});
173+
}
174+
}
175+
176+
it('CONTROL: the readable sibling draws no absent-object face on the create route', async () => {
177+
const i18n = createI18n({ defaultLanguage: 'en', detectBrowserLanguage: false });
178+
render(
179+
<I18nProvider instance={i18n} persistLanguage={false}>
180+
<MemoryRouter initialEntries={[`/apps/crm/${READABLE.name}/new`]}>
181+
<Routes>
182+
<Route path={ROUTES.create.path} element={ROUTES.create.element()} />
183+
</Routes>
184+
</MemoryRouter>
185+
</I18nProvider>,
186+
);
187+
expect(await screen.findByTestId('object-form')).toBeInTheDocument();
188+
expect(screen.queryByTestId('object-not-found')).toBeNull();
189+
});
190+
});

0 commit comments

Comments
 (0)