-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadinessCheck.test.tsx
More file actions
124 lines (112 loc) · 3.68 KB
/
ReadinessCheck.test.tsx
File metadata and controls
124 lines (112 loc) · 3.68 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { render } from 'ink-testing-library';
import { useRef } from 'react';
import { ReadinessCheck, ReadinessState } from './ReadinessCheck';
const mockSubmit = vi.hoisted(() => vi.fn());
vi.mock('@/components/Chat', () => ({
ChatInput: ({
onSubmit,
}: {
onSubmit: (value: { content: string }) => void;
}) => {
const onSubmitRef = useRef(onSubmit);
onSubmitRef.current = onSubmit;
// Store the callback for tests to access
mockSubmit.mockImplementation((value: { content: string }) => {
onSubmitRef.current(value);
});
return null;
},
}));
describe('ReadinessCheck', () => {
beforeEach(() => {
mockSubmit.mockClear();
});
it('renders checking state', () => {
const { lastFrame } = render(
<ReadinessCheck
setupState={ReadinessState.Checking}
onCommand={vi.fn()}
/>,
);
expect(lastFrame()).toContain('Checking Ollama server and model setup');
});
it('renders missing model config state', () => {
const { lastFrame } = render(
<ReadinessCheck
setupState={ReadinessState.MissingModelConfig}
onCommand={vi.fn()}
/>,
);
expect(lastFrame()).toContain('No Model Configured');
expect(lastFrame()).toContain('Select or download a model');
expect(lastFrame()).toContain('/model');
});
it('renders no installed models state', () => {
const { lastFrame } = render(
<ReadinessCheck
setupState={ReadinessState.NoInstalledModels}
onCommand={vi.fn()}
/>,
);
expect(lastFrame()).toContain('No Model Installed');
expect(lastFrame()).toContain('Download a model');
expect(lastFrame()).toContain('/model');
});
it('renders model load error state without message', () => {
const { lastFrame } = render(
<ReadinessCheck
setupState={ReadinessState.ModelLoadError}
onCommand={vi.fn()}
/>,
);
expect(lastFrame()).toContain('Connection Error');
expect(lastFrame()).toContain('Error loading models');
expect(lastFrame()).toContain('Fix the connection and restart the app');
});
it('renders server unavailable state', () => {
const { lastFrame } = render(
<ReadinessCheck
setupState={ReadinessState.ServerUnavailable}
onCommand={vi.fn()}
/>,
);
expect(lastFrame()).toContain('Ollama Server Unavailable');
expect(lastFrame()).toContain(
'Ollama server is not running or unreachable',
);
expect(lastFrame()).toContain('ollama serve');
});
it('renders model load error state with message', () => {
const { lastFrame } = render(
<ReadinessCheck
setupState={ReadinessState.ModelLoadError}
errorMessage="Connection refused"
onCommand={vi.fn()}
/>,
);
expect(lastFrame()).toContain('Connection Error');
expect(lastFrame()).toContain('Error loading models: Connection refused');
});
it('renders for Ready state with empty messages', () => {
const { lastFrame } = render(
<ReadinessCheck setupState={ReadinessState.Ready} onCommand={vi.fn()} />,
);
// No title or message lines are shown
expect(lastFrame()).not.toContain('Checking Ollama');
expect(lastFrame()).not.toContain('No model configured');
expect(lastFrame()).not.toContain('No models installed');
expect(lastFrame()).not.toContain('Unable to load models');
});
it('calls onCommand when ChatInput submits', () => {
const onCommand = vi.fn();
render(
<ReadinessCheck
setupState={ReadinessState.Ready}
onCommand={onCommand}
/>,
);
// The mock stores the callback in mockSubmit
mockSubmit({ content: '/model' });
expect(onCommand).toHaveBeenCalledWith('/model');
});
});