diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-02-12 20:57:17 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-02-12 20:57:17 +0100 |
| commit | b333b06772c89d96aacb5490d6a219fba7c09cc6 (patch) | |
| tree | 211df60083a5946baa2ed61d33d8121b7e251b06 /llama.cpp/tools/server/webui/tests/stories/fixtures/storybook-mocks.ts | |
| download | llmnpc-b333b06772c89d96aacb5490d6a219fba7c09cc6.tar.gz | |
Engage!
Diffstat (limited to 'llama.cpp/tools/server/webui/tests/stories/fixtures/storybook-mocks.ts')
| -rw-r--r-- | llama.cpp/tools/server/webui/tests/stories/fixtures/storybook-mocks.ts | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/llama.cpp/tools/server/webui/tests/stories/fixtures/storybook-mocks.ts b/llama.cpp/tools/server/webui/tests/stories/fixtures/storybook-mocks.ts new file mode 100644 index 0000000..c40a746 --- /dev/null +++ b/llama.cpp/tools/server/webui/tests/stories/fixtures/storybook-mocks.ts | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | import { serverStore } from '$lib/stores/server.svelte'; | ||
| 2 | import { modelsStore } from '$lib/stores/models.svelte'; | ||
| 3 | |||
| 4 | /** | ||
| 5 | * Mock server properties for Storybook testing | ||
| 6 | * This utility allows setting mock server configurations without polluting production code | ||
| 7 | */ | ||
| 8 | export function mockServerProps(props: Partial<ApiLlamaCppServerProps>): void { | ||
| 9 | // Reset any pointer-events from previous tests (dropdown cleanup) | ||
| 10 | const body = document.querySelector('body'); | ||
| 11 | if (body) body.style.pointerEvents = ''; | ||
| 12 | |||
| 13 | // Directly set the props for testing purposes | ||
| 14 | (serverStore as unknown as { props: ApiLlamaCppServerProps }).props = { | ||
| 15 | model_path: props.model_path || 'test-model', | ||
| 16 | modalities: { | ||
| 17 | vision: props.modalities?.vision ?? false, | ||
| 18 | audio: props.modalities?.audio ?? false | ||
| 19 | }, | ||
| 20 | ...props | ||
| 21 | } as ApiLlamaCppServerProps; | ||
| 22 | |||
| 23 | // Set router mode role so activeModelId can be set | ||
| 24 | (serverStore as unknown as { props: ApiLlamaCppServerProps }).props.role = 'ROUTER'; | ||
| 25 | |||
| 26 | // Also mock modelsStore methods for modality checking | ||
| 27 | const vision = props.modalities?.vision ?? false; | ||
| 28 | const audio = props.modalities?.audio ?? false; | ||
| 29 | |||
| 30 | // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| 31 | (modelsStore as any).modelSupportsVision = () => vision; | ||
| 32 | // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| 33 | (modelsStore as any).modelSupportsAudio = () => audio; | ||
| 34 | |||
| 35 | // Mock models list with a test model so activeModelId can be resolved | ||
| 36 | // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| 37 | (modelsStore as any).models = [ | ||
| 38 | { | ||
| 39 | id: 'test-model', | ||
| 40 | name: 'Test Model', | ||
| 41 | model: 'test-model' | ||
| 42 | } | ||
| 43 | ]; | ||
| 44 | |||
| 45 | // Mock selectedModelId | ||
| 46 | // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| 47 | (modelsStore as any).selectedModelId = 'test-model'; | ||
| 48 | } | ||
| 49 | |||
| 50 | /** | ||
| 51 | * Reset server store to clean state for testing | ||
| 52 | */ | ||
| 53 | export function resetServerStore(): void { | ||
| 54 | (serverStore as unknown as { props: ApiLlamaCppServerProps }).props = { | ||
| 55 | model_path: '', | ||
| 56 | modalities: { | ||
| 57 | vision: false, | ||
| 58 | audio: false | ||
| 59 | } | ||
| 60 | } as ApiLlamaCppServerProps; | ||
| 61 | (serverStore as unknown as { error: string }).error = ''; | ||
| 62 | (serverStore as unknown as { loading: boolean }).loading = false; | ||
| 63 | } | ||
| 64 | |||
| 65 | /** | ||
| 66 | * Common mock configurations for Storybook stories | ||
| 67 | */ | ||
| 68 | export const mockConfigs = { | ||
| 69 | visionOnly: { | ||
| 70 | modalities: { vision: true, audio: false } | ||
| 71 | }, | ||
| 72 | audioOnly: { | ||
| 73 | modalities: { vision: false, audio: true } | ||
| 74 | }, | ||
| 75 | bothModalities: { | ||
| 76 | modalities: { vision: true, audio: true } | ||
| 77 | }, | ||
| 78 | noModalities: { | ||
| 79 | modalities: { vision: false, audio: false } | ||
| 80 | } | ||
| 81 | } as const; | ||
