Skip to content

Commit 32340f2

Browse files
committed
test: pin the phone card's highlightFields read and the three fetches
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwy7XB37e8e1P6jRJ3
1 parent d7665a2 commit 32340f2

3 files changed

Lines changed: 266 additions & 0 deletions

File tree

‎ui/packages/plugin-detail/src/__tests__/RelatedList.selectFls-10186.test.tsx‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,45 @@ describe('RelatedList row fetch — the derived-columns boundary (objectui#10186
341341
for (const params of rowFetches(ds)) expect('$select' in params).toBe(false);
342342
});
343343
});
344+
345+
/**
346+
* objectstack#37891 — the child object's `highlightFields` (ADR-0085) ride
347+
* along. On a phone the enlarged tab's grid draws each row as a card whose
348+
* amount and subtitle are those fields, in that order, whether or not a
349+
* column shows them, so the rows this list reads must carry them. Through the
350+
* name field's gates: declared, readable, not redacted.
351+
*
352+
* a declared, readable highlighted field no column shows is requested RED on the base tree
353+
* a highlighted field FLS denies is not requested GREEN
354+
* control: no highlightFields keeps the projection byte-identical GREEN
355+
*/
356+
describe('RelatedList row fetch — the child object\'s highlightFields ride along (objectstack#37891)', () => {
357+
const withHighlights = { name: OBJECT, highlightFields: ['salary', 'title', 'undeclared_field'], fields: baseFields };
358+
const lastSelect = (ds: ReturnType<typeof makeDataSource>): string[] =>
359+
rowFetches(ds).at(-1)?.$select ?? [];
360+
const schemaLanded = (): boolean =>
361+
tableDrawn() && typeof (h.schema?.columns ?? []).find((c: any) => c.accessorKey === 'name')?.cell === 'function';
362+
363+
it('requests a declared, readable highlighted field no column shows, and never an undeclared one', async () => {
364+
const ds = makeDataSource(withHighlights);
365+
renderList(ds, [], { columns: ['name'] });
366+
await waitFor(() => expect(lastSelect(ds)).toContain('salary'));
367+
expect(lastSelect(ds)).toEqual(['id', 'name', 'salary', 'title']);
368+
expect(drawnKeys()).not.toContain('salary');
369+
});
370+
371+
it('does not request a highlighted field FLS denies', async () => {
372+
const ds = makeDataSource(withHighlights);
373+
renderList(ds, denying('salary'), { columns: ['name'] });
374+
await waitFor(() => expect(schemaLanded()).toBe(true));
375+
for (const params of rowFetches(ds)) expect(params.$select).not.toContain('salary');
376+
expect(lastSelect(ds)).toEqual(['id', 'name', 'title']);
377+
});
378+
379+
it('control: a child with no highlightFields sends the projection it sent before', async () => {
380+
const ds = makeDataSource();
381+
renderList(ds, [], { columns: ['name'] });
382+
await waitFor(() => expect(schemaLanded()).toBe(true));
383+
expect(lastSelect(ds)).toEqual(['id', 'name']);
384+
});
385+
});

‎ui/packages/plugin-grid/src/__tests__/phoneCardAmount-34615.test.tsx‎

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,140 @@ describe('the phone card amount slot takes a formula or summary that draws as mo
257257
expect(within(card).queryByTestId('grid-card-amount-line')).toBeNull();
258258
});
259259
});
260+
261+
/**
262+
* objectstack#37891 — when the object declares `highlightFields` (ADR-0085,
263+
* "which fields matter most", in order), the phone card reads its amount and
264+
* subtitle from that list, not from the view's column order: the amount is
265+
* the first highlighted field that draws as money, the subtitle the next
266+
* three, in that order, empty values dropped, and a number, currency or
267+
* percent part carries its field label. A highlighted field no column shows
268+
* is drawn too, and the grid's fetch asks for it. An object that declares no
269+
* `highlightFields` keeps the column-order rule above.
270+
*
271+
* The fixture is HotCRM's order line (`crm_sales_order_line`), whose related
272+
* list shows `line_number, product_title, quantity, unit_price, discount,
273+
* total_price`: on the base tree its card read `1 · 2` with the unit price as
274+
* the amount, whatever `highlightFields` said.
275+
*
276+
* ── Directions on the base tree (predicted before the first run) ─────────
277+
* amount is the highlighted total, not the unit price RED
278+
* subtitle is the labelled highlighted parts, in order RED
279+
* a highlighted field no column shows is drawn and fetched RED
280+
* an empty highlighted part is dropped RED
281+
* control: no highlightFields keeps `1 · 2`, unit price, no labels GREEN
282+
* control: a masked highlighted field is neither amount nor part GREEN
283+
*/
284+
describe('the phone card follows the object\'s highlightFields (objectstack#37891)', () => {
285+
const LINE_OBJECT = 'crm_sales_order_line_37891';
286+
const LINE_FIELDS = {
287+
id: { type: 'text' },
288+
product_title: { type: 'text', label: 'Product Title' },
289+
crm_product: { type: 'text', label: 'Product' },
290+
quantity: { type: 'number', label: 'Quantity', scale: 0 },
291+
unit_price: { type: 'currency', label: 'Sales Price' },
292+
discount: { type: 'percent', label: 'Discount %', scale: 2 },
293+
total_price: {
294+
type: 'formula',
295+
label: 'Total',
296+
returnType: 'currency',
297+
expression: 'record.quantity * record.unit_price * (1 - record.discount / 100)',
298+
},
299+
line_number: { type: 'number', label: 'Line #', scale: 0 },
300+
access_pin: { type: 'password', label: 'Access PIN' },
301+
};
302+
const LINE_ROWS = [
303+
{ id: 'l1', line_number: 1, product_title: 'Admin Training Workshop', crm_product: 'Training', quantity: 2, unit_price: 6000, discount: 10, total_price: 10800, access_pin: 's3cr3t-pin' },
304+
{ id: 'l2', line_number: 2, product_title: 'AI Agent Seat (Annual)', crm_product: 'Seat', quantity: 10, unit_price: 1000, discount: null, total_price: 10000, access_pin: 's3cr3t-pin' },
305+
];
306+
/** HotCRM's `relatedListColumns` for the order's lines. */
307+
const RELATED = ['line_number', 'product_title', 'quantity', 'unit_price', 'discount', 'total_price'];
308+
309+
async function lineCards(columns: string[], highlightFields?: string[]) {
310+
setWidth(390);
311+
const find = vi.fn(async () => ({ data: LINE_ROWS, total: LINE_ROWS.length, hasMore: false, pageSize: 50 }));
312+
const dataSource = {
313+
find,
314+
getObjectSchema: async (name: string) => ({
315+
name,
316+
nameField: 'product_title',
317+
...(highlightFields ? { highlightFields } : {}),
318+
fields: structuredClone(LINE_FIELDS),
319+
}),
320+
} as never;
321+
render(
322+
<LocalizationProvider value={{ currency: 'CNY', locale: 'en' }}>
323+
<ActionProvider>
324+
<SchemaRendererProvider dataSource={dataSource}>
325+
<ObjectGrid
326+
schema={{ type: 'object-grid', objectName: LINE_OBJECT, columns: columns.map((field) => ({ field })), pagination: { pageSize: 50 } } as never}
327+
dataSource={dataSource}
328+
/>
329+
</SchemaRendererProvider>
330+
</ActionProvider>
331+
</LocalizationProvider>,
332+
);
333+
// The money cells read the field defs, so a CN¥ amount proves they landed.
334+
await waitFor(() => expect(cards()).toHaveLength(2));
335+
await waitFor(() => expect(document.body.textContent).toContain('CN¥'));
336+
expect(document.querySelector('table'), 'the card layout, not the table').toBeNull();
337+
return { find, first: cardOf('Admin Training Workshop'), second: cardOf('AI Agent Seat (Annual)') };
338+
}
339+
const parts = (card: HTMLElement) => within(card).getAllByTestId('grid-card-subtitle-part');
340+
const labels = (card: HTMLElement) =>
341+
within(card).queryAllByTestId('grid-card-subtitle-label').map((el) => el.textContent?.trim());
342+
343+
it('takes the first highlighted money field as the amount: the line total, not the unit price the table shows first', async () => {
344+
const { first } = await lineCards(RELATED, ['total_price', 'quantity', 'unit_price', 'discount']);
345+
expect(within(first).getByTestId('grid-card-amount').textContent).toBe('CN¥10,800.00');
346+
});
347+
348+
it('draws the next highlighted fields as the subtitle, in order, each figure under its field label', async () => {
349+
const { first } = await lineCards(RELATED, ['total_price', 'quantity', 'unit_price', 'discount']);
350+
expect(parts(first)).toHaveLength(3);
351+
expect(labels(first)).toEqual(['Quantity', 'Sales Price', 'Discount %']);
352+
const [quantity, price, discount] = parts(first).map((p) => p.textContent);
353+
expect(quantity).toBe('Quantity 2');
354+
expect(price).toBe('Sales Price CN¥6,000.00');
355+
expect(discount).toMatch(/^Discount % 10(\.00)?\s?%$/);
356+
// The line number the table shows first is no longer a subtitle part.
357+
expect(within(first).getByTestId('grid-card-subtitle').textContent).not.toMatch(/^1 ·/);
358+
});
359+
360+
it('labels only figures: a text part is drawn bare', async () => {
361+
const { first } = await lineCards(RELATED, ['total_price', 'crm_product', 'quantity']);
362+
expect(parts(first).map((p) => p.textContent)).toEqual(['Training', 'Quantity 2']);
363+
expect(labels(first)).toEqual(['Quantity']);
364+
});
365+
366+
it('drops an empty highlighted part rather than drawing it', async () => {
367+
const { second } = await lineCards(RELATED, ['total_price', 'quantity', 'unit_price', 'discount']);
368+
expect(within(second).getByTestId('grid-card-amount').textContent).toBe('CN¥10,000.00');
369+
expect(labels(second)).toEqual(['Quantity', 'Sales Price']);
370+
});
371+
372+
it('draws a highlighted field no column shows, and the fetch asks for it', async () => {
373+
const { first, find } = await lineCards(
374+
['line_number', 'product_title', 'quantity', 'unit_price'],
375+
['total_price', 'quantity', 'unit_price', 'discount'],
376+
);
377+
expect(within(first).getByTestId('grid-card-amount').textContent).toBe('CN¥10,800.00');
378+
expect(labels(first)).toEqual(['Quantity', 'Sales Price', 'Discount %']);
379+
const select = (find.mock.calls.at(-1) as unknown[] | undefined)?.[1] as { $select?: string[] } | undefined;
380+
expect(select?.$select).toEqual(expect.arrayContaining(['total_price', 'discount']));
381+
});
382+
383+
it('CONTROL: an object with no highlightFields keeps the column-order card (line number · quantity, unit price, no labels)', async () => {
384+
const { first } = await lineCards(RELATED);
385+
expect(within(first).getByTestId('grid-card-subtitle').textContent).toBe('1 · 2');
386+
expect(within(first).getByTestId('grid-card-amount').textContent).toBe('CN¥6,000.00');
387+
expect(labels(first)).toEqual([]);
388+
});
389+
390+
it('CONTROL: a masked highlighted field is neither the amount nor a subtitle part, and its value is never printed', async () => {
391+
const { first } = await lineCards(RELATED, ['access_pin', 'total_price', 'quantity']);
392+
expect(within(first).getByTestId('grid-card-amount').textContent).toBe('CN¥10,800.00');
393+
expect(labels(first)).toEqual(['Quantity']);
394+
expect(first.textContent).not.toContain('s3cr3t-pin');
395+
});
396+
});

‎ui/packages/plugin-list/src/__tests__/ListView.harness.test.tsx‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,6 +3109,93 @@ describe('ListView.nameFieldSelect-13116', () => {
31093109
});
31103110
});
31113111

3112+
// ── ListView.highlightFieldsSelect-37891 ───────────────────────────────────────
3113+
3114+
/**
3115+
* objectstack#37891 — an ungrouped list asks for the object's
3116+
* `highlightFields` (ADR-0085). On a phone the grid draws each row this fetch
3117+
* hands it as a card whose amount and subtitle are those fields, in that
3118+
* order, whether or not a column shows them; without this arm a list showing
3119+
* `unit_price` but not `total_price` handed the grid rows with no total to
3120+
* put in the amount slot. Fetched, never drawn as columns. A grouped grid
3121+
* that owns its fetch projects through `ObjectGrid`'s `getSelectFields`,
3122+
* pinned in plugin-grid's `phoneCardAmount-34615.test.tsx`.
3123+
*
3124+
* a highlighted field no column shows is in `$select`, not drawn RED on the base tree
3125+
* control: an object with no highlightFields sends the same select GREEN
3126+
*/
3127+
describe('ListView.highlightFieldsSelect-37891', () => {
3128+
restoreAfterBlock();
3129+
3130+
const LINE = 'crm_sales_order_line';
3131+
const lineFields = {
3132+
id: { name: 'id', type: 'text' },
3133+
product_title: { name: 'product_title', type: 'text', label: 'Product Title' },
3134+
quantity: { name: 'quantity', type: 'number', label: 'Quantity' },
3135+
unit_price: { name: 'unit_price', type: 'currency', label: 'Sales Price' },
3136+
discount: { name: 'discount', type: 'percent', label: 'Discount %' },
3137+
total_price: { name: 'total_price', type: 'formula', returnType: 'currency', label: 'Total', expression: 'record.quantity * record.unit_price' },
3138+
};
3139+
const ROWS = [{ id: 'l1', product_title: 'Workshop', quantity: 2, unit_price: 6000, discount: 10, total_price: 10800 }];
3140+
3141+
let lastGridProps: any = null;
3142+
let prevObjectGrid: any;
3143+
beforeAll(() => {
3144+
prevObjectGrid = ComponentRegistry.get('object-grid');
3145+
ComponentRegistry.register('object-grid', (props: any) => {
3146+
lastGridProps = props;
3147+
return <div data-testid="grid-stub" />;
3148+
});
3149+
});
3150+
afterAll(() => {
3151+
if (prevObjectGrid) ComponentRegistry.register('object-grid', prevObjectGrid);
3152+
else ComponentRegistry.unregister('object-grid');
3153+
});
3154+
beforeEach(() => {
3155+
vi.clearAllMocks();
3156+
lastGridProps = null;
3157+
});
3158+
afterEach(() => {
3159+
cleanup();
3160+
lastGridProps = null;
3161+
});
3162+
3163+
async function mount(def: Record<string, unknown>, columns: string[]) {
3164+
const dataSource = {
3165+
find: vi.fn(async () => ({ data: ROWS, total: ROWS.length })),
3166+
findOne: vi.fn(),
3167+
create: vi.fn(),
3168+
update: vi.fn(),
3169+
delete: vi.fn(),
3170+
getObjectSchema: vi.fn(async (name: string) => (name === def.name ? def : null)),
3171+
} as any;
3172+
render(
3173+
<SchemaRendererProvider dataSource={dataSource}>
3174+
<ListView
3175+
schema={{ type: 'list-view', objectName: def.name as string, viewType: 'grid', columns, userActions: { editInline: false } } as any}
3176+
dataSource={dataSource}
3177+
/>
3178+
</SchemaRendererProvider>,
3179+
);
3180+
await waitFor(() => expect(dataSource.find).toHaveBeenCalled());
3181+
return [...((dataSource.find.mock.calls.at(-1)?.[1]?.$select as string[] | undefined) ?? [])].sort();
3182+
}
3183+
3184+
it('asks for a highlighted field no column shows, and does not draw it as a column', async () => {
3185+
const def = { name: LINE, nameField: 'product_title', highlightFields: ['total_price', 'quantity', 'unit_price', 'discount'], fields: lineFields };
3186+
const select = await mount(def, ['product_title', 'quantity', 'unit_price']);
3187+
expect(select).toEqual(['discount', 'id', 'product_title', 'quantity', 'total_price', 'unit_price']);
3188+
const drawn = (lastGridProps?.columns ?? lastGridProps?.fields ?? []) as unknown[];
3189+
expect(JSON.stringify(drawn)).not.toContain('total_price');
3190+
});
3191+
3192+
it('control: an object with no highlightFields sends the same $select as before', async () => {
3193+
const def = { name: LINE, nameField: 'product_title', fields: lineFields };
3194+
const select = await mount(def, ['product_title', 'quantity', 'unit_price']);
3195+
expect(select).toEqual(['id', 'product_title', 'quantity', 'unit_price']);
3196+
});
3197+
});
3198+
31123199
// ── ListView.recordDrawerCount-27545 ────────────────────────────────────────────
31133200

31143201
/**

0 commit comments

Comments
 (0)