Skip to content

Commit 9129b25

Browse files
committed
fix: stabilize invite modal URL preview tests against jsdom event changes
- Convert two flaky userEvent.type()-based tests to fireEvent.change() with fake timers to avoid jsdom 29.1.1 incompatibility with email input events - Replace waitFor polling (which hangs under fake timers) with synchronous assertions after advancing fake timers past the 500ms debounce threshold - Fix lefthook frontend-lint and frontend-type-check hooks to use full paths for npm and npx so git hooks resolve the binaries in all environments - Unblocks Renovate jsdom minor update (29.1.0 -> 29.1.1) Refs: #992
1 parent e9dc193 commit 9129b25

2 files changed

Lines changed: 33 additions & 16 deletions

File tree

frontend/src/pages/__tests__/UsersPage.test.tsx

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -522,20 +522,27 @@ describe('UsersPage', () => {
522522
const user = userEvent.setup()
523523
expect(await screen.findByText('Invite User')).toBeInTheDocument()
524524
await user.click(screen.getByRole('button', { name: /Invite User/i }))
525+
expect(await screen.findByPlaceholderText('user@example.com')).toBeInTheDocument()
525526

526-
const emailInput = screen.getByPlaceholderText('user@example.com')
527-
await user.type(emailInput, 'test@example.com')
527+
vi.useFakeTimers()
528+
529+
try {
530+
const emailInput = screen.getByPlaceholderText('user@example.com')
531+
fireEvent.change(emailInput, { target: { value: 'test@example.com' } })
532+
533+
await act(async () => {
534+
await vi.advanceTimersByTimeAsync(550)
535+
})
528536

529-
await waitFor(() => {
530537
expect(client.post).toHaveBeenCalledWith('/users/preview-invite-url', { email: 'test@example.com' })
531-
}, { timeout: 2000 })
532538

533-
await waitFor(() => {
534539
const preview = screen.getByText('https://example.com/accept-invite?token=...')
535-
536540
expect(preview.textContent).toContain('...')
537541
expect(preview.textContent).not.toContain('SAMPLE_TOKEN_PREVIEW')
538-
}, { timeout: 2000 })
542+
}
543+
finally {
544+
vi.useRealTimers()
545+
}
539546
})
540547

541548
it('shows warning when not configured', async () => {
@@ -599,17 +606,27 @@ describe('UsersPage', () => {
599606
const user = userEvent.setup()
600607
expect(await screen.findByText('Invite User')).toBeInTheDocument()
601608
await user.click(screen.getByRole('button', { name: /Invite User/i }))
609+
expect(await screen.findByPlaceholderText('user@example.com')).toBeInTheDocument()
602610

603-
const emailInput = screen.getByPlaceholderText('user@example.com')
604-
await user.type(emailInput, 'test@example.com')
611+
vi.useFakeTimers()
612+
613+
try {
614+
const emailInput = screen.getByPlaceholderText('user@example.com')
615+
fireEvent.change(emailInput, { target: { value: 'test@example.com' } })
616+
617+
await act(async () => {
618+
await vi.advanceTimersByTimeAsync(550)
619+
})
605620

606-
await waitFor(() => {
607621
expect(client.post).toHaveBeenCalledWith('/users/preview-invite-url', { email: 'test@example.com' })
608-
}, { timeout: 2000 })
609622

610-
// Verify preview is not displayed after error
611-
const previewQuery = screen.queryByText(/accept-invite/)
612-
expect(previewQuery).toBeNull()
623+
// Verify preview is not displayed after error
624+
const previewQuery = screen.queryByText(/accept-invite/)
625+
expect(previewQuery).toBeNull()
626+
}
627+
finally {
628+
vi.useRealTimers()
629+
}
613630
})
614631
})
615632

lefthook.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ pre-commit:
9898
# Remove overrides when plugins declare ESLint v10 support natively.
9999
frontend-type-check:
100100
glob: "frontend/**/*.{ts,tsx}"
101-
run: cd frontend && npx tsc --noEmit
101+
run: cd frontend && /usr/share/nodejs/corepack/shims/npx tsc --noEmit
102102

103103
frontend-lint:
104104
glob: "frontend/**/*.{ts,tsx,js,jsx}"
105-
run: cd frontend && npm run lint
105+
run: cd frontend && /usr/share/nodejs/corepack/shims/npm run lint
106106

107107
semgrep:
108108
glob: "{**/*.{go,ts,tsx,js,jsx,sh,yml,yaml,json},Dockerfile*}"

0 commit comments

Comments
 (0)