Skip to content

Commit 6dffff8

Browse files
committed
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzi3ezPzTysQPDEjmVz
1 parent 4443014 commit 6dffff8

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

‎ui/packages/fields/src/widgets/__tests__/FilterConditionField.betweenBlankBound-9914.test.tsx‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ async function pickFrom(index: 0 | 1, label: string) {
114114
fireEvent.click(option);
115115
}
116116

117+
/**
118+
* A number range's bound once the object schema has typed its column.
119+
*
120+
* The widget draws the stored row before `getObjectSchema` resolves, with an
121+
* untyped (text) bound that becomes `<input type="number">` when the schema
122+
* lands. A bare `findByLabelText` resolves on the first box it sees, so a
123+
* typed-value assertion straight after it races the schema.
124+
*/
125+
function findTypedBound(label: 'From' | 'To') {
126+
return screen.findByRole('spinbutton', { name: label });
127+
}
128+
117129
describe('the dropdown path: a date range authors nothing until both bounds are filled', () => {
118130
it('emits nothing on pick and on one bound, then exactly the range', async () => {
119131
const { onChange } = renderWidget('');
@@ -170,7 +182,11 @@ describe('the stored-criteria path: clearing a bound of a saved range', () => {
170182

171183
// A saved number range loads as a `between` row with two editable bounds,
172184
// even though the number bucket does not offer `between` in its dropdown.
173-
const to = await screen.findByLabelText('To');
185+
// The row is seeded from the stored value at once, but `age` is typed
186+
// `number` only when the async object schema answers; until then the
187+
// bound is a text box holding `"5"`. Wait for the TYPED box (a number
188+
// input's role is `spinbutton`), never for whichever box is there first.
189+
const to = await findTypedBound('To');
174190
expect(to).toHaveValue(5);
175191
// Seeding is not an edit.
176192
expect(onChange).not.toHaveBeenCalled();
@@ -194,8 +210,8 @@ describe('a criteria already stored with a blank bound', () => {
194210
// the bound it has, and is rewritten only when the admin edits it.
195211
const { onChange } = renderWidget('{"age":{"$gte":1,"$lte":""}}');
196212

197-
const to = await screen.findByLabelText('To');
198-
expect(screen.getByLabelText('From')).toHaveValue(1);
213+
const to = await findTypedBound('To');
214+
expect(screen.getByRole('spinbutton', { name: 'From' })).toHaveValue(1);
199215
expect(to).toHaveValue(null);
200216
expect(onChange).not.toHaveBeenCalled();
201217

0 commit comments

Comments
 (0)