From 52bace8b15e53d50b93b51267cce1a114be746bc Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 00:37:52 +0000 Subject: [PATCH] test(fields): wait for the schema-typed render in the emptyOperators and builderRows FilterConditionField tests Both files asserted on schema-dependent state right after a findBy that can resolve before the async `getObjectSchema` answers: an edit to the `amount` box emitted the string "6" (untyped text input), and the field trigger had no label yet. Wait for the typed number box (`spinbutton` role) and for the trigger's label, respectively. Same race and fix shape as the betweenBlankBound file. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzi3ezPzTysQPDEjmVz --- ...erConditionField.builderRows-8748.test.tsx | 8 +++++++- ...nditionField.emptyOperators-10790.test.tsx | 20 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/ui/packages/fields/src/widgets/__tests__/FilterConditionField.builderRows-8748.test.tsx b/ui/packages/fields/src/widgets/__tests__/FilterConditionField.builderRows-8748.test.tsx index 03552e1d1a2..b64b611796f 100644 --- a/ui/packages/fields/src/widgets/__tests__/FilterConditionField.builderRows-8748.test.tsx +++ b/ui/packages/fields/src/widgets/__tests__/FilterConditionField.builderRows-8748.test.tsx @@ -158,7 +158,13 @@ describe('a stored criteria still seeds the rows', () => { it('loads `{ name: { $icontains: "x" } }` into a row and emits nothing on its own', async () => { const { onChange } = renderWidget('{"name":{"$icontains":"x"}}'); - const triggers = await screen.findAllByRole('combobox'); + // The row is seeded before `getObjectSchema` resolves, and its field + // trigger reads the column's LABEL only once the schema answers: wait for + // that labelled render, never for whichever trigger is drawn first. (A + // combobox takes no accessible name from its content, so `findByRole` with + // `name` cannot spell this.) + await waitFor(() => expect(screen.getAllByRole('combobox')[0]).toHaveTextContent('Name')); + const triggers = screen.getAllByRole('combobox'); expect(triggers).toHaveLength(2); expect(triggers[0]).toHaveTextContent('Name'); expect(triggers[1]).toHaveTextContent('Contains (ignore case)'); diff --git a/ui/packages/fields/src/widgets/__tests__/FilterConditionField.emptyOperators-10790.test.tsx b/ui/packages/fields/src/widgets/__tests__/FilterConditionField.emptyOperators-10790.test.tsx index e074bbe8830..a1b58f20b7a 100644 --- a/ui/packages/fields/src/widgets/__tests__/FilterConditionField.emptyOperators-10790.test.tsx +++ b/ui/packages/fields/src/widgets/__tests__/FilterConditionField.emptyOperators-10790.test.tsx @@ -138,6 +138,20 @@ async function addRow() { fireEvent.click(add); } +/** + * The `amount` comparand box once the object schema has typed its column. + * + * A stored criteria seeds its rows before `getObjectSchema` resolves, and until + * then `amount` is untyped: its box is a text input and an edit is emitted as + * the string `"6"`. A number input's role is `spinbutton`, so waiting for that + * role waits for the typed render, not for whichever box is drawn first. + */ +async function findTypedAmountBox() { + const box = await screen.findByRole('spinbutton'); + expect(box).toHaveValue(5); + return box; +} + /** Drive a REAL Radix dropdown by its trigger's index in the document. */ async function pickFrom(index: number, label: string) { const triggers = screen.getAllByRole('combobox'); @@ -262,7 +276,7 @@ describe('RE-SAVE — a legacy rule is written as `$empty` once it is edited (ob { name: 'objectui#10790 "is not empty"', old: legacyIsNotEmpty('name'), fresh: isNotEmpty('name') }, ])('a $name row is rewritten when ANOTHER row is edited', async ({ old, fresh }) => { const { onChange } = renderWidget(JSON.stringify({ ...old, amount: 5 })); - const box = await screen.findByDisplayValue('5'); + const box = await findTypedAmountBox(); expect(onChange).not.toHaveBeenCalled(); fireEvent.change(box, { target: { value: '6' } }); const stored = lastEmitted(onChange); @@ -315,7 +329,7 @@ describe('GROUPS — the "is empty" row round-trips inside a group (objectui#108 const stored = { $or: [{ amount: 5 }, isEmpty('name')] }; expectAcceptedByTheFaces(JSON.stringify(stored)); const { onChange } = renderWidget(JSON.stringify(stored)); - const box = await screen.findByDisplayValue('5'); + const box = await findTypedAmountBox(); expect(screen.getAllByRole('combobox').map((t) => t.textContent)).toEqual([ 'Amount', 'Equals', 'Name', 'Is empty', ]); @@ -326,7 +340,7 @@ describe('GROUPS — the "is empty" row round-trips inside a group (objectui#108 it('a legacy entry inside an OR group is re-written as `$empty` once the group is edited', async () => { const stored = { $or: [{ amount: 5 }, legacyIsEmpty('name')] }; const { onChange } = renderWidget(JSON.stringify(stored)); - const box = await screen.findByDisplayValue('5'); + const box = await findTypedAmountBox(); expect(onChange).not.toHaveBeenCalled(); fireEvent.change(box, { target: { value: '6' } }); expect(lastEmitted(onChange)).toBe(JSON.stringify({ $or: [{ amount: 6 }, isEmpty('name')] }));