Fixing flaky domain search test.

This commit is contained in:
Roland 2026-05-31 13:09:20 -06:00
parent 345b69b7d7
commit 5497e1eb61
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
2 changed files with 13 additions and 8 deletions

View file

@ -124,7 +124,12 @@ describe('Domains List Page', () => {
});
it('filters domains with search', () => {
cy.get('input[placeholder="Domain filter..."]').type('example');
cy.get('input[placeholder="Domain filter..."]')
.type('example')
// Confirm the input itself stabilized before asserting downstream effects.
.should('have.value', 'example');
// The filter is driven by the URL query param; wait for the router to commit it.
cy.url().should('include', 'domain=example');
// Chain assertions so they retry together with the extended timeout
cy.get('table:visible tbody tr', {timeout: 10000})
.should('have.length', 1)

View file

@ -435,14 +435,14 @@ const useClearableInput = (searchStr, onChange, onClear, onSubmit, size = 'small
const [submitted, setSubmitted] = useState(false);
React.useEffect(() => {
// Search was changed above.
if (searchStr !== value) {
setValue(searchStr);
// `searchStr` is the source of truth from the parent (often an async URL query param).
// Depend ONLY on `searchStr` -- never on `value` -- otherwise a transient render where the
// local `value` has advanced (e.g. "ex") but `searchStr` still trails ("e") fires this
// effect and reverts `value`, garbling fast typing (flaky filter test).
if ((searchStr || '') !== value) {
setValue(searchStr || '');
}
if (!searchStr) {
setValue('');
}
}, [searchStr, value]);
}, [searchStr]);
const handleChange = (e) => {
if (e) {