Skip to content

Commit 31237fc

Browse files
committed
test(record-page): pin the top bar on each face, the enlarged toolbar and the Activity count
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgVP3twvBvDTwoLPU6J
1 parent 6037a9c commit 31237fc

9 files changed

Lines changed: 702 additions & 26 deletions

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
* for an event that carries no `code`, by the character it typed
2424
* (objectstack#27241), and does nothing while a text field has focus;
2525
* `⌘⇧.` (the timeline column's) is no longer the page's;
26-
* - ⊟ is ONE icon, named by its label, at the end of the record header's
27-
* action row (objectstack#27241) — not on the crumb row, which keeps only
28-
* the ways back and has no child without one;
26+
* - ⊟ is ONE icon, named by its label, in the record's top bar
27+
* (objectstack#27524, Target 7: after the step group, before ⤢ / ⤡) — not
28+
* in the header's action row, which keeps the business actions, and the
29+
* crumb row is gone; a record drawn with no top bar of its own (a host's
30+
* plain overlay) keeps it at the end of that row (objectstack#27241);
2931
* - it is drawn only where the tier has a right column: both two-column
3032
* tiers, the embedded record at those widths too, never the one column;
3133
* - the chord is the topmost record view's: a drawer wide enough for its
@@ -218,16 +220,19 @@ describe('RecordDetailView — the right-column switch ⊟ (objectstack#27052, o
218220
it('one ⊟ icon at the end of the header\'s action row, on; off draws the details alone; on restores', async () => {
219221
const { container } = renderPage();
220222
const group = await screen.findByRole('group', { name: 'Panels' }, { timeout: 5000 });
221-
// objectstack#27241 — the end of the header's action row, after ⋯ and a
222-
// hairline; the crumb row keeps only the ways back (none on a direct open).
223-
expect(group.closest('[data-record-crumb-row]')).toBeNull();
224-
const toolbar = group.closest('[role="toolbar"]')!;
225-
expect(toolbar).not.toBeNull();
226-
expect(toolbar.closest('[data-record-column]')).toBeNull();
227-
const trailing = group.closest('[data-page-header-trailing]')!;
228-
expect(trailing.querySelector('[role="separator"][aria-orientation="vertical"]')).not.toBeNull();
229-
expect(toolbar.lastElementChild).toBe(trailing);
230-
expect(container.querySelector('[data-record-crumb-row]')?.childElementCount ?? 0).toBe(0);
223+
// objectstack#27524, Target 7 — in the page's top bar, among its frame
224+
// controls: no list context on a direct open, so no step group before it.
225+
const bar = group.closest('[data-record-top-bar]')!;
226+
expect(bar).not.toBeNull();
227+
expect(group.closest('[data-record-top-bar-controls]')).not.toBeNull();
228+
expect(bar.querySelector('[data-record-top-bar-step]')).toBeNull();
229+
// Not in the header's action row any more, and the crumb row is gone.
230+
expect(group.closest('[role="toolbar"]')).toBeNull();
231+
expect(container.querySelector('[data-page-header-trailing]')).toBeNull();
232+
expect(container.querySelector('[data-record-crumb-row]')).toBeNull();
233+
// The bar sits above the record header.
234+
const header = container.querySelector('[role="toolbar"]')!;
235+
expect(bar.compareDocumentPosition(header) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
231236
// ONE switch, an icon named by its label: the segmented text control and
232237
// the timeline segment are gone.
233238
expect(group.querySelectorAll('button')).toHaveLength(1);
@@ -315,7 +320,7 @@ describe('RecordDetailView — the right-column switch ⊟ (objectstack#27052, o
315320
const { container } = renderPage({ width: 900 });
316321
const group = await screen.findByRole('group', { name: 'Panels' }, { timeout: 5000 });
317322
expect(container.querySelector('[data-record-page-tier]')?.getAttribute('data-record-page-tier')).toBe('two-column');
318-
expect(group.closest('[role="toolbar"]')).not.toBeNull();
323+
expect(group.closest('[data-record-top-bar]')).not.toBeNull();
319324
expect(shown(container)).toBe('details right');
320325
fireEvent.click(rightColumnSwitch());
321326
await waitFor(() => expect(shown(container)).toBe('details'));
Lines changed: 284 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
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, Target 7 — the record's top bar on each face, from a real
11+
* `RecordDetailView` mount (the `panelToggles-27052` harness).
12+
*
13+
* - the page opened directly: the breadcrumb 「对象 › 记录名」 (the object goes
14+
* to the object's list), ⊟ where the tier has a right column, nothing else
15+
* — no counter, no ↓ ↑, no ⤡; the crumb row is gone;
16+
* - the page the list row's ↗ opened: the counter (its tooltip naming the
17+
* list's view), ↓ ↑ and `j` / `k` over the list's rows — a step replaces the
18+
* page with the sibling's — ⤡ 「Collapse to drawer」 back to the list with
19+
* the record stepped to open, and the object crumb back to the list;
20+
* - the page under a `?from=` trail: ← and the path, each ancestor a link;
21+
* - the record in a pane: the pane's bar names it at the root, and its ⊟ sits
22+
* in that bar, not in the header's action row.
23+
*/
24+
25+
import * as React from 'react';
26+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
27+
import { render, screen, cleanup, fireEvent, waitFor } from '@testing-library/react';
28+
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
29+
import { MetadataCtx } from '@object-ui/react';
30+
import { RelatedCountStore } from '@object-ui/components';
31+
32+
vi.mock('@object-ui/auth', async (importOriginal) => ({
33+
...(await importOriginal<Record<string, unknown>>()),
34+
useAuth: () => ({ user: { id: 'u1', name: 'Ada', image: null }, activeOrganization: null }),
35+
createAuthenticatedFetch: () => vi.fn(),
36+
}));
37+
38+
vi.mock('@object-ui/collaboration', async (importOriginal) => ({
39+
...(await importOriginal<Record<string, unknown>>()),
40+
useRecordPresence: () => [],
41+
PresenceAvatars: () => null,
42+
}));
43+
44+
vi.mock('sonner', () => ({
45+
toast: Object.assign(vi.fn(), {
46+
success: vi.fn(),
47+
error: vi.fn(),
48+
info: vi.fn(),
49+
warning: vi.fn(),
50+
loading: vi.fn(),
51+
dismiss: vi.fn(),
52+
}),
53+
}));
54+
55+
vi.mock('./ActionConfirmDialog', () => ({ ActionConfirmDialog: () => null }));
56+
vi.mock('./ActionParamDialog', () => ({ ActionParamDialog: () => null }));
57+
vi.mock('./ActionResultDialog', () => ({ ActionResultDialog: () => null }));
58+
vi.mock('./FlowRunner', () => ({ FlowRunner: () => null }));
59+
vi.mock('./MetadataInspector', () => ({
60+
MetadataPanel: () => null,
61+
useMetadataInspector: () => ({ showDebug: false, toggle: () => {} }),
62+
}));
63+
64+
import { RecordDetailView } from './RecordDetailView';
65+
import { RecordStackDrawer, recordDrawerReturnState, useRecordDrawerStack } from './recordDrawerStack';
66+
67+
const APP = 'demo';
68+
const LEAD = 'crm_lead';
69+
const BASE_FIELDS = { id: { type: 'text', label: 'Id' }, name: { type: 'text', label: 'Name' } };
70+
const OBJECTS = [
71+
{ name: LEAD, label: 'Lead', pluralLabel: 'Leads', fields: BASE_FIELDS },
72+
{ name: 'crm_task', label: 'Task', pluralLabel: 'Tasks', fields: { ...BASE_FIELDS, lead: { type: 'lookup', reference: LEAD, label: 'Lead' } } },
73+
];
74+
const ROWS = ['r-1', 'r-2', 'r-3'];
75+
76+
let rootWidth = 1440;
77+
78+
function makeDataSource() {
79+
return {
80+
find: vi.fn(async () => ({ data: [], total: 0 })),
81+
create: vi.fn(async (_o: string, row: unknown) => row),
82+
findOne: vi.fn(async (_o: string, recordId: string) => ({ id: recordId, name: `Record ${recordId}` })),
83+
update: vi.fn(async () => ({})),
84+
delete: vi.fn(async () => ({})),
85+
};
86+
}
87+
88+
const metadata = {
89+
objects: OBJECTS,
90+
pages: [],
91+
loading: false,
92+
error: null,
93+
refresh: async () => {},
94+
invalidate: () => {},
95+
ensureType: async () => [],
96+
getItem: async () => null,
97+
getItemsByType: () => [],
98+
} as never;
99+
100+
function Where() {
101+
const location = useLocation();
102+
return (
103+
<>
104+
<output data-testid="where">{`${location.pathname}${location.search}`}</output>
105+
<output data-testid="where-state">{JSON.stringify(location.state ?? null)}</output>
106+
</>
107+
);
108+
}
109+
110+
function mountPage(entry: string | { pathname: string; search?: string; state?: unknown }) {
111+
const dataSource = makeDataSource();
112+
render(
113+
<MemoryRouter initialEntries={[entry as never]}>
114+
<MetadataCtx.Provider value={metadata}>
115+
<Routes>
116+
<Route
117+
path="/apps/:appName/:objectName/record/:recordId"
118+
element={<RecordDetailView dataSource={dataSource as never} objects={OBJECTS} onEdit={() => {}} />}
119+
/>
120+
<Route path="/apps/:appName/:objectName" element={<div data-testid="list" />} />
121+
</Routes>
122+
<Where />
123+
</MetadataCtx.Provider>
124+
</MemoryRouter>,
125+
);
126+
return dataSource;
127+
}
128+
129+
const where = () => screen.getByTestId('where').textContent;
130+
const pageBar = () => document.querySelector('[data-record-page-root] > [data-record-top-bar]') as HTMLElement | null;
131+
132+
beforeEach(() => {
133+
cleanup();
134+
rootWidth = 1440;
135+
window.localStorage.clear();
136+
RelatedCountStore._reset();
137+
vi.stubGlobal(
138+
'fetch',
139+
vi.fn(async () => new Response(JSON.stringify({ data: [] }), { status: 200, headers: { 'content-type': 'application/json' } })),
140+
);
141+
const measure = HTMLElement.prototype.getBoundingClientRect;
142+
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (this: HTMLElement) {
143+
if (!this.hasAttribute('data-record-page-root')) return measure.call(this);
144+
const width = rootWidth;
145+
return { x: 0, y: 0, top: 0, left: 0, right: width, bottom: 800, width, height: 800, toJSON: () => ({}) } as DOMRect;
146+
});
147+
});
148+
149+
afterEach(() => {
150+
vi.unstubAllGlobals();
151+
vi.restoreAllMocks();
152+
});
153+
154+
describe('the page\'s top bar (objectstack#27524, Target 7)', () => {
155+
it('opened directly: 「对象 › 记录名」 and ⊟, nothing else; the crumb row is gone', async () => {
156+
mountPage(`/apps/${APP}/${LEAD}/record/r-1`);
157+
await screen.findByRole('group', { name: 'Panels' }, { timeout: 5000 });
158+
const bar = pageBar()!;
159+
expect(bar).not.toBeNull();
160+
await waitFor(() => expect(screen.getByTestId('record-page-crumb').textContent).toBe('LeadsRecord r-1'));
161+
const object = bar.querySelector('[data-record-crumb-object]') as HTMLAnchorElement;
162+
expect(object.getAttribute('href')).toBe(`/apps/${APP}/${LEAD}`);
163+
expect(bar.querySelector('[data-record-top-bar-step]')).toBeNull();
164+
expect(bar.querySelector('[data-record-top-bar-position]')).toBeNull();
165+
expect(screen.queryByTestId('record-drawer-return')).toBeNull();
166+
expect(bar.querySelector('[role="group"][aria-label="Panels"]')).not.toBeNull();
167+
expect(document.querySelector('[data-record-crumb-row]')).toBeNull();
168+
});
169+
170+
it('opened from the list row\'s ↗: the counter, ↓ ↑ and j / k over the list\'s rows, ⤡ and the object crumb back to the list', async () => {
171+
const back = recordDrawerReturnState(
172+
{ pathname: `/apps/${APP}/${LEAD}`, search: '?recordId=r-2', state: null },
173+
[{ objectName: LEAD, recordId: 'r-2', siblings: ROWS }],
174+
);
175+
mountPage({
176+
pathname: `/apps/${APP}/${LEAD}/record/r-2`,
177+
state: { ...back, from: { pathname: `/apps/${APP}/${LEAD}`, label: 'All leads' } },
178+
});
179+
await screen.findByRole('group', { name: 'Panels' }, { timeout: 5000 });
180+
const position = () => pageBar()!.querySelector('[data-record-top-bar-position]');
181+
expect(position()?.textContent).toBe('2 / 3');
182+
expect(position()?.getAttribute('title')).toBe('2 of 3 in All leads');
183+
// ⊟ after the step group, ⤡ at the end.
184+
const controls = Array.from(pageBar()!.querySelector('[data-record-top-bar-controls]')!.children);
185+
expect(controls.at(-1)?.getAttribute('data-testid')).toBe('record-drawer-return');
186+
187+
fireEvent.click(screen.getByRole('button', { name: 'Next record' }));
188+
await waitFor(() => expect(where()).toBe(`/apps/${APP}/${LEAD}/record/r-3`));
189+
await waitFor(() => expect(position()?.textContent).toBe('3 / 3'));
190+
expect((screen.getByRole('button', { name: 'Next record' }) as HTMLButtonElement).disabled).toBe(true);
191+
// `k` steps back; the arrow keys are the page's scroll, not the bar's.
192+
fireEvent.keyDown(document.body, { key: 'ArrowUp' });
193+
expect(where()).toBe(`/apps/${APP}/${LEAD}/record/r-3`);
194+
fireEvent.keyDown(document.body, { key: 'k' });
195+
await waitFor(() => expect(where()).toBe(`/apps/${APP}/${LEAD}/record/r-2`));
196+
197+
// ⤡ returns to the list with the record stepped to open in its pane.
198+
fireEvent.click(screen.getByTestId('record-drawer-return'));
199+
await waitFor(() => expect(where()).toBe(`/apps/${APP}/${LEAD}?recordId=r-2`));
200+
expect(screen.getByTestId('where-state').textContent).toContain('"recordDrawerRestore":[{"objectName":"crm_lead","recordId":"r-2"');
201+
});
202+
203+
it('the object crumb of a ↗ page returns to the list with no record open', async () => {
204+
const back = recordDrawerReturnState(
205+
{ pathname: `/apps/${APP}/${LEAD}`, search: '?view=all&recordId=r-1', state: null },
206+
[{ objectName: LEAD, recordId: 'r-1', siblings: ROWS }],
207+
);
208+
mountPage({ pathname: `/apps/${APP}/${LEAD}/record/r-1`, state: { ...back, from: { pathname: `/apps/${APP}/${LEAD}?view=all`, label: 'All leads' } } });
209+
const object = await waitFor(() => {
210+
const el = pageBar()?.querySelector('[data-record-crumb-object]');
211+
expect(el).toBeTruthy();
212+
return el as HTMLElement;
213+
});
214+
expect(object.textContent).toBe('Leads');
215+
fireEvent.click(object);
216+
await waitFor(() => expect(where()).toBe(`/apps/${APP}/${LEAD}?view=all`));
217+
});
218+
219+
it('under a ?from= trail: ← and the path, each ancestor a link to its page', async () => {
220+
const trail = encodeURIComponent(JSON.stringify([{ o: LEAD, i: 'L-1', t: 'Mira Costa' }]));
221+
mountPage(`/apps/${APP}/crm_task/record/t-1?from=${trail}`);
222+
const path = await screen.findByTestId('record-page-trail', undefined, { timeout: 5000 });
223+
expect(path.textContent).toBe('Lead Mira CostaTask');
224+
const ancestor = path.querySelector('a')!;
225+
expect(ancestor.getAttribute('href')).toBe(`/apps/${APP}/${LEAD}/record/L-1`);
226+
const backLink = pageBar()!.querySelector('[data-record-crumb-back]')!;
227+
expect(backLink.getAttribute('aria-label')).toBe('Go back');
228+
expect(screen.queryByTestId('record-page-crumb')).toBeNull();
229+
});
230+
});
231+
232+
/** The list host's pane, drawing the record embedded (`objectViewRecordOverlay.tsx`'s shape). */
233+
function PaneHost({ dataSource }: { dataSource: unknown }) {
234+
const [recordId, setRecordId] = React.useState('r-1');
235+
const root = React.useMemo(() => ({ objectName: LEAD, recordId, siblings: ROWS }), [recordId]);
236+
const stack = useRecordDrawerStack({ root, onRootStep: setRecordId });
237+
return (
238+
<RecordStackDrawer
239+
stack={stack}
240+
open
241+
mode="split"
242+
mainContent={<div data-testid="list" />}
243+
objects={OBJECTS}
244+
stepScope="All leads"
245+
onClose={() => {}}
246+
renderRecord={(level) => (
247+
<RecordDetailView
248+
dataSource={dataSource as never}
249+
objects={OBJECTS}
250+
onEdit={() => {}}
251+
objectNameOverride={level.objectName}
252+
recordIdOverride={level.recordId}
253+
embedded
254+
/>
255+
)}
256+
/>
257+
);
258+
}
259+
260+
describe('the pane\'s top bar holds the record\'s ⊟ and names it (objectstack#27524)', () => {
261+
it('the record reports its title to the breadcrumb, and its ⊟ sits in the pane\'s bar, not the header', async () => {
262+
const dataSource = makeDataSource();
263+
render(
264+
<MemoryRouter initialEntries={[`/apps/${APP}/${LEAD}?recordId=r-1`]}>
265+
<MetadataCtx.Provider value={metadata}>
266+
<PaneHost dataSource={dataSource} />
267+
</MetadataCtx.Provider>
268+
</MemoryRouter>,
269+
);
270+
await waitFor(() => expect(screen.getByTestId('record-drawer-crumb').textContent).toBe('LeadsRecord r-1'), { timeout: 5000 });
271+
const group = await screen.findByRole('group', { name: 'Panels' }, { timeout: 5000 });
272+
expect(group.closest('[data-record-pane-toggles]')).not.toBeNull();
273+
expect(group.closest('[data-record-top-bar]')).not.toBeNull();
274+
expect(group.closest('[data-record-page-root]')).toBeNull();
275+
expect(document.querySelector('[data-page-header-trailing]')).toBeNull();
276+
// The pane draws its own bar; the record inside draws none.
277+
expect(document.querySelectorAll('[data-record-top-bar]')).toHaveLength(1);
278+
expect(document.querySelector('[data-record-top-bar-position]')?.getAttribute('title')).toBe('1 of 3 in All leads');
279+
280+
// A step names the next record once it reports its title.
281+
fireEvent.click(screen.getByRole('button', { name: 'Next record' }));
282+
await waitFor(() => expect(screen.getByTestId('record-drawer-crumb').textContent).toBe('LeadsRecord r-2'), { timeout: 5000 });
283+
});
284+
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4254,8 +4254,8 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
42544254
{originFrom?.pathname && (
42554255
<Link
42564256
to={originFrom.pathname}
4257-
aria-label={t('detail.goBack', { defaultValue: 'Back' })}
4258-
title={t('detail.goBack', { defaultValue: 'Back' })}
4257+
aria-label={t('detail.goBack', { defaultValue: 'Go back' })}
4258+
title={t('detail.goBack', { defaultValue: 'Go back' })}
42594259
className="inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring"
42604260
data-record-crumb-back=""
42614261
>

‎ui/packages/app-shell/src/views/__tests__/recordDrawerStack-26679.test.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ describe('a related row opens in the same drawer, one level down (ruling 5)', ()
168168
it('pushes the task, shows ← and the path, and ← returns to the lead', () => {
169169
mountList();
170170
expect(body()).toBe('crm_lead/L-1');
171-
expect(screen.getByTestId('record-drawer-leading').textContent).toBe('');
171+
// objectstack#27524, Target 7 — at the root the bar's left end is the
172+
// breadcrumb 「对象 › 记录名」, not ← and a path.
173+
expect(screen.getByTestId('record-drawer-crumb').textContent).toBe('Lead#L-1');
174+
expect(trail()).toBeNull();
172175

173176
fireEvent.click(button('open task row'));
174177
expect(body()).toBe('crm_task/T-1');
@@ -345,8 +348,9 @@ describe('on the record page, a related row opens a drawer over the page (target
345348
fireEvent.click(screen.getAllByRole('button', { name: 'open task row' })[0]);
346349
expect(dialogBody()).toBe('crm_task/T-1');
347350
expect(where()).toBe(`/apps/${APP}/crm_lead/record/L-1`);
348-
// The drawer's root is the task: nothing on the left, ↑ ↓ over the rows.
349-
expect(screen.getByTestId('record-drawer-leading').textContent).toBe('');
351+
// The drawer's root is the task: its breadcrumb on the left
352+
// (objectstack#27524), ↑ ↓ over the rows.
353+
expect(screen.getByTestId('record-drawer-crumb').textContent).toBe('Task#T-1');
350354
fireEvent.click(button('Next record'));
351355
expect(dialogBody()).toBe('crm_task/T-2');
352356
fireEvent.click(screen.getByTitle('Close'));

0 commit comments

Comments
 (0)