Skip to content

Commit 878aebd

Browse files
fix(plugin-grid): a related tab's phone card follows the relationship's columns and drops the reference back to the page record (#38918)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwB7Un8hgmYaC4XFXQuvaosiq)_ Fixes #38895 Clause-②: yes (widening) — new optional member only: `ObjectGridComponentProps.cardFields` on `@object-ui/plugin-grid`; nothing removed or renamed Metadata-protocol: none ## 维护者速读 - 手机用户打开记录页的相关列表标签(例如产品页的商机明细)时,每张卡片改为显示该关系声明的列(所属商机、数量、金额),不再在每张卡片上重复当前页面的记录本身(以前显示成一串原始编号);电脑端表格不变。 - 替 HotCRM 解决产品页商机明细在手机上看不到商机的问题,这是 19.0.0-next.3 引入的显示回归。 - 出错时只影响手机上相关列表卡片显示哪几个字段,不碰数据;撤回本次改动即恢复原来的卡片。 - 无 ## What changes On a phone (and in the side preview's card face), a record page's related tab hands its rows to `object-grid`, which draws each row as the list card. Since the phone card started following the child object's `highlightFields`, that card body ignored the relationship's own `relatedListColumns`, and it drew the lookup back to the page's own record. The related list never expands that key (its `$expand` drops `referenceField` by design), so the card showed it as a raw id or an unresolved reference, and a product's deal lines never showed the deal. - `ui/packages/plugin-grid/src/ObjectGrid.tsx`: a new HOST prop, `cardFields` (a React prop on the grid's host channel, beside `cardFace`; never authored metadata, no spec or node key change). When a host passes it, the card body reads those fields, in order, in place of the object's `highlightFields`, with the same rules: the amount is the first that draws as money, the subtitle the next three, and number parts carry their field label. Absent, the card is exactly as before: `highlightFields`, else the shown columns. - `ui/packages/plugin-detail/src/RelatedList.tsx`: the enlarged tab passes `cardFields` = the columns it already draws (`effectiveColumns`) whenever the list is declared, that is when the relationship has `relatedListColumns` or the child declares `highlightFields`. Those columns already follow the ADR-0035 §3/§4 override chain (relationship `relatedListColumns`, else the child's `highlightFields` led by its name field) and already pass the FK, FLS and redaction gates, so the key back to the page is never among them. With neither declared, nothing is passed and the card keeps the grid's shown columns, which are this list's columns already. The value is memoised on a string key, not on the array's identity (ui commandment #10). - Lookups render their record name: every lookup the card can now draw is one the list expands (authored columns restrict `$expand` to themselves; derived columns expand every relation but the parent FK). The raw-id draw had no second cause: it was the unexpanded parent FK, which the card no longer draws. - Not changed: the desktop table, every non-related list's phone card (the `highlightFields` card from #37891 / PR #38214), the card title (the declared name field). - `.changeset/38895-phone-related-list-card-columns.md`: `patch` for `@object-ui/plugin-grid` and `@object-ui/plugin-detail`. Read first, by risk: 1. `RelatedList.tsx`, the `declaresCardList` / `cardFields` block above `enlargedGridHost`: decides when the card follows the list. 2. `ObjectGrid.tsx`, the `declaredCardFields` line in `buildMobileCardRenderer`: the one place the card body source changes. 3. `ui/packages/plugin-grid/src/__tests__/relatedTabPhoneCard-38895.test.tsx`. ## Tests New file `ui/packages/plugin-grid/src/__tests__/relatedTabPhoneCard-38895.test.tsx` (no shared harness file exists for `ObjectGrid` or `RelatedList`). It drives the real chain, `RelatedList` (enlarged) then `object-grid` then its card renderer, with HotCRM's opportunity line on a product page as the fixture (`highlightFields` leads with the product; the product relationship's `relatedListColumns` leads with the deal), against a data source that honours `$expand`: - declared `relatedListColumns`: each card's parts are exactly `deal name · Quantity n · Total $…`, the list expands the deal and never the product, and no card carries the product's id; - no `relatedListColumns`: the parts are the child's `highlightFields` minus the product (`Quantity 8 · Total $8,000.00`); - control: the same tab at 1440 px is the table of the relationship's columns, with no column for the product. <details><summary>Reproduction on the base tree (test committed before the fix, a8c74c9)</summary> ``` × with relatedListColumns declared ... AssertionError: expected 'Restricted record' to be 'Globex Line Expansion' × with no relatedListColumns ... expected [ 'Restricted record', …(2) ] to deeply equal [ 'Quantity 8', 'Total $8,000.00' ] Tests 2 failed | 1 passed (3) ``` The first part of every card is the product reference back to the page, unresolved. </details> <details><summary>Ablation, one leg per half, each via scripts/ablation-replace.mjs (mutation landed by anchor count and blob, restored to HEAD blob, git diff HEAD empty)</summary> - grid half: `hostCardFields ?? (objectSchema as any)?.highlightFields` back to `(objectSchema as any)?.highlightFields`: 2 failed / 1 passed; first card's parts read `[ 'TcoGX1WJ77TN-SKX', … ]`, the raw product id. - host half: the `cardFields` spread deleted from `enlargedGridHost`: 2 failed / 1 passed, same two readings. - fix in place: 3 passed (3). </details> <details><summary>Package suites at d65d66c</summary> - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/plugin-grid/`: Test Files 322 passed (322), Tests 2843 passed (2843). - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/plugin-detail/src/__tests__/RelatedList packages/plugin-detail/src/__tests__/RecordPageColumns packages/plugin-detail/src/__tests__/relatedTab`: Test Files 65 passed (65), Tests 505 passed (505). The rest of `plugin-detail` is left to Test UI (it does not fit one foreground window). - `pnpm --filter @object-ui/plugin-grid run type-check && pnpm --filter @object-ui/plugin-detail run type-check`: exit 0; `tsconfig.test.json` lists the new test file (`--listFilesOnly`, 1 hit). </details> ## Acceptance notes - The card title is still the child's declared name field. On HotCRM's product page that is `product_title`, the same product name on every card; the card asked only for the body, so the title is unchanged here. - With `relatedListColumns` declared, the amount is the first money column in the relationship's order (HotCRM's list puts `unit_price` before `total_price`, so the amount is the sales price and the total is a labelled subtitle part). This is the order the author declared, the same rule `highlightFields` follows. - Real-app reading at 390 px: NOT MEASURED, reason: a showcase or HotCRM boot plus a Console build did not fit this run; the test drives the same component chain the record page draws. ## Verification <details><summary>Targeted gates at d65d66c (dispatch-gates --commands, derived from this diff)</summary> 39 derived, 39 run, each exit 0, including `pnpm --dir ui exec vitest run scripts/` (172 passed, 2 skipped). `dispatch-gates --ran`: "39 derived famil(ies) accounted for — 39 run, 0 NOT-MEASURED (a DERIVED zero — all 39 recorded an exit code and none of them is 3)". `pnpm check:new-line-citations` (ui): "0 new citation(s)". Type-check lanes and the full farm are CI's. </details> Two-minute check: `pnpm --dir ui exec vitest run packages/plugin-grid/src/__tests__/relatedTabPhoneCard-38895.test.tsx` shows 3 passed; the first case reads the deal's name as each card's first subtitle part. --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzfcCk7a8bQdgyaxzu7)_ <!-- signed: repo:objectstack@os-support-ai · os-support-ai · session_01WGufzfcCk7a8bQdgyaxzu7 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ad83af4 commit 878aebd

4 files changed

Lines changed: 266 additions & 6 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/plugin-grid': patch
3+
'@object-ui/plugin-detail': patch
4+
---
5+
6+
fix(plugin-grid, plugin-detail): on a phone, a related tab's cards follow the relationship's columns and leave out the reference back to the page's record
7+
8+
Clause-②: yes (widening) — new optional member only: `ObjectGridComponentProps.cardFields` on `@object-ui/plugin-grid`; nothing removed or renamed
9+
Metadata-protocol: none
10+
11+
On a phone, a record page's related tab draws each row as a card. Since 19.0.0-next.3 the card body read the child object's `highlightFields`, so the relationship's own `relatedListColumns` were ignored. The card also drew the lookup back to the record the page is showing: the same value on every card, and one the list never expands, so it showed as a raw id or an unresolved reference. A product's opportunity lines, for example, showed the product on every card and never the deal.
12+
13+
The card body now reads the relationship's `relatedListColumns` when they are declared, and the child's `highlightFields` otherwise. This is the same order the tab's table follows. The reference back to the page's record is left out. A lookup on the card is one the list expands, so it shows the record's name. Other lists keep the `highlightFields` card, and the desktop table is unchanged. No metadata change is needed.

‎ui/packages/plugin-detail/src/RelatedList.tsx‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3986,6 +3986,24 @@ export const RelatedList: React.FC<RelatedListProps> = ({
39863986
},
39873987
[tabSummaries, patchTabConditions],
39883988
);
3989+
/**
3990+
* objectstack#38895 — the fields the enlarged grid's phone card reads
3991+
* (`cardFields`): the list this relationship declares, as this list draws
3992+
* it — its `relatedListColumns`, else the child's `highlightFields`
3993+
* (ADR-0035 §3/§4) — through the same gates as the columns, so never the
3994+
* key back to the page's own record. Without either declaration the card
3995+
* keeps the grid's shown columns, which are this list's columns already.
3996+
*/
3997+
const declaresCardList = (Array.isArray(columns) && columns.length > 0)
3998+
|| (Array.isArray((objectSchema as { highlightFields?: unknown } | undefined)?.highlightFields)
3999+
&& ((objectSchema as { highlightFields: unknown[] }).highlightFields.length > 0));
4000+
const cardFieldsKey = declaresCardList
4001+
? effectiveColumns.map((c: any) => c.accessorKey || columnIdentity(c)).filter(Boolean).join(',')
4002+
: '';
4003+
const cardFields = React.useMemo(
4004+
() => (cardFieldsKey === '' ? undefined : cardFieldsKey.split(',')),
4005+
[cardFieldsKey],
4006+
);
39894007
const enlargedGridHost = React.useMemo(() => {
39904008
if (!enlargedGrid) return undefined;
39914009
const heldBefore = currentPage * (effectivePageSize || 0);
@@ -3998,10 +4016,13 @@ export const RelatedList: React.FC<RelatedListProps> = ({
39984016
// tab's own query), and selection with the floating bar (bulk delete).
39994017
// One growing window, no pager: `data` is every row loaded so far and
40004018
// `rowCount` the match total, which the footer leads with.
4001-
const cardFace = previewFace ? { cardFace: true } : {};
4019+
const cardHost = {
4020+
...(previewFace ? { cardFace: true } : {}),
4021+
...(cardFields ? { cardFields } : {}),
4022+
};
40024023
if (tabList) {
40034024
return {
4004-
...cardFace,
4025+
...cardHost,
40054026
manualPagination: true,
40064027
rowCount: total ?? sortedData.length,
40074028
page: 1,
@@ -4023,7 +4044,7 @@ export const RelatedList: React.FC<RelatedListProps> = ({
40234044
};
40244045
}
40254046
return {
4026-
...cardFace,
4047+
...cardHost,
40274048
manualPagination: true,
40284049
rowCount,
40294050
page: currentPage + 1,
@@ -4036,7 +4057,7 @@ export const RelatedList: React.FC<RelatedListProps> = ({
40364057
...(onRowDelete ? { onDelete: handleDeleteRow } : {}),
40374058
...(writeTabColumnState ? { onColumnStateChange: writeTabColumnState } : {}),
40384059
};
4039-
}, [writeTabColumnState, enlargedGrid, windowed, total, currentPage, effectivePageSize, relatedData.length, hasMore, sortedData.length, paginatedData.length, activeSort, handleTableSort, objectSchema, onRowEdit, onRowDelete, handleDeleteRow, tabList, tabRecordCountLead, pickTabSummary, tabFindParams, handleBulkDeleteRows, tabBulkDelete, previewFace]);
4060+
}, [writeTabColumnState, enlargedGrid, windowed, total, currentPage, effectivePageSize, relatedData.length, hasMore, sortedData.length, paginatedData.length, activeSort, handleTableSort, objectSchema, onRowEdit, onRowDelete, handleDeleteRow, tabList, tabRecordCountLead, pickTabSummary, tabFindParams, handleBulkDeleteRows, tabBulkDelete, previewFace, cardFields]);
40404061

40414062
// objectstack#35601 — a stateful child (tasks) is grouped by its status on
40424063
// the related tab: open groups first, completed last (`statusGroupsOf`).

‎ui/packages/plugin-grid/src/ObjectGrid.tsx‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,18 @@ export interface ObjectGridComponentProps extends ObjectGridExternalPaginationPr
277277
* prop, never authored metadata.
278278
*/
279279
cardFace?: boolean;
280+
/**
281+
* [objectstack#38895] The fields the phone card's BODY reads, in priority
282+
* order, in place of the object's `highlightFields`: its amount is the first
283+
* that draws as money and its subtitle the next three, as for
284+
* `highlightFields`. A related list passes the list its relationship
285+
* declares (ADR-0035 §3/§4: the relationship's `relatedListColumns`, else the
286+
* child's `highlightFields`), never the lookup back to the page's own
287+
* record, which is the same value on every card. Absent: the object's
288+
* `highlightFields`, else the shown columns. Only the card reads it; the
289+
* table keeps its columns. A HOST prop, never authored metadata.
290+
*/
291+
cardFields?: readonly string[];
280292
/**
281293
* [objectstack#35702] The host's own wording of the record count that leads
282294
* the footer row (the list's 「42 records」, plural forms included). Absent ⇒
@@ -979,6 +991,7 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
979991
onColumnSummaryChange,
980992
residentSummaryRow,
981993
cardFace: hostCardFace,
994+
cardFields: hostCardFields,
982995
summaryRowLead,
983996
onColumnSummaryPick,
984997
summaryPickFields,
@@ -4446,8 +4459,12 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
44464459
// field-level security, so a field the viewer may not read is left out).
44474460
// The fetches that feed this grid ask for those fields beside the name
44484461
// field. An object that declares none keeps the shown columns' order.
4449-
const highlightNames = Array.isArray((objectSchema as any)?.highlightFields)
4450-
? [...new Set(((objectSchema as any).highlightFields as unknown[])
4462+
// objectstack#38895 — a host's `cardFields` (a related list: the list its
4463+
// relationship declares, minus the key back to the page's record) stands
4464+
// in for `highlightFields` and is read the same way.
4465+
const declaredCardFields: unknown = hostCardFields ?? (objectSchema as any)?.highlightFields;
4466+
const highlightNames = Array.isArray(declaredCardFields)
4467+
? [...new Set((declaredCardFields as unknown[])
44514468
.filter((n): n is string => typeof n === 'string' && !!objectFields?.[n]))]
44524469
: [];
44534470
const followsHighlights = highlightNames.length > 0;
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
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#38895 — on a phone, a record page's related tab draws each row
11+
* as the list card (objectstack#28484), and the card's BODY follows the
12+
* RELATIONSHIP's list, not the child object's `highlightFields`
13+
* (objectstack#37891, which stays for every other list): the relationship's
14+
* `relatedListColumns` when it declares them, else the child's
15+
* `highlightFields` — the override chain of ADR-0035 §3/§4 the tab's table
16+
* already follows. The lookup back to the page's own record is never a part:
17+
* it is the same value on every card, and the list never expands it, so it
18+
* could only draw a raw id.
19+
*
20+
* Driven through the real chain the tab draws: `RelatedList` (enlarged, a
21+
* list of the parent record) → `object-grid` → its card renderer. The fixture
22+
* is HotCRM's opportunity line on a product's page: `highlightFields` leads
23+
* with the product (right for the line's own page and the deal's list), while
24+
* the product relationship's `relatedListColumns` leads with the deal.
25+
*
26+
* ── Directions on the base tree (measured by reverting the fix) ──────────
27+
* declared columns: the deal is a part, by its name RED
28+
* declared columns: no part is the product's id RED
29+
* no declared columns: highlightFields minus the product RED
30+
* control: the tab's table at a desktop width keeps its columns GREEN
31+
*/
32+
import { describe, it, expect, vi, beforeAll, afterEach } from 'vitest';
33+
import { render, cleanup, waitFor, within } from '@testing-library/react';
34+
import '@testing-library/jest-dom';
35+
import React from 'react';
36+
37+
vi.mock('@object-ui/permissions', async (importOriginal) => {
38+
const actual = await importOriginal<typeof import('@object-ui/permissions')>();
39+
return {
40+
...actual,
41+
usePermissions: () => ({ isLoaded: false, checkField: () => true, getObjectApiOperations: () => undefined, can: () => true }),
42+
};
43+
});
44+
45+
// Registers `object-grid`, the enlarged related tab's face.
46+
import '../index';
47+
import { registerAllFields } from '@object-ui/fields';
48+
import { LocalizationProvider } from '@object-ui/i18n';
49+
import { ActionProvider, FilterScopeProvider, SchemaRendererProvider } from '@object-ui/react';
50+
import { RelatedList } from '../../../plugin-detail/src/RelatedList';
51+
import { RelatedListEnlargedContext } from '../../../plugin-detail/src/relatedListCompact';
52+
import { resetRelatedTabConditionsForTests } from '../../../plugin-detail/src/relatedTabConditions';
53+
54+
registerAllFields();
55+
56+
const ORIGINAL_INNER_WIDTH = window.innerWidth;
57+
function setWidth(px: number) {
58+
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: px });
59+
}
60+
61+
beforeAll(() => {
62+
if (!Element.prototype.scrollIntoView) Element.prototype.scrollIntoView = vi.fn() as any;
63+
});
64+
65+
afterEach(() => {
66+
cleanup();
67+
setWidth(ORIGINAL_INNER_WIDTH);
68+
resetRelatedTabConditionsForTests();
69+
});
70+
71+
const LINE_OBJECT = 'crm_opportunity_line_item_38895';
72+
const LINE_FIELDS = {
73+
id: { type: 'text' },
74+
product_title: { type: 'text', label: 'Product Title' },
75+
crm_product: { type: 'lookup', reference: 'crm_product', label: 'Product' },
76+
crm_opportunity: { type: 'lookup', reference: 'crm_opportunity', label: 'Opportunity' },
77+
quantity: { type: 'number', label: 'Quantity', scale: 0 },
78+
unit_price: { type: 'currency', label: 'Sales Price' },
79+
total_price: {
80+
type: 'formula',
81+
label: 'Total',
82+
returnType: 'currency',
83+
expression: 'record.quantity * record.unit_price',
84+
},
85+
};
86+
/** HotCRM's line: the product leads, for the line's own page and the deal's list. */
87+
const HIGHLIGHTS = ['crm_product', 'quantity', 'unit_price', 'total_price'];
88+
/** HotCRM's `relatedListColumns` on the line's product relationship: the deal leads. */
89+
const PRODUCT_RELATED_COLUMNS = ['crm_opportunity', 'quantity', 'unit_price', 'total_price'];
90+
91+
const PRODUCT_ID = 'TcoGX1WJ77TN-SKX';
92+
const DEALS: Record<string, { id: string; name: string }> = {
93+
o1: { id: 'o1', name: 'Globex Line Expansion' },
94+
o2: { id: 'o2', name: 'Lattice Student Success Platform' },
95+
};
96+
const LINES = [
97+
{ id: 'l1', product_title: 'AI Agent Seat (Annual)', crm_product: PRODUCT_ID, crm_opportunity: 'o1', quantity: 8, unit_price: 1000, total_price: 8000 },
98+
{ id: 'l2', product_title: 'AI Agent Seat (Annual)', crm_product: PRODUCT_ID, crm_opportunity: 'o2', quantity: 5, unit_price: 1000, total_price: 5000 },
99+
];
100+
101+
/**
102+
* A backend that honours `$expand`, as the ObjectStack read path does. It
103+
* holds the lines alone, so a lookup the list did not expand cannot be
104+
* resolved by a second read and draws whatever the row carries.
105+
*/
106+
function makeDataSource() {
107+
return {
108+
find: vi.fn(async (object: string, params: { $expand?: string[] } = {}) => {
109+
if (object !== LINE_OBJECT) return { data: [], total: 0 };
110+
const expand = new Set(params.$expand ?? []);
111+
return {
112+
data: LINES.map((line) => ({
113+
...line,
114+
...(expand.has('crm_opportunity') ? { crm_opportunity: DEALS[line.crm_opportunity] } : {}),
115+
...(expand.has('crm_product') ? { crm_product: { id: PRODUCT_ID, name: 'AI Agent Seat (Annual)' } } : {}),
116+
})),
117+
total: LINES.length,
118+
};
119+
}),
120+
getObjectSchema: vi.fn(async (name: string) => ({
121+
name,
122+
nameField: 'product_title',
123+
highlightFields: HIGHLIGHTS,
124+
fields: structuredClone(LINE_FIELDS),
125+
})),
126+
} as any;
127+
}
128+
129+
/** The product page's 「Opportunity Line Items」 tab. */
130+
async function renderProductLinesTab(opts: { width: number; columns?: string[] }) {
131+
setWidth(opts.width);
132+
const ds = makeDataSource();
133+
const utils = render(
134+
<LocalizationProvider value={{ currency: 'USD', locale: 'en' }}>
135+
<ActionProvider>
136+
<SchemaRendererProvider dataSource={ds}>
137+
<FilterScopeProvider currentUserId="u-1">
138+
<RelatedListEnlargedContext.Provider value>
139+
<RelatedList
140+
title="Opportunity Line Items"
141+
type="table"
142+
api={LINE_OBJECT}
143+
objectName={LINE_OBJECT}
144+
referenceField="crm_product"
145+
parentId={PRODUCT_ID}
146+
{...(opts.columns ? { columns: opts.columns } : {})}
147+
dataSource={ds}
148+
/>
149+
</RelatedListEnlargedContext.Provider>
150+
</FilterScopeProvider>
151+
</SchemaRendererProvider>
152+
</ActionProvider>
153+
</LocalizationProvider>,
154+
);
155+
return { ...utils, ds };
156+
}
157+
158+
const cards = () => Array.from(document.querySelectorAll<HTMLElement>('[data-testid="grid-mobile-card"]'));
159+
const parts = (card: HTMLElement) =>
160+
within(card).queryAllByTestId('grid-card-subtitle-part').map((p) => p.textContent?.trim());
161+
162+
async function phoneCards(columns?: string[]) {
163+
const g = await renderProductLinesTab({ width: 390, ...(columns ? { columns } : {}) });
164+
await waitFor(() => expect(cards()).toHaveLength(2), { timeout: 5000 });
165+
// The money cells read the field defs, so a dollar amount proves they landed.
166+
await waitFor(() => expect(document.body.textContent).toContain('$'));
167+
expect(document.querySelector('table'), 'the card layout, not the table').toBeNull();
168+
return { ...g, first: cards()[0], second: cards()[1] };
169+
}
170+
171+
describe('the phone card of a related tab follows the relationship\'s list (objectstack#38895)', () => {
172+
it('with relatedListColumns declared, each card names its deal and its quantity, never the page\'s product', async () => {
173+
const { first, second, ds } = await phoneCards(PRODUCT_RELATED_COLUMNS);
174+
// The list expands the deal it lists and never the key back to the page.
175+
const lineReads = ds.find.mock.calls.filter((call: unknown[]) => call[0] === LINE_OBJECT);
176+
const params = lineReads.at(-1)?.[1] as { $expand?: string[] };
177+
expect(params.$expand).toContain('crm_opportunity');
178+
expect(params.$expand ?? []).not.toContain('crm_product');
179+
180+
expect(parts(first)).toEqual(['Globex Line Expansion', 'Quantity 8', 'Total $8,000.00']);
181+
expect(parts(second)).toEqual(['Lattice Student Success Platform', 'Quantity 5', 'Total $5,000.00']);
182+
// The amount is the first money field of the relationship's list.
183+
expect(within(first).getByTestId('grid-card-amount').textContent).toBe('$1,000.00');
184+
for (const card of [first, second]) {
185+
expect(card.textContent, 'no raw id of the page\'s own record').not.toContain(PRODUCT_ID);
186+
}
187+
});
188+
189+
it('with no relatedListColumns, the card falls back to the child\'s highlightFields, minus the key back to the page', async () => {
190+
const { first, second } = await phoneCards();
191+
expect(parts(first)).toEqual(['Quantity 8', 'Total $8,000.00']);
192+
expect(within(first).getByTestId('grid-card-amount').textContent).toBe('$1,000.00');
193+
for (const card of [first, second]) {
194+
expect(card.textContent, 'no raw id of the page\'s own record').not.toContain(PRODUCT_ID);
195+
}
196+
});
197+
198+
it('CONTROL: the same tab at a desktop width is the table of the relationship\'s columns', async () => {
199+
await renderProductLinesTab({ width: 1440, columns: PRODUCT_RELATED_COLUMNS });
200+
await waitFor(() => expect(document.querySelector('table')).not.toBeNull(), { timeout: 5000 });
201+
await waitFor(() => expect(document.body.textContent).toContain('Globex Line Expansion'));
202+
expect(cards()).toHaveLength(0);
203+
const headers = Array.from(document.querySelectorAll('thead th')).map((th) => th.textContent?.trim() ?? '');
204+
for (const label of ['Opportunity', 'Quantity', 'Sales Price', 'Total']) {
205+
expect(headers.some((h) => h.includes(label)), `a ${label} column`).toBe(true);
206+
}
207+
expect(headers.some((h) => h === 'Product'), 'no column for the key back to the page').toBe(false);
208+
});
209+
});

0 commit comments

Comments
 (0)