fix: openrouter unselect itself (#5943)
* fix: selected openrouter model does not work * test: add tests to cover new change
This commit is contained in:
parent
08af8a49aa
commit
fdaa3b1992
@ -11,15 +11,22 @@ vi.mock('@/services/threads', () => ({
|
|||||||
|
|
||||||
// Mock ulid
|
// Mock ulid
|
||||||
vi.mock('ulidx', () => ({
|
vi.mock('ulidx', () => ({
|
||||||
ulid: vi.fn(() => 'test-ulid-123')
|
ulid: vi.fn(() => 'test-ulid-123'),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Mock fzf
|
// Mock fzf
|
||||||
vi.mock('fzf', () => ({
|
vi.mock('fzf', () => ({
|
||||||
Fzf: vi.fn(() => ({
|
Fzf: vi.fn(() => ({
|
||||||
find: vi.fn(() => [])
|
find: vi.fn(() => []),
|
||||||
}))
|
})),
|
||||||
}))
|
}))
|
||||||
|
global.__TAURI_INTERNALS__ = {
|
||||||
|
plugins: {
|
||||||
|
path: {
|
||||||
|
sep: '/',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
describe('useThreads', () => {
|
describe('useThreads', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -29,7 +36,7 @@ describe('useThreads', () => {
|
|||||||
useThreads.setState({
|
useThreads.setState({
|
||||||
threads: {},
|
threads: {},
|
||||||
currentThreadId: undefined,
|
currentThreadId: undefined,
|
||||||
searchIndex: null
|
searchIndex: null,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -47,7 +54,7 @@ describe('useThreads', () => {
|
|||||||
|
|
||||||
const threads = [
|
const threads = [
|
||||||
{ id: 'thread1', title: 'Thread 1', messages: [] },
|
{ id: 'thread1', title: 'Thread 1', messages: [] },
|
||||||
{ id: 'thread2', title: 'Thread 2', messages: [] }
|
{ id: 'thread2', title: 'Thread 2', messages: [] },
|
||||||
]
|
]
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
@ -58,6 +65,34 @@ describe('useThreads', () => {
|
|||||||
expect(result.current.threads['thread1']).toEqual(threads[0])
|
expect(result.current.threads['thread1']).toEqual(threads[0])
|
||||||
expect(result.current.threads['thread2']).toEqual(threads[1])
|
expect(result.current.threads['thread2']).toEqual(threads[1])
|
||||||
})
|
})
|
||||||
|
it('should set threads with cortex model migrated', () => {
|
||||||
|
const { result } = renderHook(() => useThreads())
|
||||||
|
|
||||||
|
const threads = [
|
||||||
|
{
|
||||||
|
id: 'thread1',
|
||||||
|
title: 'Thread 1',
|
||||||
|
messages: [],
|
||||||
|
model: { provider: 'llama.cpp', id: 'thread1:free' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'thread2',
|
||||||
|
title: 'Thread 2',
|
||||||
|
messages: [],
|
||||||
|
model: { provider: 'llama.cpp', id: 'thread2:test' },
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
result.current.setThreads(threads)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(Object.keys(result.current.threads)).toHaveLength(2)
|
||||||
|
expect(result.current.threads['thread1'].model.id).toEqual('thread1:free')
|
||||||
|
expect(result.current.threads['thread1'].model.provider).toEqual('llamacpp')
|
||||||
|
expect(result.current.threads['thread2'].model.id).toEqual('thread2/test')
|
||||||
|
expect(result.current.threads['thread2'].model.provider).toEqual('llamacpp')
|
||||||
|
})
|
||||||
|
|
||||||
it('should set current thread ID', () => {
|
it('should set current thread ID', () => {
|
||||||
const { result } = renderHook(() => useThreads())
|
const { result } = renderHook(() => useThreads())
|
||||||
@ -106,7 +141,7 @@ describe('useThreads', () => {
|
|||||||
|
|
||||||
const threads = [
|
const threads = [
|
||||||
{ id: 'thread1', title: 'Thread 1', messages: [] },
|
{ id: 'thread1', title: 'Thread 1', messages: [] },
|
||||||
{ id: 'thread2', title: 'Thread 2', messages: [] }
|
{ id: 'thread2', title: 'Thread 2', messages: [] },
|
||||||
]
|
]
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
@ -143,7 +178,12 @@ describe('useThreads', () => {
|
|||||||
it('should toggle favorite', () => {
|
it('should toggle favorite', () => {
|
||||||
const { result } = renderHook(() => useThreads())
|
const { result } = renderHook(() => useThreads())
|
||||||
|
|
||||||
const thread = { id: 'thread1', title: 'Thread 1', messages: [], starred: false }
|
const thread = {
|
||||||
|
id: 'thread1',
|
||||||
|
title: 'Thread 1',
|
||||||
|
messages: [],
|
||||||
|
starred: false,
|
||||||
|
}
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
result.current.setThreads([thread])
|
result.current.setThreads([thread])
|
||||||
@ -171,7 +211,7 @@ describe('useThreads', () => {
|
|||||||
|
|
||||||
const threads = [
|
const threads = [
|
||||||
{ id: 'thread1', title: 'Thread 1', messages: [] },
|
{ id: 'thread1', title: 'Thread 1', messages: [] },
|
||||||
{ id: 'thread2', title: 'Thread 2', messages: [] }
|
{ id: 'thread2', title: 'Thread 2', messages: [] },
|
||||||
]
|
]
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
@ -215,7 +255,7 @@ describe('useThreads', () => {
|
|||||||
|
|
||||||
const threads = [
|
const threads = [
|
||||||
{ id: 'thread1', title: 'Thread 1', messages: [] },
|
{ id: 'thread1', title: 'Thread 1', messages: [] },
|
||||||
{ id: 'thread2', title: 'Thread 2', messages: [] }
|
{ id: 'thread2', title: 'Thread 2', messages: [] },
|
||||||
]
|
]
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
|
|||||||
@ -44,7 +44,9 @@ export const useThreads = create<ThreadState>()((set, get) => ({
|
|||||||
'llamacpp'
|
'llamacpp'
|
||||||
),
|
),
|
||||||
// Cortex migration: take first two parts of the ID (the last is file name which is not needed)
|
// Cortex migration: take first two parts of the ID (the last is file name which is not needed)
|
||||||
id: thread.model?.id.split(':').slice(0, 2).join(sep()),
|
id: !thread.model?.id.endsWith(':free')
|
||||||
|
? thread.model?.id.split(':').slice(0, 2).join(sep())
|
||||||
|
: thread.model?.id,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user