Skip to content

Commit 7a0555e

Browse files
committed
test(app-shell): the record tab row on every tier, and the address it drives
The tier pins read the page's one tablist as its tab row; a new pin walks the row through the browser's history: one pushed entry, tab to tab replaces it, and 概览, Esc or Back return in one step. The retired full related face's header pin leaves with the face. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibzGCEznLfiQm2T5icF
1 parent c1734bc commit 7a0555e

3 files changed

Lines changed: 295 additions & 32 deletions

File tree

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

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
* three columns.
2222
* - ≥ 760 px: details | the right column at 320 px, the details grid at two.
2323
* - < 760 px (the split pane at 720, a phone at 390): ONE column, the details
24-
* then the right column's panels in their order. No tab strip, no rail.
24+
* then the right column's panels in their order. No rail, and no tab
25+
* strip but the record's own tab row under the header (Target 8), the
26+
* same on every tier: 「概览」, 动态, then the related panels.
2527
* - The embedded record (drawer / split pane) follows the same rule.
2628
* - The right column opens with the 动态 panel, so History is read at open in
27-
* every tier. `?tab=` addresses no strip; `?related=timeline` is the 动态
28-
* tab, the full stream.
29+
* every tier. `?tab=` addresses no strip (「概览」 stays the active tab);
30+
* `?related=timeline` is the 动态 tab, the full stream.
2931
*/
3032

3133
import * as React from 'react';
@@ -218,6 +220,24 @@ const rightPanels = (container: HTMLElement) =>
218220
(el) => (el.hasAttribute('data-record-timeline-panel') ? 'timeline' : el.getAttribute('data-related-card-id')),
219221
);
220222

223+
/**
224+
* The page's only tablist is its tab row (objectstack#27524, Target 8): the
225+
* same tabs on every tier, the active one as `active`.
226+
*/
227+
const expectTabRowOnly = (active = 'overview') => {
228+
const lists = screen.getAllByRole('tablist');
229+
expect(lists).toHaveLength(1);
230+
expect(lists[0].closest('[data-record-tab-row]')).not.toBeNull();
231+
const tabs = Array.from(lists[0].querySelectorAll('[role="tab"]'));
232+
expect(tabs.map((tab) => tab.getAttribute('data-record-tab'))).toEqual([
233+
'overview',
234+
'timeline',
235+
'showcase_task.project',
236+
'showcase_note.project',
237+
]);
238+
expect(lists[0].querySelector('[aria-selected="true"]')?.getAttribute('data-record-tab')).toBe(active);
239+
};
240+
221241
describe('RecordDetailView — one record page, laid out by its width (objectstack#26678, objectstack#27524)', () => {
222242
it('1440 px: details beside the right column at 380 px, the details grid at three columns; 动态 leads; History is read at open', async () => {
223243
const { container } = renderPage({ width: 1440 });
@@ -226,7 +246,7 @@ describe('RecordDetailView — one record page, laid out by its width (objectsta
226246
expect(shown(container)).toBe('details right');
227247
expect(columnsGrid(container)).toContain('23.75rem');
228248
expect(detailsGrid(container)).toContain('@lg:grid-cols-3');
229-
expect(screen.queryByRole('tablist')).toBeNull();
249+
expectTabRowOnly();
230250
expect(rightPanels(container)).toEqual(['timeline', 'showcase_task.project', 'showcase_note.project']);
231251
// No resident timeline column and no rail: the two columns are all.
232252
expect(column(container, 'timeline')).toBeNull();
@@ -253,19 +273,19 @@ describe('RecordDetailView — one record page, laid out by its width (objectsta
253273
// The same panels as the wide tier — no rail to open first.
254274
expect(rightPanels(container)).toEqual(['timeline', 'showcase_task.project', 'showcase_note.project']);
255275
expect(screen.queryByTestId('record-related-rail-toggle')).toBeNull();
256-
expect(screen.queryByRole('tablist')).toBeNull();
276+
expectTabRowOnly();
257277
});
258278

259279
it.each([
260280
['the split pane', 720],
261281
['a phone', 390],
262-
])('%s (%i px): one column — the details, then the 动态 panel and the related panels; no tabs; History is read at open', async (_name, width) => {
282+
])('%s (%i px): one column — the details, then the 动态 panel and the related panels; the tab row; History is read at open', async (_name, width) => {
263283
const { container } = renderPage({ width });
264284
await screen.findAllByText('Tasks', undefined, { timeout: 5000 });
265285
expect(tierOf(container)).toBe('stack');
266286
expect(shown(container)).toBe('details');
267287
expect(columnsGrid(container)).toContain('grid-cols-1');
268-
expect(screen.queryByRole('tablist')).toBeNull();
288+
expectTabRowOnly();
269289
// The panels follow the details, in the right column's order.
270290
const details = column(container, 'details')!;
271291
const right = column(container, 'right')!;
@@ -284,14 +304,14 @@ describe('RecordDetailView — one record page, laid out by its width (objectsta
284304
const { container } = renderPage({ width: 720, embedded: true });
285305
await screen.findAllByText('Tasks', undefined, { timeout: 5000 });
286306
expect(tierOf(container)).toBe('stack');
287-
expect(screen.queryByRole('tablist')).toBeNull();
307+
expectTabRowOnly();
288308
});
289309

290310
it('`?tab=` addresses no strip on a laid-out page; `?related=timeline` is the 动态 tab: the full stream with its chips', async () => {
291311
const tabbed = renderPage({ width: 720, search: '?tab=related' });
292312
await screen.findAllByText('Tasks', undefined, { timeout: 5000 });
293313
expect(tierOf(tabbed.container)).toBe('stack');
294-
expect(screen.queryByRole('tablist')).toBeNull();
314+
expectTabRowOnly();
295315
expect(column(tabbed.container, 'details')).not.toBeNull();
296316
tabbed.unmount();
297317

@@ -307,6 +327,7 @@ describe('RecordDetailView — one record page, laid out by its width (objectsta
307327
expect(face.getAttribute('aria-label')).toBe('Activity');
308328
expect(face.querySelector('[data-stream-filters]')).not.toBeNull();
309329
expect(face.querySelector('[data-record-timeline-peek]')).toBeNull();
330+
expectTabRowOnly('timeline');
310331
// The face takes the page: no columns under it.
311332
expect(container.querySelector('[data-record-columns]')).toBeNull();
312333
await waitFor(() => expect(auditReads()).toBeGreaterThan(0));
Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
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#27524, Targets 8 and 9 — the record's tab row drives the
11+
* address, through a real `RecordDetailView` mount and the browser's own
12+
* history:
13+
*
14+
* - leaving 「概览」 for a tab PUSHES one entry, `?related=object.field`
15+
* (`?related=timeline` for 动态);
16+
* - moving from tab to tab REPLACES that entry, so the history grows by one
17+
* however many tabs the reader visits;
18+
* - 「概览」, Esc and the browser's Back each return to the page in one step,
19+
* and the header with its tab row stays drawn on every face.
20+
*/
21+
22+
import * as React from 'react';
23+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
24+
import { render, screen, cleanup, waitFor, fireEvent, act } from '@testing-library/react';
25+
import { BrowserRouter } from 'react-router-dom';
26+
import { MetadataCtx } from '@object-ui/react';
27+
import { RelatedCountStore } from '@object-ui/components';
28+
29+
vi.mock('@object-ui/auth', async (importOriginal) => ({
30+
...(await importOriginal<Record<string, unknown>>()),
31+
useAuth: () => ({ user: { id: 'u1', name: 'Ada', image: null }, activeOrganization: null }),
32+
createAuthenticatedFetch: () => vi.fn(),
33+
}));
34+
35+
vi.mock('@object-ui/collaboration', async (importOriginal) => ({
36+
...(await importOriginal<Record<string, unknown>>()),
37+
useRecordPresence: () => [],
38+
PresenceAvatars: () => null,
39+
}));
40+
41+
vi.mock('sonner', () => ({
42+
toast: Object.assign(vi.fn(), {
43+
success: vi.fn(),
44+
error: vi.fn(),
45+
info: vi.fn(),
46+
warning: vi.fn(),
47+
loading: vi.fn(),
48+
dismiss: vi.fn(),
49+
}),
50+
}));
51+
52+
// Orthogonal chrome — stubbed so the only asynchrony here is the page's own.
53+
vi.mock('./ActionConfirmDialog', () => ({ ActionConfirmDialog: () => null }));
54+
vi.mock('./ActionParamDialog', () => ({ ActionParamDialog: () => null }));
55+
vi.mock('./ActionResultDialog', () => ({ ActionResultDialog: () => null }));
56+
vi.mock('./FlowRunner', () => ({ FlowRunner: () => null }));
57+
vi.mock('./MetadataInspector', () => ({
58+
MetadataPanel: () => null,
59+
useMetadataInspector: () => ({ showDebug: false, toggle: () => {} }),
60+
}));
61+
62+
import { RecordDetailView } from './RecordDetailView';
63+
64+
const PARENT = 'showcase_project';
65+
const RECORD_ID = 'p-1';
66+
67+
const BASE_FIELDS = {
68+
id: { type: 'text', label: 'Id' },
69+
name: { type: 'text', label: 'Name' },
70+
};
71+
72+
/**
73+
* The project's own text fields, each with a value: more than the header's
74+
* highlights take, so the details section holds enough of them (more than
75+
* five) for the wide tier's three-column grid.
76+
*/
77+
const PROJECT_TEXT = ['code', 'region', 'sponsor', 'phase', 'cost_center', 'tier', 'site', 'channel', 'segment', 'program', 'quarter', 'team'];
78+
79+
const OBJECTS = [
80+
{
81+
name: PARENT,
82+
label: 'Project',
83+
pluralLabel: 'Projects',
84+
managedBy: 'platform',
85+
// History is on for this object, so the synthesized page carries it.
86+
enable: { trackHistory: true },
87+
// A worked object — its status options declare lifecycle kinds. Since
88+
// objectstack#27524 that no longer changes the page: every object's page
89+
// has the same two columns.
90+
fields: {
91+
...BASE_FIELDS,
92+
...Object.fromEntries(PROJECT_TEXT.map((name) => [name, { type: 'text', label: name }])),
93+
status: {
94+
type: 'select',
95+
label: 'Status',
96+
options: [
97+
{ value: 'active', label: 'Active', kind: 'open' },
98+
{ value: 'done', label: 'Done', kind: 'won' },
99+
],
100+
},
101+
},
102+
},
103+
{
104+
name: 'showcase_task',
105+
label: 'Task',
106+
pluralLabel: 'Tasks',
107+
managedBy: 'platform',
108+
fields: { ...BASE_FIELDS, project: { type: 'master_detail', reference: PARENT, label: 'Project' } },
109+
},
110+
{
111+
name: 'showcase_note',
112+
label: 'Note',
113+
pluralLabel: 'Notes',
114+
managedBy: 'platform',
115+
fields: { ...BASE_FIELDS, project: { type: 'lookup', reference: PARENT, label: 'Project' } },
116+
},
117+
{ name: 'sys_audit_log', label: 'Audit log', managedBy: 'platform', fields: BASE_FIELDS },
118+
];
119+
120+
/** The width this view's root measures; every other element measures as the environment does. */
121+
let rootWidth = 0;
122+
let dataSource: { find: ReturnType<typeof vi.fn> } & Record<string, unknown>;
123+
124+
function makeDataSource() {
125+
return {
126+
find: vi.fn(async () => ({ data: [], total: 0 })),
127+
create: vi.fn(async (_o: string, row: unknown) => row),
128+
findOne: vi.fn(async (_o: string, recordId: string) => ({
129+
id: recordId,
130+
name: `Project ${recordId}`,
131+
...Object.fromEntries(PROJECT_TEXT.map((name) => [name, `${name} value`])),
132+
status: 'active',
133+
})),
134+
update: vi.fn(async () => ({})),
135+
delete: vi.fn(async () => ({})),
136+
};
137+
}
138+
139+
function renderPage({ width, embedded = false, search = '' }: { width: number; embedded?: boolean; search?: string }) {
140+
rootWidth = width;
141+
// The real browser history: the view reads the address bar it writes.
142+
window.history.replaceState(null, '', `/app/demo/${PARENT}/${RECORD_ID}${search}`);
143+
dataSource = makeDataSource();
144+
const metadata = {
145+
objects: OBJECTS,
146+
pages: [],
147+
loading: false,
148+
error: null,
149+
refresh: async () => {},
150+
invalidate: () => {},
151+
ensureType: async () => [],
152+
getItem: async () => null,
153+
getItemsByType: () => [],
154+
} as never;
155+
return render(
156+
<BrowserRouter>
157+
<MetadataCtx.Provider value={metadata}>
158+
<RecordDetailView
159+
dataSource={dataSource as never}
160+
objects={OBJECTS}
161+
onEdit={() => {}}
162+
objectNameOverride={PARENT}
163+
recordIdOverride={RECORD_ID}
164+
embedded={embedded}
165+
/>
166+
</MetadataCtx.Provider>
167+
</BrowserRouter>,
168+
);
169+
}
170+
171+
const tierOf = (container: HTMLElement) =>
172+
container.querySelector('[data-record-page-tier]')?.getAttribute('data-record-page-tier') ?? null;
173+
const column = (container: HTMLElement, name: string) =>
174+
container.querySelector(`[data-record-column="${name}"]`) as HTMLElement | null;
175+
const auditReads = () => dataSource.find.mock.calls.filter((call) => call[0] === 'sys_audit_log').length;
176+
177+
beforeEach(() => {
178+
cleanup();
179+
RelatedCountStore._reset();
180+
vi.stubGlobal(
181+
'fetch',
182+
vi.fn(async () =>
183+
new Response(JSON.stringify({ data: [] }), {
184+
status: 200,
185+
headers: { 'content-type': 'application/json' },
186+
}),
187+
),
188+
);
189+
const measure = HTMLElement.prototype.getBoundingClientRect;
190+
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (this: HTMLElement) {
191+
if (!this.hasAttribute('data-record-page-root')) return measure.call(this);
192+
return { x: 0, y: 0, top: 0, left: 0, right: rootWidth, bottom: 800, width: rootWidth, height: 800, toJSON: () => ({}) } as DOMRect;
193+
});
194+
});
195+
196+
afterEach(() => {
197+
vi.unstubAllGlobals();
198+
vi.restoreAllMocks();
199+
});
200+
201+
const search = () => new URLSearchParams(window.location.search).get('related');
202+
const tab = (id: string) => document.querySelector(`[role="tab"][data-record-tab="${id}"]`) as HTMLElement;
203+
const activeTab = () => document.querySelector('[role="tab"][aria-selected="true"]')?.getAttribute('data-record-tab') ?? null;
204+
const face = () => document.querySelector('[data-related-enlarged]');
205+
206+
describe('RecordDetailView — the tab row drives the address (objectstack#27524, Targets 8 and 9)', () => {
207+
it('a tab pushes one entry, the next tab replaces it, 「概览」 returns in one step', async () => {
208+
renderPage({ width: 1440 });
209+
await screen.findAllByText('Tasks', undefined, { timeout: 5000 });
210+
const start = window.history.length;
211+
expect(activeTab()).toBe('overview');
212+
213+
fireEvent.click(tab('showcase_task.project'));
214+
await waitFor(() => expect(face()?.getAttribute('data-related-enlarged')).toBe('showcase_task.project'));
215+
expect(search()).toBe('showcase_task.project');
216+
expect(window.history.length).toBe(start + 1);
217+
expect(activeTab()).toBe('showcase_task.project');
218+
// The header is drawn once, above the row, on the enlarged face too.
219+
expect(document.querySelectorAll('h1')).toHaveLength(1);
220+
221+
fireEvent.click(tab('timeline'));
222+
await waitFor(() => expect(face()?.getAttribute('data-related-enlarged')).toBe('timeline'));
223+
expect(search()).toBe('timeline');
224+
fireEvent.click(tab('showcase_note.project'));
225+
await waitFor(() => expect(face()?.getAttribute('data-related-enlarged')).toBe('showcase_note.project'));
226+
expect(search()).toBe('showcase_note.project');
227+
// Three tabs visited, one entry.
228+
expect(window.history.length).toBe(start + 1);
229+
230+
fireEvent.click(tab('overview'));
231+
await waitFor(() => expect(face()).toBeNull());
232+
await waitFor(() => expect(search()).toBeNull());
233+
expect(activeTab()).toBe('overview');
234+
expect(document.querySelector('[data-record-columns]')).not.toBeNull();
235+
});
236+
237+
it('Esc on a tab returns to 「概览」, and so does the browser\'s Back', async () => {
238+
renderPage({ width: 720 });
239+
await screen.findAllByText('Tasks', undefined, { timeout: 5000 });
240+
fireEvent.click(tab('showcase_task.project'));
241+
fireEvent.click(await waitFor(() => tab('showcase_note.project')));
242+
await waitFor(() => expect(search()).toBe('showcase_note.project'));
243+
fireEvent.keyDown(face()!, { key: 'Escape' });
244+
await waitFor(() => expect(search()).toBeNull());
245+
await waitFor(() => expect(face()).toBeNull());
246+
247+
fireEvent.click(tab('timeline'));
248+
await waitFor(() => expect(search()).toBe('timeline'));
249+
act(() => window.history.back());
250+
await waitFor(() => expect(search()).toBeNull());
251+
await waitFor(() => expect(face()).toBeNull());
252+
expect(activeTab()).toBe('overview');
253+
});
254+
255+
it('a link to a tab opens it as the active tab; 「概览」 then replaces the address, with nothing to pop', async () => {
256+
renderPage({ width: 1440, search: '?related=showcase_task.project' });
257+
await waitFor(() => expect(face()?.getAttribute('data-related-enlarged')).toBe('showcase_task.project'), { timeout: 5000 });
258+
expect(activeTab()).toBe('showcase_task.project');
259+
const start = window.history.length;
260+
fireEvent.click(tab('overview'));
261+
await waitFor(() => expect(search()).toBeNull());
262+
expect(window.history.length).toBe(start);
263+
expect(window.location.pathname).toBe(`/app/demo/${PARENT}/${RECORD_ID}`);
264+
});
265+
});

‎ui/packages/plugin-detail/src/__tests__/RelatedPanel.header-27524.test.tsx‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -178,29 +178,6 @@ describe('the related panel header (objectstack#27524, Target 1)', () => {
178178
});
179179
});
180180

181-
describe('the arranged full face (the Related tab) has no collapse either (objectstack#27524)', () => {
182-
it('draws ⠿ and ⋯, no chevron, and a click on its header leaves the rows drawn', async () => {
183-
render(
184-
<RelatedCardChromeContext.Provider value={chromeOf()}>
185-
<RelatedList
186-
title="Tasks"
187-
type="table"
188-
api="task"
189-
objectName="task"
190-
data={rows}
191-
dataSource={{ find: vi.fn(async () => rows), getObjectSchema: vi.fn(async () => ({ name: 'task', fields })) } as any}
192-
/>
193-
</RelatedCardChromeContext.Provider>,
194-
);
195-
await waitFor(() => expect(screen.getByText('Call Ada')).toBeInTheDocument());
196-
expect(document.querySelector('[data-related-panel-handle]')).not.toBeNull();
197-
expect(document.querySelector('[data-related-card-menu]')).not.toBeNull();
198-
expect(document.querySelector('.lucide-chevron-down, .lucide-chevron-right')).toBeNull();
199-
fireEvent.click(screen.getByText('Tasks'));
200-
expect(screen.getByText('Call Ada')).toBeInTheDocument();
201-
});
202-
});
203-
204181
describe('the compact row’s first column (objectstack#27524, Target 11)', () => {
205182
// A product's line items: the child's name field IS the key back to the product.
206183
const lineFields = {

0 commit comments

Comments
 (0)