From 6dffff81de2248140d6a7e8049353eff4c1eaad4 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 23:22:47 +0000 Subject: [PATCH] test(fields): wait for the schema-typed range bound before asserting its number value The stored-criteria `between` tests asserted `toHaveValue(5)` / `toHaveValue(1)` straight after `findByLabelText('To')`. The widget seeds the row from the stored value at once but types `age` as a number only when the async `getObjectSchema` answers, so the first box found can still be the untyped text box holding "5". Wait for the typed box itself (`spinbutton` role). Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzi3ezPzTysQPDEjmVz --- ...itionField.betweenBlankBound-9914.test.tsx | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ui/packages/fields/src/widgets/__tests__/FilterConditionField.betweenBlankBound-9914.test.tsx b/ui/packages/fields/src/widgets/__tests__/FilterConditionField.betweenBlankBound-9914.test.tsx index ad96dd6b058..4f2b9b94a68 100644 --- a/ui/packages/fields/src/widgets/__tests__/FilterConditionField.betweenBlankBound-9914.test.tsx +++ b/ui/packages/fields/src/widgets/__tests__/FilterConditionField.betweenBlankBound-9914.test.tsx @@ -114,6 +114,18 @@ async function pickFrom(index: 0 | 1, label: string) { fireEvent.click(option); } +/** + * A number range's bound once the object schema has typed its column. + * + * The widget draws the stored row before `getObjectSchema` resolves, with an + * untyped (text) bound that becomes `` when the schema + * lands. A bare `findByLabelText` resolves on the first box it sees, so a + * typed-value assertion straight after it races the schema. + */ +function findTypedBound(label: 'From' | 'To') { + return screen.findByRole('spinbutton', { name: label }); +} + describe('the dropdown path: a date range authors nothing until both bounds are filled', () => { it('emits nothing on pick and on one bound, then exactly the range', async () => { const { onChange } = renderWidget(''); @@ -170,7 +182,11 @@ describe('the stored-criteria path: clearing a bound of a saved range', () => { // A saved number range loads as a `between` row with two editable bounds, // even though the number bucket does not offer `between` in its dropdown. - const to = await screen.findByLabelText('To'); + // The row is seeded from the stored value at once, but `age` is typed + // `number` only when the async object schema answers; until then the + // bound is a text box holding `"5"`. Wait for the TYPED box (a number + // input's role is `spinbutton`), never for whichever box is there first. + const to = await findTypedBound('To'); expect(to).toHaveValue(5); // Seeding is not an edit. expect(onChange).not.toHaveBeenCalled(); @@ -194,8 +210,8 @@ describe('a criteria already stored with a blank bound', () => { // the bound it has, and is rewritten only when the admin edits it. const { onChange } = renderWidget('{"age":{"$gte":1,"$lte":""}}'); - const to = await screen.findByLabelText('To'); - expect(screen.getByLabelText('From')).toHaveValue(1); + const to = await findTypedBound('To'); + expect(screen.getByRole('spinbutton', { name: 'From' })).toHaveValue(1); expect(to).toHaveValue(null); expect(onChange).not.toHaveBeenCalled();