-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai-assistant.test.js
More file actions
47 lines (39 loc) · 1.51 KB
/
ai-assistant.test.js
File metadata and controls
47 lines (39 loc) · 1.51 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
import { describe, expect, it, vi } from 'vitest';
import { getAssistantReply, normalizePrompt } from '../assets/js/ai-assistant.js';
describe('ai assistant helpers', () => {
it('normalizes prompt text', () => {
expect(normalizePrompt(' HeLLo ')).toBe('hello');
});
it('returns guidance for empty prompts', () => {
expect(getAssistantReply('')).toContain('Typ een korte vraag');
});
it('matches prompts to known sections', () => {
expect(getAssistantReply('Waar is de blog pagina?')).toContain('/blog/');
expect(getAssistantReply('toont dashboard widgets')).toContain('/dashboard/');
expect(getAssistantReply('laat updates zien')).toContain('/updates/');
});
it('returns default fallback when no keyword matches', () => {
expect(getAssistantReply('onbekende vraag')).toContain('nog geen live AI-backend');
});
it('registers behavior only when required nodes exist', async () => {
vi.resetModules();
const fakeToggle = {
state: 'false',
setAttribute: vi.fn(function setAttribute(_name, value) {
this.state = value;
}),
getAttribute: vi.fn(function getAttribute() {
return this.state;
}),
addEventListener: vi.fn(),
};
const fakeRoot = {
querySelector: (selector) => {
if (selector === '[data-ai-helper-toggle]') return fakeToggle;
return null;
},
};
const { initAiAssistant } = await import('../assets/js/ai-assistant.js');
expect(() => initAiAssistant(fakeRoot)).not.toThrow();
});
});