-
Notifications
You must be signed in to change notification settings - Fork 543
Expand file tree
/
Copy pathuse-feedback-submit.test.ts
More file actions
74 lines (62 loc) · 2.25 KB
/
Copy pathuse-feedback-submit.test.ts
File metadata and controls
74 lines (62 loc) · 2.25 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
import { describe, expect, it } from 'vitest';
import { buildFeedbackContent } from './build-feedback-content';
import { FEEDBACK_EMAIL_SCHEMA } from './schemas/feedback-email';
describe('buildFeedbackContent', () => {
it('includes feedback, metadata, and app version when provided', () => {
const content = buildFeedbackContent({
feedback: 'Great app',
contactEmail: 'person@example.com',
githubUser: { login: 'octocat', name: 'Octo Cat' },
appVersion: '1.2.3',
platformDisplayName: 'macOS 15.5 (arm64)',
});
expect(content).toContain('Great app');
expect(content).toContain('Contact: person@example.com');
expect(content).toContain('GitHub: Octo Cat (@octocat)');
expect(content).toContain('Emdash Version: 1.2.3');
expect(content).toContain('Platform: macOS 15.5 (arm64)');
});
it('notes diagnostic logs when user opts in', () => {
const content = buildFeedbackContent({
feedback: 'Something broke',
contactEmail: '',
githubUser: null,
appVersion: '1.2.3',
includeDiagnosticLogs: true,
});
expect(content).toContain('Diagnostic Logs: attached by user opt-in');
});
it('omits diagnostic-log note when user does not opt in', () => {
const content = buildFeedbackContent({
feedback: 'Something broke',
contactEmail: '',
githubUser: null,
appVersion: '1.2.3',
});
expect(content).not.toContain('Diagnostic Logs');
});
it('omits empty metadata fields', () => {
const content = buildFeedbackContent({
feedback: 'Needs improvement',
contactEmail: ' ',
githubUser: null,
appVersion: '',
});
expect(content).toBe('Needs improvement');
});
});
describe('FEEDBACK_EMAIL_SCHEMA', () => {
it('accepts blank optional email', () => {
expect(FEEDBACK_EMAIL_SCHEMA.safeParse('').success).toBe(true);
});
it('accepts valid email', () => {
expect(FEEDBACK_EMAIL_SCHEMA.safeParse('person@example.com').success).toBe(true);
});
it('rejects invalid email', () => {
const result = FEEDBACK_EMAIL_SCHEMA.safeParse('person');
expect(result.success).toBe(false);
if (!result.success) {
expect(result.error.issues[0]?.message).toBe('Please enter a valid email address.');
}
});
});