Skip to content

Commit d4661df

Browse files
test(fields): wait for the schema-typed range bound before asserting its number value (#35055)
🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WGufzi3ezPzTysQPDEjmVz Part of #34991 The card stays open: two sibling test files with the same race (`FilterConditionField.emptyOperators-10790`, `FilterConditionField.builderRows-8748`) follow in a second PR under it (seat order 2026-11-18 00:31Z, claim amendment 6965218495). repo:objectstack#3 · os-support-ai · session_01WGufzi3ezPzTysQPDEjmVz Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:只改一个测试文件。两个“已保存的数值区间”用例改为等待带类型的数字输入框(`spinbutton` 角色)出现后再断言 `toHaveValue(5)` / `toHaveValue(1)`。 - 为什么改:控件先用已保存的值画出区间行,`age` 的 number 类型要等异步的 `getObjectSchema` 返回才生效;在那之前框是文本框,值是字符串 "5"。原测试 `findByLabelText` 拿到第一个框就断言,在慢机上与 schema 赛跑,队列构建 44173515593 因此误踢 PR #34955。 - 风险与回滚:零产品风险,不改任何发布代码;回滚即还原这一个测试文件。断言没有放宽,仍要求数字 5。 - 先看:`ui/packages/fields/src/widgets/__tests__/FilterConditionField.betweenBlankBound-9914.test.tsx` 的 `findTypedBound` 及两处调用。 - 两分钟验证:把该文件的 `getObjectSchema` 改成延迟 300ms 返回后跑 `pnpm --filter @object-ui/fields exec vitest run --root ../.. packages/fields/src/widgets/__tests__/FilterConditionField.betweenBlankBound-9914.test.tsx`,预期 14/14 通过(修复前同样改动会在 :174 报 `5 (string)`)。 - 需要你做的:无,席位落地。 ## What changes The stored-criteria `between` tests asserted a typed value straight after `findByLabelText`. `FilterConditionField` seeds the row from the stored value at once, but `age` is typed `number` only when the async `getObjectSchema` answers; until then `FilterBuilder` draws the bound as a text box holding `"5"`. The test now waits for the typed box itself (`findByRole('spinbutton', { name })`), via one helper `findTypedBound`, in both tests of this file that had the race (`:174` `To`, and `:198` `From` in the blank-bound migration test). No skip, no retry, no quarantine; `toHaveValue(5)` and `toHaveValue(1)` are unchanged. Widget reading: after the schema lands the bound IS a number input showing the number, so no product change and no changeset. The untyped text box exists only in the window before the schema answers (see Acceptance notes). ## Tests <details><summary>Reproduction: schema resolution delayed 300 ms (fails before, passes after)</summary> Mutation landed with `scripts/ablation-replace.mjs` (anchor hit 1, blob changed, restored to HEAD blob, `git diff HEAD` empty), on the test-only anchor `getObjectSchema: async () => OBJECT_SCHEMA` replaced by a 300 ms `setTimeout` promise. - Leg A, test as on base 4443014 plus delay: `Tests 2 failed | 12 passed (14)`. `:174 expect(element).toHaveValue(5)` Expected `5 (number)`, Received `5 (string)`, the queue signature exactly; and `:198 toHaveValue(1)` Received `1 (string)`. - Leg B, test at 6dffff8 plus delay: `Test Files 1 passed (1)`, `Tests 14 passed (14)`. </details> <details><summary>Package and neighbours at 6dffff8</summary> - `@object-ui/fields` package (`vitest run --root ../.. packages/fields/`, under os-verify-lock): `Test Files 307 passed | 1 skipped (308)`, `Tests 4651 passed | 7 skipped (4658)`, VERDICT command-exit 0. - The six `FilterConditionField*` files: `Test Files 6 passed (6)`, `Tests 128 passed (128)`. </details> ## Acceptance notes - Same race, other file, not changed here (scope is this file): with the same 300 ms delay, `FilterConditionField.emptyOperators-10790.test.tsx` fails 6 tests (`findByDisplayValue('5')` then an edit expects `"amount":6`, receives `"amount":"6"`), and `FilterConditionField.builderRows-8748.test.tsx` fails 1 (`findAllByRole('combobox')` then `toHaveTextContent('Name')`, receives empty). Both are latent copies of this flake. - Widget behaviour in the pre-schema window: an edit typed into a number bound before `getObjectSchema` answers is emitted untyped (the emptyOperators probe above emits `"amount":"6"`). Measured only through the unit harness; not reached through a running app. - Type check of the test project (`type-check`) and the full UI farm are left to CI (`Type Check UI`, `Test UI`). ## Verification <details><summary>Derived gate families (dispatch-gates --commands, 27 commands)</summary> All 26 non-vitest commands exit 0 at 6dffff8 (one `check:type-check-debt` first run exited 3 while queued behind a held lock; rerun exit 0, `0 raw tsc error(s) total`). `pnpm --dir ui exec vitest run scripts/` (under os-verify-lock): `Test Files 171 passed | 2 skipped (173)`, `Tests 5077 passed | 2 skipped (5079)`, VERDICT command-exit 0. `dispatch-gates --ran`: 27 derived, 27 run, 0 NOT-MEASURED (a derived zero, every line carries its exit code). </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzi3ezPzTysQPDEjmVz)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzi3ezPzTysQPDEjmVz --> Co-authored-by: Claude <noreply@anthropic.com>
1 parent b7edbeb commit d4661df

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)