|
| 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