Skip to content

Commit affdb0b

Browse files
committed
test(web): stabilize app flow tests
1 parent 376e13f commit affdb0b

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

web/__tests__/apps/app-card-operations-flow.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ vi.mock('@/next/navigation', () => ({
5353
}),
5454
}))
5555

56+
vi.mock('@tanstack/react-query', async (importOriginal) => {
57+
const actual = await importOriginal<typeof import('@tanstack/react-query')>()
58+
return {
59+
...actual,
60+
useQuery: () => ({
61+
data: [],
62+
}),
63+
}
64+
})
65+
5666
// Mock headless UI Popover so it renders content without transition
5767
vi.mock('@headlessui/react', async () => {
5868
const actual = await vi.importActual<typeof import('@headlessui/react')>('@headlessui/react')

web/__tests__/apps/app-list-browsing-flow.test.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { ReactElement, ReactNode } from 'react'
99
*/
1010
import type { AppListResponse } from '@/models/app'
1111
import type { App } from '@/types/app'
12-
import { fireEvent, render, screen } from '@testing-library/react'
12+
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
1313
import { beforeEach, describe, expect, it, vi } from 'vitest'
1414
import { createSystemFeaturesWrapper } from '@/__tests__/utils/mock-system-features'
1515
import List from '@/app/components/apps/list'
@@ -92,6 +92,9 @@ vi.mock('@tanstack/react-query', async (importOriginal) => {
9292
const actual = await importOriginal<typeof import('@tanstack/react-query')>()
9393
return {
9494
...actual,
95+
useQuery: () => ({
96+
data: [],
97+
}),
9598
useInfiniteQuery: () => ({
9699
data: { pages: mockPages },
97100
isLoading: mockIsLoading,
@@ -360,13 +363,18 @@ describe('App List Browsing Flow', () => {
360363
expect(input).toBeInTheDocument()
361364
})
362365

363-
it('should allow typing in search input', () => {
366+
it('should update search query when typing in search input', async () => {
364367
mockPages = [createPage([createMockApp()])]
365-
renderList()
368+
const { onUrlUpdate } = renderList()
366369

367-
const input = document.querySelector('input')!
370+
const input = screen.getByPlaceholderText('common.operation.search')
368371
fireEvent.change(input, { target: { value: 'test search' } })
369-
expect(input.value).toBe('test search')
372+
373+
await waitFor(() => {
374+
expect(onUrlUpdate).toHaveBeenCalled()
375+
})
376+
const lastCall = onUrlUpdate.mock.calls[onUrlUpdate.mock.calls.length - 1]![0]
377+
expect(lastCall.searchParams.get('keywords')).toBe('test search')
370378
})
371379
})
372380

0 commit comments

Comments
 (0)