-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuseImportModel.test.ts
70 lines (52 loc) · 1.92 KB
/
useImportModel.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// useImportModel.test.ts
import { renderHook, act } from '@testing-library/react'
import { extensionManager } from '@/extension'
import useImportModel from './useImportModel'
// Mock dependencies
jest.mock('@janhq/core')
jest.mock('@/extension')
jest.mock('@/containers/Toast')
jest.mock('uuid', () => ({ v4: () => 'mocked-uuid' }))
describe('useImportModel', () => {
beforeEach(() => {
jest.clearAllMocks()
})
it('should import models successfully', async () => {
const mockImportModels = jest.fn().mockResolvedValue(undefined)
const mockExtension = {
importModels: mockImportModels,
} as any
jest.spyOn(extensionManager, 'get').mockReturnValue(mockExtension)
const { result } = renderHook(() => useImportModel())
const models = [
{ importId: '1', name: 'Model 1', path: '/path/to/model1' },
{ importId: '2', name: 'Model 2', path: '/path/to/model2' },
] as any
await act(async () => {
await result.current.importModels(models, 'local' as any)
})
expect(mockImportModels).toHaveBeenCalledWith(models, 'local')
})
it('should update model info successfully', async () => {
const mockUpdateModelInfo = jest
.fn()
.mockResolvedValue({ id: 'model-1', name: 'Updated Model' })
const mockExtension = {
updateModelInfo: mockUpdateModelInfo,
} as any
jest.spyOn(extensionManager, 'get').mockReturnValue(mockExtension)
const { result } = renderHook(() => useImportModel())
const modelInfo = { id: 'model-1', name: 'Updated Model' }
await act(async () => {
await result.current.updateModelInfo(modelInfo)
})
expect(mockUpdateModelInfo).toHaveBeenCalledWith(modelInfo)
})
it('should handle empty file paths', async () => {
const { result } = renderHook(() => useImportModel())
await act(async () => {
await result.current.sanitizeFilePaths([])
})
// Expect no state changes or side effects
})
})