Skip to content

Commit 36d46b5

Browse files
test(fields): wait for the schema-typed render in the emptyOperators and builderRows FilterConditionField tests (#35063)
🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WGufzi3ezPzTysQPDEjmVz Fixes #34991 repo:objectstack#3 · os-support-ai · session_01WGufzi3ezPzTysQPDEjmVz Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:只改两个测试文件(`FilterConditionField.emptyOperators-10790` 与 `FilterConditionField.builderRows-8748`),让断言等到 schema 返回后的带类型渲染再执行。接续 #35055(同一张卡的第一个 PR,修了 betweenBlankBound 文件)。 - 为什么改:控件先用已保存的条件画出行,字段类型和字段标签要等异步 `getObjectSchema` 返回才生效。原测试 `findBy` 拿到第一次渲染就断言:数字框还是文本框时编辑会发出字符串 "6",字段下拉还没有标签 "Name"。慢机上与 schema 赛跑,和 #35055 是同一个队列误踢根因。 - 风险与回滚:零产品风险,不改任何发布代码;回滚即还原这两个测试文件。断言没有放宽,仍要求数字 6 和标签 Name。 - 先看:`FilterConditionField.emptyOperators-10790.test.tsx` 的 `findTypedAmountBox`;`FilterConditionField.builderRows-8748.test.tsx` 的 `waitFor` 标签等待。 - 两分钟验证:把任一文件的 `getObjectSchema` 改为延迟 300ms 返回再跑该文件,预期全部通过(修复前 emptyOperators 红 6 个、builderRows 红 1 个)。 - 需要你做的:无,席位落地。 ## What changes Follows #35055, which fixed the same render race in `FilterConditionField.betweenBlankBound-9914.test.tsx` and lands as `Part of #34991`. That PR's 300 ms schema-delay reproduction found two sibling files with the same race; this PR fixes them and closes the card. - `FilterConditionField.emptyOperators-10790.test.tsx`: three `findByDisplayValue('5')` sites (the four RE-SAVE cases and the two OR-group cases) are replaced by `findTypedAmountBox()`, which waits for the typed number box (`findByRole('spinbutton')`) and asserts `toHaveValue(5)` before the edit. The emitted `"amount":6` assertions are unchanged; the string `"6"` is not accepted. - `FilterConditionField.builderRows-8748.test.tsx`: the seeded-row test waits for the field trigger to read its label (`waitFor` on `toHaveTextContent('Name')`) before taking the triggers. A combobox takes no accessible name from its content, so `findByRole('combobox', { name: 'Name' })` cannot spell it (measured: it fails even with no delay). No skip, retry or quarantine. Test-only, so no changeset (`skip-changeset`). ## Tests <details><summary>Reproduction: schema resolution delayed 300 ms, before and after, per file</summary> Each mutation was applied by `scripts/ablation-replace.mjs` (anchor `getObjectSchema: async () => OBJECT_SCHEMA,` hit once) and restored to the HEAD blob with `git diff HEAD` empty. Leg A uses the file as on base 743308b; leg B uses 52bace8. | File | Leg A, base plus delay | Leg B, fix plus delay | |---|---|---| | emptyOperators-10790 | Tests 6 failed, 30 passed (36) | Tests 36 passed (36) | | builderRows-8748 | Tests 1 failed, 3 passed (4) | Tests 4 passed (4) | </details> <details><summary>Neighbours and package at 52bace8</summary> - The six `FilterConditionField*` files: `Test Files 6 passed (6)`, `Tests 128 passed (128)`. - The `@object-ui/fields` package (run under os-verify-lock): `Test Files 307 passed | 1 skipped (308)`, `Tests 4651 passed | 7 skipped (4658)`, VERDICT command-exit 0. </details> ## Acceptance notes - The untyped emit before the schema answers is a widget question and is out of scope here. It is being carded separately. - Type check of the test project and the full UI suite are left to CI (`Type Check UI`, `Test UI`). ## Verification <details><summary>Derived gate families (dispatch-gates --commands, 27 commands)</summary> All 27 commands exit 0 at 52bace8, including `pnpm --dir ui exec vitest run scripts/`: `Test Files 171 passed | 2 skipped (173)`, `Tests 5077 passed | 2 skipped (5079)`. `dispatch-gates --ran`: 27 derived, 27 run, 0 NOT-MEASURED, a derived zero. overlap-check: VERDICT clean exit 0. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzi3ezPzTysQPDEjmVz)_ Governing claim for this branch: 6965814231 on #34991. <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzi3ezPzTysQPDEjmVz --> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6328877 commit 36d46b5

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎ui/packages/fields/src/widgets/__tests__/FilterConditionField.builderRows-8748.test.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,13 @@ describe('a stored criteria still seeds the rows', () => {
158158
it('loads `{ name: { $icontains: "x" } }` into a row and emits nothing on its own', async () => {
159159
const { onChange } = renderWidget('{"name":{"$icontains":"x"}}');
160160

161-
const triggers = await screen.findAllByRole('combobox');
161+
// The row is seeded before `getObjectSchema` resolves, and its field
162+
// trigger reads the column's LABEL only once the schema answers: wait for
163+
// that labelled render, never for whichever trigger is drawn first. (A
164+
// combobox takes no accessible name from its content, so `findByRole` with
165+
// `name` cannot spell this.)
166+
await waitFor(() => expect(screen.getAllByRole('combobox')[0]).toHaveTextContent('Name'));
167+
const triggers = screen.getAllByRole('combobox');
162168
expect(triggers).toHaveLength(2);
163169
expect(triggers[0]).toHaveTextContent('Name');
164170
expect(triggers[1]).toHaveTextContent('Contains (ignore case)');

‎ui/packages/fields/src/widgets/__tests__/FilterConditionField.emptyOperators-10790.test.tsx‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ async function addRow() {
138138
fireEvent.click(add);
139139
}
140140

141+
/**
142+
* The `amount` comparand box once the object schema has typed its column.
143+
*
144+
* A stored criteria seeds its rows before `getObjectSchema` resolves, and until
145+
* then `amount` is untyped: its box is a text input and an edit is emitted as
146+
* the string `"6"`. A number input's role is `spinbutton`, so waiting for that
147+
* role waits for the typed render, not for whichever box is drawn first.
148+
*/
149+
async function findTypedAmountBox() {
150+
const box = await screen.findByRole('spinbutton');
151+
expect(box).toHaveValue(5);
152+
return box;
153+
}
154+
141155
/** Drive a REAL Radix dropdown by its trigger's index in the document. */
142156
async function pickFrom(index: number, label: string) {
143157
const triggers = screen.getAllByRole('combobox');
@@ -262,7 +276,7 @@ describe('RE-SAVE — a legacy rule is written as `$empty` once it is edited (ob
262276
{ name: 'objectui#10790 "is not empty"', old: legacyIsNotEmpty('name'), fresh: isNotEmpty('name') },
263277
])('a $name row is rewritten when ANOTHER row is edited', async ({ old, fresh }) => {
264278
const { onChange } = renderWidget(JSON.stringify({ ...old, amount: 5 }));
265-
const box = await screen.findByDisplayValue('5');
279+
const box = await findTypedAmountBox();
266280
expect(onChange).not.toHaveBeenCalled();
267281
fireEvent.change(box, { target: { value: '6' } });
268282
const stored = lastEmitted(onChange);
@@ -315,7 +329,7 @@ describe('GROUPS — the "is empty" row round-trips inside a group (objectui#108
315329
const stored = { $or: [{ amount: 5 }, isEmpty('name')] };
316330
expectAcceptedByTheFaces(JSON.stringify(stored));
317331
const { onChange } = renderWidget(JSON.stringify(stored));
318-
const box = await screen.findByDisplayValue('5');
332+
const box = await findTypedAmountBox();
319333
expect(screen.getAllByRole('combobox').map((t) => t.textContent)).toEqual([
320334
'Amount', 'Equals', 'Name', 'Is empty',
321335
]);
@@ -326,7 +340,7 @@ describe('GROUPS — the "is empty" row round-trips inside a group (objectui#108
326340
it('a legacy entry inside an OR group is re-written as `$empty` once the group is edited', async () => {
327341
const stored = { $or: [{ amount: 5 }, legacyIsEmpty('name')] };
328342
const { onChange } = renderWidget(JSON.stringify(stored));
329-
const box = await screen.findByDisplayValue('5');
343+
const box = await findTypedAmountBox();
330344
expect(onChange).not.toHaveBeenCalled();
331345
fireEvent.change(box, { target: { value: '6' } });
332346
expect(lastEmitted(onChange)).toBe(JSON.stringify({ $or: [{ amount: 6 }, isEmpty('name')] }));

0 commit comments

Comments
 (0)