fix: mock system api in layout tests to prevent network crashes

- Mocked `getNotifications` and `checkUpdates` in `Layout.test.tsx`
- Prevents `UND_ERR_INVALID_ARG` errors caused by unmocked `undici` network requests in JSDOM
- Ensures clean test execution for `Layout` and child components
This commit is contained in:
GitHub Actions
2026-02-09 07:28:16 +00:00
parent 376f9d3e34
commit dc505b2789
6 changed files with 40 additions and 15 deletions
@@ -32,6 +32,14 @@ vi.mock('../../api/featureFlags', () => ({
}),
}))
// Mock System API to prevent unhandled network requests
vi.mock('../../api/system', () => ({
getNotifications: vi.fn().mockResolvedValue([]),
markNotificationRead: vi.fn(),
markAllNotificationsRead: vi.fn(),
checkUpdates: vi.fn().mockResolvedValue({ available: false }),
}))
const renderWithProviders = (children: ReactNode) => {
const queryClient = new QueryClient({
defaultOptions: {
@@ -362,6 +362,10 @@ describe('UsersPage', () => {
})
describe('URL Preview in InviteModal', () => {
afterEach(() => {
vi.useRealTimers()
})
it('shows URL preview when valid email is entered', async () => {
vi.mocked(usersApi.listUsers).mockResolvedValue(mockUsers)
vi.mocked(client.post).mockResolvedValue({
@@ -406,19 +410,23 @@ describe('UsersPage', () => {
})
renderWithQueryClient(<UsersPage />)
const user = userEvent.setup()
await waitFor(() => expect(screen.getByText('Invite User')).toBeInTheDocument())
await user.click(screen.getByRole('button', { name: /Invite User/i }))
await waitFor(() => expect(screen.getByPlaceholderText('user@example.com')).toBeInTheDocument())
vi.useFakeTimers()
const openUser = userEvent.setup({ advanceTimers: vi.advanceTimersByTime })
await openUser.click(screen.getByRole('button', { name: /Invite User/i }))
try {
const emailInput = screen.getByPlaceholderText('user@example.com')
fireEvent.change(emailInput, { target: { value: 'test@example.com' } })
// Verify not called immediately
expect(client.post).not.toHaveBeenCalled()
await act(async () => {
await vi.advanceTimersByTimeAsync(500)
await vi.advanceTimersByTimeAsync(550)
})
expect(client.post).toHaveBeenCalledTimes(1)