summaryrefslogtreecommitdiff
path: root/llama.cpp/tools/server/webui/tests/stories/fixtures/storybook-mocks.ts
blob: c40a74655a07727f4118a55b520c92cb90e53f84 (plain)
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
71
72
73
74
75
76
77
78
79
80
81
import { serverStore } from '$lib/stores/server.svelte';
import { modelsStore } from '$lib/stores/models.svelte';

/**
 * Mock server properties for Storybook testing
 * This utility allows setting mock server configurations without polluting production code
 */
export function mockServerProps(props: Partial<ApiLlamaCppServerProps>): void {
	// Reset any pointer-events from previous tests (dropdown cleanup)
	const body = document.querySelector('body');
	if (body) body.style.pointerEvents = '';

	// Directly set the props for testing purposes
	(serverStore as unknown as { props: ApiLlamaCppServerProps }).props = {
		model_path: props.model_path || 'test-model',
		modalities: {
			vision: props.modalities?.vision ?? false,
			audio: props.modalities?.audio ?? false
		},
		...props
	} as ApiLlamaCppServerProps;

	// Set router mode role so activeModelId can be set
	(serverStore as unknown as { props: ApiLlamaCppServerProps }).props.role = 'ROUTER';

	// Also mock modelsStore methods for modality checking
	const vision = props.modalities?.vision ?? false;
	const audio = props.modalities?.audio ?? false;

	// eslint-disable-next-line @typescript-eslint/no-explicit-any
	(modelsStore as any).modelSupportsVision = () => vision;
	// eslint-disable-next-line @typescript-eslint/no-explicit-any
	(modelsStore as any).modelSupportsAudio = () => audio;

	// Mock models list with a test model so activeModelId can be resolved
	// eslint-disable-next-line @typescript-eslint/no-explicit-any
	(modelsStore as any).models = [
		{
			id: 'test-model',
			name: 'Test Model',
			model: 'test-model'
		}
	];

	// Mock selectedModelId
	// eslint-disable-next-line @typescript-eslint/no-explicit-any
	(modelsStore as any).selectedModelId = 'test-model';
}

/**
 * Reset server store to clean state for testing
 */
export function resetServerStore(): void {
	(serverStore as unknown as { props: ApiLlamaCppServerProps }).props = {
		model_path: '',
		modalities: {
			vision: false,
			audio: false
		}
	} as ApiLlamaCppServerProps;
	(serverStore as unknown as { error: string }).error = '';
	(serverStore as unknown as { loading: boolean }).loading = false;
}

/**
 * Common mock configurations for Storybook stories
 */
export const mockConfigs = {
	visionOnly: {
		modalities: { vision: true, audio: false }
	},
	audioOnly: {
		modalities: { vision: false, audio: true }
	},
	bothModalities: {
		modalities: { vision: true, audio: true }
	},
	noModalities: {
		modalities: { vision: false, audio: false }
	}
} as const;