-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-comment.test.ts
More file actions
111 lines (98 loc) · 4.58 KB
/
github-comment.test.ts
File metadata and controls
111 lines (98 loc) · 4.58 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
import { describe, it, expect } from 'vitest';
import { buildCommentBody } from '../../packages/core/src/publisher/github-comment.js';
import type { ChangeAnalysis } from '../../packages/core/src/analyzer/change-summarizer.js';
describe('buildCommentBody', () => {
const ANALYSIS: ChangeAnalysis = {
changedFiles: ['app/routes/home.tsx', 'src/components/Button.tsx'],
affectedRoutes: [{ file: 'app/routes/home.tsx', route: '/', changeType: 'modified' }],
changeDescription: 'Added a virtual try-on button',
suggestedDemoFlow: '1. Navigate to home page\n2. Click try-on button',
};
it('includes comment marker for idempotent updates', () => {
const body = buildCommentBody({ analysis: ANALYSIS, script: 'demo()', owner: 'o', repo: 'r', pullNumber: 1 });
expect(body).toContain('<!-- git-glimpse-demo -->');
});
it('includes recording URL as image when provided', () => {
const body = buildCommentBody({
analysis: ANALYSIS,
recordingUrl: 'https://example.com/demo.gif',
script: 'demo()',
owner: 'o', repo: 'r', pullNumber: 1,
});
expect(body).toContain('');
expect(body).toContain('Open it directly');
});
it('includes screenshots when no recording URL', () => {
const body = buildCommentBody({
analysis: ANALYSIS,
screenshots: ['https://example.com/s1.png', 'https://example.com/s2.png'],
script: 'demo()',
owner: 'o', repo: 'r', pullNumber: 1,
});
expect(body).toContain('Screenshot 1');
expect(body).toContain('Screenshot 2');
expect(body).not.toContain('No recording available');
});
it('shows fallback when neither recording nor screenshots are present', () => {
const body = buildCommentBody({ analysis: ANALYSIS, script: 'demo()', owner: 'o', repo: 'r', pullNumber: 1 });
expect(body).toContain('No recording available');
});
it('truncates file list to 5 and shows count of remaining', () => {
const manyFilesAnalysis: ChangeAnalysis = {
...ANALYSIS,
changedFiles: ['a.tsx', 'b.tsx', 'c.tsx', 'd.tsx', 'e.tsx', 'f.tsx', 'g.tsx'],
};
const body = buildCommentBody({ analysis: manyFilesAnalysis, script: 'demo()', owner: 'o', repo: 'r', pullNumber: 1 });
expect(body).toContain('`a.tsx`');
expect(body).toContain('`e.tsx`');
expect(body).not.toContain('`f.tsx`');
expect(body).toContain('+2 more');
});
it('shows all files when 5 or fewer', () => {
const body = buildCommentBody({ analysis: ANALYSIS, script: 'demo()', owner: 'o', repo: 'r', pullNumber: 1 });
expect(body).toContain('`app/routes/home.tsx`');
expect(body).toContain('`src/components/Button.tsx`');
expect(body).not.toContain('more');
});
it('includes the change description', () => {
const body = buildCommentBody({ analysis: ANALYSIS, script: 'demo()', owner: 'o', repo: 'r', pullNumber: 1 });
expect(body).toContain('Added a virtual try-on button');
});
it('wraps script in collapsible details with typescript code block', () => {
const body = buildCommentBody({ analysis: ANALYSIS, script: 'export async function demo(page) {}', owner: 'o', repo: 'r', pullNumber: 1 });
expect(body).toContain('<details>');
expect(body).toContain('Demo script (auto-generated)');
expect(body).toContain('```typescript');
expect(body).toContain('export async function demo(page) {}');
});
it('includes rerun link when provided', () => {
const body = buildCommentBody({
analysis: ANALYSIS,
script: 'demo()',
rerunUrl: 'https://github.com/owner/repo/actions/runs/123',
owner: 'o', repo: 'r', pullNumber: 1,
});
expect(body).toContain('Re-run demo');
expect(body).toContain('https://github.com/owner/repo/actions/runs/123');
});
it('omits rerun link when not provided', () => {
const body = buildCommentBody({ analysis: ANALYSIS, script: 'demo()', owner: 'o', repo: 'r', pullNumber: 1 });
expect(body).not.toContain('Re-run demo');
});
it('includes git-glimpse branding', () => {
const body = buildCommentBody({ analysis: ANALYSIS, script: 'demo()', owner: 'o', repo: 'r', pullNumber: 1 });
expect(body).toContain('git-glimpse');
expect(body).toContain('logo_square_small.png');
});
it('prefers recording URL over screenshots', () => {
const body = buildCommentBody({
analysis: ANALYSIS,
recordingUrl: 'https://example.com/demo.gif',
screenshots: ['https://example.com/s1.png'],
script: 'demo()',
owner: 'o', repo: 'r', pullNumber: 1,
});
expect(body).toContain('![Demo]');
expect(body).not.toContain('Screenshot 1');
});
});