-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve models and threads caching (#3744)
* chore: managing and maintaining models and threads in the cache * test: add tests for hooks
- Loading branch information
Showing
30 changed files
with
2,084 additions
and
84 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
Empty file.
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,78 @@ | ||
// Extension.atom.test.ts | ||
|
||
import { act, renderHook } from '@testing-library/react' | ||
import * as ExtensionAtoms from './Extension.atom' | ||
import { useAtom, useAtomValue, useSetAtom } from 'jotai' | ||
|
||
describe('Extension.atom.ts', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
describe('installingExtensionAtom', () => { | ||
it('should initialize as an empty array', () => { | ||
const { result } = renderHook(() => useAtomValue(ExtensionAtoms.installingExtensionAtom)) | ||
expect(result.current).toEqual([]) | ||
}) | ||
}) | ||
|
||
describe('setInstallingExtensionAtom', () => { | ||
it('should add a new installing extension', () => { | ||
const { result: setAtom } = renderHook(() => useSetAtom(ExtensionAtoms.setInstallingExtensionAtom)) | ||
const { result: getAtom } = renderHook(() => useAtomValue(ExtensionAtoms.installingExtensionAtom)) | ||
|
||
act(() => { | ||
setAtom.current('ext1', { extensionId: 'ext1', percentage: 0 }) | ||
}) | ||
|
||
expect(getAtom.current).toEqual([{ extensionId: 'ext1', percentage: 0 }]) | ||
}) | ||
|
||
it('should update an existing installing extension', () => { | ||
const { result: setAtom } = renderHook(() => useSetAtom(ExtensionAtoms.setInstallingExtensionAtom)) | ||
const { result: getAtom } = renderHook(() => useAtomValue(ExtensionAtoms.installingExtensionAtom)) | ||
|
||
act(() => { | ||
setAtom.current('ext1', { extensionId: 'ext1', percentage: 0 }) | ||
setAtom.current('ext1', { extensionId: 'ext1', percentage: 50 }) | ||
}) | ||
|
||
expect(getAtom.current).toEqual([{ extensionId: 'ext1', percentage: 50 }]) | ||
}) | ||
}) | ||
|
||
describe('removeInstallingExtensionAtom', () => { | ||
it('should remove an installing extension', () => { | ||
const { result: setAtom } = renderHook(() => useSetAtom(ExtensionAtoms.setInstallingExtensionAtom)) | ||
const { result: removeAtom } = renderHook(() => useSetAtom(ExtensionAtoms.removeInstallingExtensionAtom)) | ||
const { result: getAtom } = renderHook(() => useAtomValue(ExtensionAtoms.installingExtensionAtom)) | ||
|
||
act(() => { | ||
setAtom.current('ext1', { extensionId: 'ext1', percentage: 0 }) | ||
setAtom.current('ext2', { extensionId: 'ext2', percentage: 50 }) | ||
removeAtom.current('ext1') | ||
}) | ||
|
||
expect(getAtom.current).toEqual([{ extensionId: 'ext2', percentage: 50 }]) | ||
}) | ||
}) | ||
|
||
describe('inActiveEngineProviderAtom', () => { | ||
it('should initialize as an empty array', () => { | ||
const { result } = renderHook(() => useAtomValue(ExtensionAtoms.inActiveEngineProviderAtom)) | ||
expect(result.current).toEqual([]) | ||
}) | ||
|
||
it('should persist value in storage', () => { | ||
const { result } = renderHook(() => useAtom(ExtensionAtoms.inActiveEngineProviderAtom)) | ||
|
||
act(() => { | ||
result.current[1](['provider1', 'provider2']) | ||
}) | ||
|
||
// Simulate a re-render to check if the value persists | ||
const { result: newResult } = renderHook(() => useAtomValue(ExtensionAtoms.inActiveEngineProviderAtom)) | ||
expect(newResult.current).toEqual(['provider1', 'provider2']) | ||
}) | ||
}) | ||
}) |
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
Oops, something went wrong.