test: Stabilize user select email-filtering tests (#41095)

Co-authored-by: n8n-cat-bot[bot] <n8n-cat-bot[bot]@users.noreply.github.com>
This commit is contained in:
n8n-cat-bot[bot] 2026-10-14 13:17:45 +00:00 committed by GitHub
parent ae374e79ab
commit 9c42a76b1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,7 +15,8 @@ const getRenderedOptions = async () => {
const filterInput = async (filterText: string) => {
const input = screen.getByRole('combobox');
await userEvent.type(input, filterText);
// Avoid a timer wait for each character on busy CI workers.
await userEvent.type(input, filterText, { delay: null });
};
const sampleUsers: IUser[] = [
@ -171,6 +172,56 @@ describe('UserSelect', () => {
});
});
it.each([0, 100])('finishes email checks with %i ms timer latency', async (latency) => {
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date'] });
const scheduleTimeout = globalThis.setTimeout;
// DEVP-1283: Model a busy CI worker without a wall-clock delay.
vi.stubGlobal(
'setTimeout',
(handler: (...args: unknown[]) => void, delay?: number, ...args: unknown[]) =>
scheduleTimeout(handler, Math.max(delay ?? 0, latency), ...args),
);
const { unmount } = renderComponent({ props: { users: sampleUsers } });
const runInteraction = async (interaction: Promise<unknown>) => {
let settled = false;
const completion = interaction.finally(() => {
settled = true;
});
while (!settled) {
await vi.advanceTimersToNextTimerAsync();
}
await completion;
};
try {
const startedAt = Date.now();
await runInteraction(filterInput('alice@example.com'));
const aliceOptions = await getRenderedOptions();
expect(aliceOptions).toHaveLength(1);
expect(aliceOptions[0]).toHaveAttribute('id', 'user-select-option-id-u1');
await runInteraction(userEvent.click(document.body));
await runInteraction(filterInput('Example.com'));
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
await runInteraction(userEvent.click(document.body));
await runInteraction(filterInput('example.com'));
expect(await getRenderedOptions()).toHaveLength(sampleUsers.length);
// All three searches share the default Vitest test timeout.
expect(Date.now() - startedAt).toBeLessThan(5000);
} finally {
try {
unmount();
await vi.runAllTimersAsync();
} finally {
vi.unstubAllGlobals();
vi.useRealTimers();
}
}
});
it('filters by full name and email and sorts by last name', async () => {
const specificUsers: IUser[] = [
{