forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
- Loading branch information
Showing
22 changed files
with
152 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { act, renderHook } from '@testing-library/react'; | ||
import { DeepPartial } from 'utility-types'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
import { DEFAULT_AGENT, DEFAULT_SETTINGS } from '@/const/settings'; | ||
import { useGlobalStore } from '@/store/global'; | ||
import { SettingsTabs } from '@/store/global/initialState'; | ||
import { LobeAgentSettings } from '@/types/session'; | ||
import { GlobalSettings, OpenAIConfig } from '@/types/settings'; | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
vi.mock('@/utils/uuid', () => ({ | ||
nanoid: vi.fn(() => 'unique-id'), | ||
})); | ||
|
||
describe('SettingsAction', () => { | ||
describe('importAppSettings', () => { | ||
it('should import app settings', () => { | ||
const { result } = renderHook(() => useGlobalStore()); | ||
const newSettings: GlobalSettings = { | ||
...DEFAULT_SETTINGS, | ||
themeMode: 'dark', | ||
}; | ||
|
||
act(() => { | ||
result.current.importAppSettings(newSettings); | ||
}); | ||
|
||
expect(result.current.settings).toEqual(newSettings); | ||
}); | ||
}); | ||
|
||
describe('resetSettings', () => { | ||
it('should reset settings to default', () => { | ||
const { result } = renderHook(() => useGlobalStore()); | ||
|
||
act(() => { | ||
result.current.resetSettings(); | ||
}); | ||
|
||
expect(result.current.settings).toEqual(DEFAULT_SETTINGS); | ||
}); | ||
}); | ||
|
||
describe('setOpenAIConfig', () => { | ||
it('should set OpenAI configuration', () => { | ||
const { result } = renderHook(() => useGlobalStore()); | ||
const openAIConfig: Partial<OpenAIConfig> = { OPENAI_API_KEY: 'test' }; | ||
|
||
act(() => { | ||
result.current.setOpenAIConfig(openAIConfig); | ||
}); | ||
|
||
expect(result.current.settings.languageModel.openAI.OPENAI_API_KEY).toEqual( | ||
openAIConfig.OPENAI_API_KEY, | ||
); | ||
}); | ||
}); | ||
|
||
describe('setSettings', () => { | ||
it('should set partial settings', () => { | ||
const { result } = renderHook(() => useGlobalStore()); | ||
const partialSettings: Partial<GlobalSettings> = { themeMode: 'dark' }; | ||
|
||
act(() => { | ||
result.current.setSettings(partialSettings); | ||
}); | ||
|
||
expect(result.current.settings.themeMode).toEqual('dark'); | ||
}); | ||
}); | ||
|
||
describe('switchSettingTabs', () => { | ||
it('should switch settings tabs', () => { | ||
const { result } = renderHook(() => useGlobalStore()); | ||
|
||
act(() => { | ||
result.current.switchSettingTabs(SettingsTabs.Agent); | ||
}); | ||
|
||
expect(result.current.settingsTab).toEqual(SettingsTabs.Agent); | ||
}); | ||
}); | ||
|
||
describe('switchThemeMode', () => { | ||
it('should switch theme mode', () => { | ||
const { result } = renderHook(() => useGlobalStore()); | ||
|
||
act(() => { | ||
result.current.switchThemeMode('light'); | ||
}); | ||
|
||
expect(result.current.settings.themeMode).toEqual('light'); | ||
}); | ||
}); | ||
|
||
describe('updateDefaultAgent', () => { | ||
it('should update default agent settings', () => { | ||
const { result } = renderHook(() => useGlobalStore()); | ||
const updatedAgent: DeepPartial<LobeAgentSettings> = { | ||
meta: { title: 'docs' }, | ||
}; | ||
|
||
act(() => { | ||
result.current.updateDefaultAgent(updatedAgent); | ||
}); | ||
|
||
expect(result.current.settings.defaultAgent).toEqual({ | ||
...DEFAULT_AGENT, | ||
...updatedAgent, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters