mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 09:58:04 +08:00
refactor(web): migrate to Vitest and esm (#29974)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
This commit is contained in:
@ -3,7 +3,7 @@ import userEvent from '@testing-library/user-event'
|
||||
import UrlInput from './base/url-input'
|
||||
|
||||
// Mock doc link context
|
||||
jest.mock('@/context/i18n', () => ({
|
||||
vi.mock('@/context/i18n', () => ({
|
||||
useDocLink: () => () => 'https://docs.example.com',
|
||||
}))
|
||||
|
||||
@ -13,13 +13,13 @@ jest.mock('@/context/i18n', () => ({
|
||||
|
||||
describe('UrlInput', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
// Helper to create default props for UrlInput
|
||||
const createUrlInputProps = (overrides: Partial<Parameters<typeof UrlInput>[0]> = {}) => ({
|
||||
isRunning: false,
|
||||
onRun: jest.fn(),
|
||||
onRun: vi.fn(),
|
||||
...overrides,
|
||||
})
|
||||
|
||||
@ -78,7 +78,7 @@ describe('UrlInput', () => {
|
||||
|
||||
it('should show loading state on button when running', () => {
|
||||
// Arrange
|
||||
const onRun = jest.fn()
|
||||
const onRun = vi.fn()
|
||||
const props = createUrlInputProps({ isRunning: true, onRun })
|
||||
|
||||
// Act
|
||||
@ -148,7 +148,7 @@ describe('UrlInput', () => {
|
||||
describe('Button Click', () => {
|
||||
it('should call onRun with URL when button is clicked', async () => {
|
||||
// Arrange
|
||||
const onRun = jest.fn()
|
||||
const onRun = vi.fn()
|
||||
const props = createUrlInputProps({ onRun })
|
||||
|
||||
// Act
|
||||
@ -164,7 +164,7 @@ describe('UrlInput', () => {
|
||||
|
||||
it('should call onRun with empty string if no URL entered', async () => {
|
||||
// Arrange
|
||||
const onRun = jest.fn()
|
||||
const onRun = vi.fn()
|
||||
const props = createUrlInputProps({ onRun })
|
||||
|
||||
// Act
|
||||
@ -177,7 +177,7 @@ describe('UrlInput', () => {
|
||||
|
||||
it('should not call onRun when isRunning is true', async () => {
|
||||
// Arrange
|
||||
const onRun = jest.fn()
|
||||
const onRun = vi.fn()
|
||||
const props = createUrlInputProps({ onRun, isRunning: true })
|
||||
|
||||
// Act
|
||||
@ -191,7 +191,7 @@ describe('UrlInput', () => {
|
||||
|
||||
it('should not call onRun when already running', async () => {
|
||||
// Arrange
|
||||
const onRun = jest.fn()
|
||||
const onRun = vi.fn()
|
||||
|
||||
// First render with isRunning=false, type URL, then rerender with isRunning=true
|
||||
const { rerender } = render(<UrlInput isRunning={false} onRun={onRun} />)
|
||||
@ -211,7 +211,7 @@ describe('UrlInput', () => {
|
||||
|
||||
it('should prevent multiple clicks when already running', async () => {
|
||||
// Arrange
|
||||
const onRun = jest.fn()
|
||||
const onRun = vi.fn()
|
||||
const props = createUrlInputProps({ onRun, isRunning: true })
|
||||
|
||||
// Act
|
||||
@ -250,8 +250,8 @@ describe('UrlInput', () => {
|
||||
|
||||
it('should call updated onRun callback after prop change', async () => {
|
||||
// Arrange
|
||||
const onRun1 = jest.fn()
|
||||
const onRun2 = jest.fn()
|
||||
const onRun1 = vi.fn()
|
||||
const onRun2 = vi.fn()
|
||||
|
||||
// Act
|
||||
const { rerender } = render(<UrlInput isRunning={false} onRun={onRun1} />)
|
||||
@ -363,7 +363,7 @@ describe('UrlInput', () => {
|
||||
|
||||
it('should handle keyboard enter to trigger run', async () => {
|
||||
// Arrange - Note: This tests if the button can be activated via keyboard
|
||||
const onRun = jest.fn()
|
||||
const onRun = vi.fn()
|
||||
const props = createUrlInputProps({ onRun })
|
||||
|
||||
// Act
|
||||
@ -382,7 +382,7 @@ describe('UrlInput', () => {
|
||||
|
||||
it('should handle empty URL submission', async () => {
|
||||
// Arrange
|
||||
const onRun = jest.fn()
|
||||
const onRun = vi.fn()
|
||||
const props = createUrlInputProps({ onRun })
|
||||
|
||||
// Act
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import type { Mock } from 'vitest'
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import JinaReader from './index'
|
||||
@ -6,25 +7,25 @@ import { checkJinaReaderTaskStatus, createJinaReaderTask } from '@/service/datas
|
||||
import { sleep } from '@/utils'
|
||||
|
||||
// Mock external dependencies
|
||||
jest.mock('@/service/datasets', () => ({
|
||||
createJinaReaderTask: jest.fn(),
|
||||
checkJinaReaderTaskStatus: jest.fn(),
|
||||
vi.mock('@/service/datasets', () => ({
|
||||
createJinaReaderTask: vi.fn(),
|
||||
checkJinaReaderTaskStatus: vi.fn(),
|
||||
}))
|
||||
|
||||
jest.mock('@/utils', () => ({
|
||||
sleep: jest.fn(() => Promise.resolve()),
|
||||
vi.mock('@/utils', () => ({
|
||||
sleep: vi.fn(() => Promise.resolve()),
|
||||
}))
|
||||
|
||||
// Mock modal context
|
||||
const mockSetShowAccountSettingModal = jest.fn()
|
||||
jest.mock('@/context/modal-context', () => ({
|
||||
const mockSetShowAccountSettingModal = vi.fn()
|
||||
vi.mock('@/context/modal-context', () => ({
|
||||
useModalContext: () => ({
|
||||
setShowAccountSettingModal: mockSetShowAccountSettingModal,
|
||||
}),
|
||||
}))
|
||||
|
||||
// Mock doc link context
|
||||
jest.mock('@/context/i18n', () => ({
|
||||
vi.mock('@/context/i18n', () => ({
|
||||
useDocLink: () => () => 'https://docs.example.com',
|
||||
}))
|
||||
|
||||
@ -54,12 +55,12 @@ const createCrawlResultItem = (overrides: Partial<CrawlResultItem> = {}): CrawlR
|
||||
})
|
||||
|
||||
const createDefaultProps = (overrides: Partial<Parameters<typeof JinaReader>[0]> = {}) => ({
|
||||
onPreview: jest.fn(),
|
||||
onPreview: vi.fn(),
|
||||
checkedCrawlResult: [] as CrawlResultItem[],
|
||||
onCheckedCrawlResultChange: jest.fn(),
|
||||
onJobIdChange: jest.fn(),
|
||||
onCheckedCrawlResultChange: vi.fn(),
|
||||
onJobIdChange: vi.fn(),
|
||||
crawlOptions: createDefaultCrawlOptions(),
|
||||
onCrawlOptionsChange: jest.fn(),
|
||||
onCrawlOptionsChange: vi.fn(),
|
||||
...overrides,
|
||||
})
|
||||
|
||||
@ -68,7 +69,7 @@ const createDefaultProps = (overrides: Partial<Parameters<typeof JinaReader>[0]>
|
||||
// ============================================================================
|
||||
describe('JinaReader', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('Rendering', () => {
|
||||
@ -158,7 +159,7 @@ describe('JinaReader', () => {
|
||||
it('should call onCrawlOptionsChange when options change', async () => {
|
||||
// Arrange
|
||||
const user = userEvent.setup()
|
||||
const onCrawlOptionsChange = jest.fn()
|
||||
const onCrawlOptionsChange = vi.fn()
|
||||
const props = createDefaultProps({ onCrawlOptionsChange })
|
||||
|
||||
// Act
|
||||
@ -188,7 +189,7 @@ describe('JinaReader', () => {
|
||||
it('should execute crawl task when checkedCrawlResult is provided', async () => {
|
||||
// Arrange
|
||||
const checkedItem = createCrawlResultItem({ source_url: 'https://checked.com' })
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: {
|
||||
title: 'Test',
|
||||
@ -234,7 +235,7 @@ describe('JinaReader', () => {
|
||||
describe('State Management', () => {
|
||||
it('should transition from init to running state when run is clicked', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
let resolvePromise: () => void
|
||||
mockCreateTask.mockImplementation(() => new Promise((resolve) => {
|
||||
resolvePromise = () => resolve({ data: { title: 'T', content: 'C', description: 'D', url: 'https://example.com' } })
|
||||
@ -262,7 +263,7 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should transition to finished state after successful crawl', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: {
|
||||
title: 'Test Page',
|
||||
@ -288,8 +289,8 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should update crawl result state during polling', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'test-job-123' })
|
||||
mockCheckStatus
|
||||
@ -310,8 +311,8 @@ describe('JinaReader', () => {
|
||||
],
|
||||
})
|
||||
|
||||
const onCheckedCrawlResultChange = jest.fn()
|
||||
const onJobIdChange = jest.fn()
|
||||
const onCheckedCrawlResultChange = vi.fn()
|
||||
const onJobIdChange = vi.fn()
|
||||
const props = createDefaultProps({ onCheckedCrawlResultChange, onJobIdChange })
|
||||
|
||||
// Act
|
||||
@ -332,7 +333,7 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should fold options when step changes from init', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: {
|
||||
title: 'Test',
|
||||
@ -367,9 +368,9 @@ describe('JinaReader', () => {
|
||||
describe('Side Effects and Cleanup', () => {
|
||||
it('should call sleep during polling', async () => {
|
||||
// Arrange
|
||||
const mockSleep = sleep as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const mockSleep = sleep as Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'test-job' })
|
||||
mockCheckStatus
|
||||
@ -392,7 +393,7 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should update controlFoldOptions when step changes', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
mockCreateTask.mockImplementation(() => new Promise((_resolve) => { /* pending */ }))
|
||||
|
||||
const props = createDefaultProps()
|
||||
@ -439,7 +440,7 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should memoize checkValid callback based on crawlOptions', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
mockCreateTask.mockResolvedValue({ data: { title: 'T', content: 'C', description: 'D', url: 'https://a.com' } })
|
||||
|
||||
const props = createDefaultProps()
|
||||
@ -483,7 +484,7 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle URL input and run button click', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: {
|
||||
title: 'Test',
|
||||
@ -512,8 +513,8 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle preview action on crawled result', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const onPreview = jest.fn()
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const onPreview = vi.fn()
|
||||
const crawlResultData = {
|
||||
title: 'Preview Test',
|
||||
content: '# Content',
|
||||
@ -545,7 +546,7 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle checkbox changes in options', async () => {
|
||||
// Arrange
|
||||
const onCrawlOptionsChange = jest.fn()
|
||||
const onCrawlOptionsChange = vi.fn()
|
||||
const props = createDefaultProps({
|
||||
onCrawlOptionsChange,
|
||||
crawlOptions: createDefaultCrawlOptions({ crawl_sub_pages: false }),
|
||||
@ -593,7 +594,7 @@ describe('JinaReader', () => {
|
||||
describe('API Calls', () => {
|
||||
it('should call createJinaReaderTask with correct parameters', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: { title: 'T', content: 'C', description: 'D', url: 'https://api-test.com' },
|
||||
})
|
||||
@ -618,8 +619,8 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle direct data response from API', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const onCheckedCrawlResultChange = jest.fn()
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const onCheckedCrawlResultChange = vi.fn()
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: {
|
||||
@ -651,9 +652,9 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle job_id response and poll for status', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const onJobIdChange = jest.fn()
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
const onJobIdChange = vi.fn()
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'poll-job-123' })
|
||||
mockCheckStatus.mockResolvedValueOnce({
|
||||
@ -686,8 +687,8 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle failed status from polling', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'fail-job' })
|
||||
mockCheckStatus.mockResolvedValueOnce({
|
||||
@ -713,8 +714,8 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle API error during status check', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'error-job' })
|
||||
mockCheckStatus.mockRejectedValueOnce({
|
||||
@ -737,9 +738,9 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should limit total to crawlOptions.limit', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const onCheckedCrawlResultChange = jest.fn()
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
const onCheckedCrawlResultChange = vi.fn()
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'limit-job' })
|
||||
mockCheckStatus.mockResolvedValueOnce({
|
||||
@ -832,7 +833,7 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should accept URL with http:// protocol', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: { title: 'T', content: 'C', description: 'D', url: 'http://example.com' },
|
||||
})
|
||||
@ -907,10 +908,10 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle API throwing an exception', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
mockCreateTask.mockRejectedValueOnce(new Error('Network error'))
|
||||
// Suppress console output during test to avoid noisy logs
|
||||
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(jest.fn())
|
||||
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(vi.fn())
|
||||
|
||||
const props = createDefaultProps()
|
||||
|
||||
@ -930,8 +931,8 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle status response without status field', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'no-status-job' })
|
||||
mockCheckStatus.mockResolvedValueOnce({
|
||||
@ -955,8 +956,8 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should show unknown error when error message is empty', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'empty-error-job' })
|
||||
mockCheckStatus.mockResolvedValueOnce({
|
||||
@ -980,9 +981,9 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle empty data array from API', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const onCheckedCrawlResultChange = jest.fn()
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
const onCheckedCrawlResultChange = vi.fn()
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'empty-data-job' })
|
||||
mockCheckStatus.mockResolvedValueOnce({
|
||||
@ -1008,9 +1009,9 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle null data from running status', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const onCheckedCrawlResultChange = jest.fn()
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
const onCheckedCrawlResultChange = vi.fn()
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'null-data-job' })
|
||||
mockCheckStatus
|
||||
@ -1043,9 +1044,9 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should return empty array when completed job has undefined data', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const onCheckedCrawlResultChange = jest.fn()
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
const onCheckedCrawlResultChange = vi.fn()
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'undefined-data-job' })
|
||||
mockCheckStatus.mockResolvedValueOnce({
|
||||
@ -1071,8 +1072,8 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should show zero current progress when crawlResult is not yet available', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'zero-current-job' })
|
||||
mockCheckStatus.mockImplementation(() => new Promise(() => { /* never resolves */ }))
|
||||
@ -1095,8 +1096,8 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should show 0/0 progress when limit is zero string', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'zero-total-job' })
|
||||
mockCheckStatus.mockImplementation(() => new Promise(() => { /* never resolves */ }))
|
||||
@ -1119,9 +1120,9 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should complete successfully when result data is undefined', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const onCheckedCrawlResultChange = jest.fn()
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
const onCheckedCrawlResultChange = vi.fn()
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'undefined-result-data-job' })
|
||||
mockCheckStatus.mockResolvedValueOnce({
|
||||
@ -1148,8 +1149,8 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should use limit as total when crawlResult total is not available', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'no-total-job' })
|
||||
mockCheckStatus.mockImplementation(() => new Promise(() => { /* never resolves */ }))
|
||||
@ -1172,8 +1173,8 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should fallback to limit when crawlResult has zero total', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'both-zero-job' })
|
||||
mockCheckStatus
|
||||
@ -1203,8 +1204,8 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should construct result item from direct data response', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const onCheckedCrawlResultChange = jest.fn()
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const onCheckedCrawlResultChange = vi.fn()
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: {
|
||||
@ -1241,7 +1242,7 @@ describe('JinaReader', () => {
|
||||
describe('Prop Variations', () => {
|
||||
it('should handle different limit values in crawlOptions', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: { title: 'T', content: 'C', description: 'D', url: 'https://limit.com' },
|
||||
})
|
||||
@ -1268,7 +1269,7 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle different max_depth values', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: { title: 'T', content: 'C', description: 'D', url: 'https://depth.com' },
|
||||
})
|
||||
@ -1295,7 +1296,7 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle crawl_sub_pages disabled', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: { title: 'T', content: 'C', description: 'D', url: 'https://nosub.com' },
|
||||
})
|
||||
@ -1322,7 +1323,7 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle use_sitemap enabled', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: { title: 'T', content: 'C', description: 'D', url: 'https://sitemap.com' },
|
||||
})
|
||||
@ -1349,7 +1350,7 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle includes and excludes patterns', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: { title: 'T', content: 'C', description: 'D', url: 'https://patterns.com' },
|
||||
})
|
||||
@ -1382,7 +1383,7 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle pre-selected crawl results', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const existingResult = createCrawlResultItem({ source_url: 'https://existing.com' })
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
@ -1407,7 +1408,7 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle string type limit value', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: { title: 'T', content: 'C', description: 'D', url: 'https://string-limit.com' },
|
||||
})
|
||||
@ -1435,8 +1436,8 @@ describe('JinaReader', () => {
|
||||
describe('Display and UI States', () => {
|
||||
it('should show crawling progress during running state', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'progress-job' })
|
||||
mockCheckStatus.mockImplementation(() => new Promise((_resolve) => { /* pending */ })) // Never resolves
|
||||
@ -1459,7 +1460,7 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should display time consumed after crawl completion', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: { title: 'T', content: 'C', description: 'D', url: 'https://time.com' },
|
||||
@ -1481,7 +1482,7 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should display crawled results list after completion', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: {
|
||||
@ -1508,11 +1509,11 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should show error message component when crawl fails', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
|
||||
mockCreateTask.mockRejectedValueOnce(new Error('Failed'))
|
||||
// Suppress console output during test to avoid noisy logs
|
||||
jest.spyOn(console, 'log').mockImplementation(jest.fn())
|
||||
vi.spyOn(console, 'log').mockImplementation(vi.fn())
|
||||
|
||||
const props = createDefaultProps()
|
||||
|
||||
@ -1535,11 +1536,11 @@ describe('JinaReader', () => {
|
||||
describe('Integration', () => {
|
||||
it('should complete full crawl workflow with job polling', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as jest.Mock
|
||||
const onCheckedCrawlResultChange = jest.fn()
|
||||
const onJobIdChange = jest.fn()
|
||||
const onPreview = jest.fn()
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const mockCheckStatus = checkJinaReaderTaskStatus as Mock
|
||||
const onCheckedCrawlResultChange = vi.fn()
|
||||
const onJobIdChange = vi.fn()
|
||||
const onPreview = vi.fn()
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({ job_id: 'full-workflow-job' })
|
||||
mockCheckStatus
|
||||
@ -1600,8 +1601,8 @@ describe('JinaReader', () => {
|
||||
|
||||
it('should handle select all and deselect all in results', async () => {
|
||||
// Arrange
|
||||
const mockCreateTask = createJinaReaderTask as jest.Mock
|
||||
const onCheckedCrawlResultChange = jest.fn()
|
||||
const mockCreateTask = createJinaReaderTask as Mock
|
||||
const onCheckedCrawlResultChange = vi.fn()
|
||||
|
||||
mockCreateTask.mockResolvedValueOnce({
|
||||
data: { title: 'Single', content: 'C', description: 'D', url: 'https://single.com' },
|
||||
|
||||
Reference in New Issue
Block a user