Skip to content

Commit 0179f34

Browse files
committed
test(plugin-grid, app-shell): the bulk and parameter dialogs leave a { $record } lookup filter out
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ADHkmTKRu1t68jcJGgRYi3
1 parent 9775a8c commit 0179f34

2 files changed

Lines changed: 159 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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#34197 — an action's parameter dialog is not a record form, so a
11+
* lookup param whose `lookupFilters` read `{ $record }` leaves that entry out,
12+
* even when a SIBLING param carries a value of the same name.
13+
*
14+
* The dialog hands every picker its own in-progress values as
15+
* `dependentValues` (objectui#8672 ruling A), and those values are not the
16+
* record a `{ $record: 'quote_date' }` path names. The picker resolves a
17+
* reference only on a field a record form stamped (`withRecordBeingEdited`);
18+
* `paramToField` builds the widget field from enumerated keys and stamps
19+
* nothing. Driven through the real `ActionParamDialog`.
20+
*
21+
* CONTROL: the literal entry beside it reaches the candidate query, so the
22+
* dialog does forward `lookupFilters` — the missing entry is left out, not
23+
* lost with the rest.
24+
*/
25+
import { describe, it, expect, vi, beforeAll } from 'vitest';
26+
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
27+
import '@testing-library/jest-dom';
28+
import type { ActionParamDef } from '@object-ui/core';
29+
import { SchemaRendererProvider } from '@object-ui/react';
30+
// Module scope, per AGENTS.md 测试纪律: the picker sits behind `React.lazy`.
31+
import '@object-ui/fields';
32+
import { ActionParamDialog } from './ActionParamDialog';
33+
34+
beforeAll(() => {
35+
if (!Element.prototype.scrollIntoView) Element.prototype.scrollIntoView = vi.fn() as never;
36+
});
37+
38+
const QUOTE_DATE: ActionParamDef = { name: 'quote_date', label: 'Quote date', type: 'text' };
39+
const PRICE_BOOK: ActionParamDef = {
40+
name: 'price_book',
41+
label: 'Price Book',
42+
type: 'lookup',
43+
referenceTo: 'price_book',
44+
lookupFilters: [
45+
{ field: 'is_active', operator: 'eq', value: true },
46+
{ field: 'valid_from', operator: 'lte', value: { $record: 'quote_date' }, orEmpty: true },
47+
],
48+
} as ActionParamDef;
49+
50+
describe('ActionParamDialog — a { $record } lookup filter is left out (objectstack#34197)', () => {
51+
it('leaves the entry out although a sibling param holds a value of that name', async () => {
52+
const ds = {
53+
find: vi.fn(async () => ({ data: [{ id: 'b1', name: 'Standard 2026' }], total: 1 })),
54+
findOne: vi.fn(async () => null),
55+
};
56+
render(
57+
<SchemaRendererProvider dataSource={ds as never}>
58+
<ActionParamDialog state={{ open: true, params: [QUOTE_DATE, PRICE_BOOK], resolve: () => {} }} onOpenChange={() => {}} />
59+
</SchemaRendererProvider>,
60+
);
61+
fireEvent.change(await screen.findByLabelText('Quote date'), { target: { value: '2026-11-01' } });
62+
63+
const trigger = await screen.findByTestId('lookup-trigger-price_book');
64+
await act(async () => {
65+
fireEvent.click(trigger);
66+
});
67+
const queries = () => ds.find.mock.calls.filter((c: any[]) => c[0] === 'price_book').map((c: any[]) => c[1]?.$filter);
68+
await waitFor(() => expect(queries().length).toBeGreaterThan(0));
69+
for (const filter of queries()) expect(filter).toEqual({ is_active: true });
70+
expect(ds.findOne).not.toHaveBeenCalled();
71+
});
72+
});
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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#34197 — a bulk action dialog edits no single record, so a
11+
* lookup param whose `lookupFilters` read `{ $record }` leaves that entry out,
12+
* even when a SIBLING param carries a value of the same name.
13+
*
14+
* The dialog hands every picker its own in-progress values as
15+
* `dependentValues` (objectui#8755), and those values are not the record a
16+
* `{ $record: 'quote_date' }` path names. The picker resolves a reference
17+
* only on a field a record form stamped (`withRecordBeingEdited`); this
18+
* dialog stamps nothing. Driven through the real `BulkActionDialog`, because
19+
* the hand-off of the sibling values IS the hazard.
20+
*
21+
* CONTROL: the literal entry beside it reaches the candidate query, so the
22+
* dialog does forward `lookupFilters` — the missing entry is left out, not
23+
* lost with the rest.
24+
*/
25+
import { describe, it, expect, vi, beforeAll } from 'vitest';
26+
import React from 'react';
27+
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
28+
import '@testing-library/jest-dom';
29+
// Module scope, per AGENTS.md §测试纪律: the picker sits behind `React.lazy`.
30+
import '@object-ui/fields';
31+
import { BulkActionDialog } from '../components/BulkActionDialog';
32+
33+
beforeAll(() => {
34+
if (!Element.prototype.scrollIntoView) Element.prototype.scrollIntoView = vi.fn() as any;
35+
});
36+
37+
function makeDataSource() {
38+
return {
39+
find: vi.fn(async () => ({ data: [{ id: 'b1', name: 'Standard 2026' }], total: 1 })),
40+
findOne: vi.fn(async () => null),
41+
update: vi.fn(async () => ({})),
42+
delete: vi.fn(async () => ({})),
43+
} as any;
44+
}
45+
46+
const QUOTE_DATE = { name: 'quote_date', label: 'Quote date', type: 'text' };
47+
const PRICE_BOOK = {
48+
name: 'price_book',
49+
label: 'Price Book',
50+
type: 'lookup',
51+
object: 'price_book',
52+
lookupFilters: [
53+
{ field: 'is_active', operator: 'eq', value: true },
54+
{ field: 'valid_from', operator: 'lte', value: { $record: 'quote_date' }, orEmpty: true },
55+
],
56+
};
57+
58+
describe('BulkActionDialog — a { $record } lookup filter is left out (objectstack#34197)', () => {
59+
it('leaves the entry out although a sibling param holds a value of that name', async () => {
60+
const ds = makeDataSource();
61+
render(
62+
<BulkActionDialog
63+
def={{ name: 'bulk_reprice', label: 'Reprice', operation: 'update', params: [QUOTE_DATE, PRICE_BOOK] } as any}
64+
rows={[{ id: 'r1' }, { id: 'r2' }]}
65+
resource="quote"
66+
dataSource={ds}
67+
open
68+
onClose={() => {}}
69+
/>,
70+
);
71+
const dateInput = await waitFor(() => {
72+
const el = document.getElementById('bulk-param-quote_date');
73+
if (!el) throw new Error('dialog not ready');
74+
return el;
75+
});
76+
fireEvent.change(dateInput, { target: { value: '2026-11-01' } });
77+
78+
const trigger = await screen.findByTestId('lookup-trigger-price_book');
79+
await act(async () => {
80+
fireEvent.click(trigger);
81+
});
82+
const queries = () => ds.find.mock.calls.filter((c: any[]) => c[0] === 'price_book').map((c: any[]) => c[1]?.$filter);
83+
await waitFor(() => expect(queries().length).toBeGreaterThan(0));
84+
for (const filter of queries()) expect(filter).toEqual({ is_active: true });
85+
expect(ds.findOne).not.toHaveBeenCalled();
86+
});
87+
});

0 commit comments

Comments
 (0)