|
1 | | -import { describe, it, expect } from 'vitest'; |
2 | | -import { stripHash, isValidHex } from './utils'; |
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { getExportSnippet, getPlaceholderSnippet } from './utils'; |
3 | 3 |
|
4 | | -describe('Customize Utils', () => { |
5 | | - describe('stripHash', () => { |
6 | | - it('removes leading # from hex color', () => { |
7 | | - expect(stripHash('#ff0000')).toBe('ff0000'); |
8 | | - }); |
| 4 | +describe('Export Snippet utilities', () => { |
| 5 | + const EXPECTED_BASE_URL = 'https://commitpulse.vercel.app/api/streak'; |
9 | 6 |
|
10 | | - it('returns unchanged string if no # prefix', () => { |
11 | | - expect(stripHash('ff0000')).toBe('ff0000'); |
12 | | - }); |
| 7 | + describe('getExportSnippet', () => { |
| 8 | + it('generates markdown snippet', () => { |
| 9 | + const queryString = 'user=testuser&theme=dark'; |
| 10 | + const result = getExportSnippet('markdown', queryString); |
13 | 11 |
|
14 | | - it('handles empty string', () => { |
15 | | - expect(stripHash('')).toBe(''); |
| 12 | + expect(typeof result).toBe('string'); |
| 13 | + expect(result.startsWith('![CommitPulse]')).toBe(true); |
| 14 | + expect(result).toContain(EXPECTED_BASE_URL); |
| 15 | + expect(result).toBe(``); |
16 | 16 | }); |
17 | 17 |
|
18 | | - it('only removes leading #, not all occurrences', () => { |
19 | | - expect(stripHash('##ff0000')).toBe('#ff0000'); |
20 | | - }); |
| 18 | + it('generates html snippet', () => { |
| 19 | + const queryString = 'user=testuser&theme=dark'; |
| 20 | + const result = getExportSnippet('html', queryString); |
21 | 21 |
|
22 | | - it('handles just # character', () => { |
23 | | - expect(stripHash('#')).toBe(''); |
| 22 | + expect(typeof result).toBe('string'); |
| 23 | + expect(result.startsWith('<img src=')).toBe(true); |
| 24 | + expect(result).toContain(EXPECTED_BASE_URL); |
| 25 | + expect(result).toBe(`<img src="${EXPECTED_BASE_URL}?${queryString}" alt="CommitPulse" />`); |
24 | 26 | }); |
25 | | - }); |
26 | | - |
27 | | - describe('isValidHex', () => { |
28 | | - describe('valid 6-digit hex colors', () => { |
29 | | - it('accepts lowercase hex without #', () => { |
30 | | - expect(isValidHex('ffffff')).toBe(true); |
31 | | - expect(isValidHex('000000')).toBe(true); |
32 | | - expect(isValidHex('ff0000')).toBe(true); |
33 | | - }); |
34 | 27 |
|
35 | | - it('accepts uppercase hex without #', () => { |
36 | | - expect(isValidHex('FFFFFF')).toBe(true); |
37 | | - expect(isValidHex('FF0000')).toBe(true); |
38 | | - }); |
| 28 | + it('handles empty query string', () => { |
| 29 | + const emptyQuery = ''; |
| 30 | + const markdownResult = getExportSnippet('markdown', emptyQuery); |
| 31 | + const htmlResult = getExportSnippet('html', emptyQuery); |
39 | 32 |
|
40 | | - it('accepts mixed case hex without #', () => { |
41 | | - expect(isValidHex('FfFfFf')).toBe(true); |
42 | | - expect(isValidHex('aAbBcC')).toBe(true); |
43 | | - }); |
| 33 | + expect(markdownResult.startsWith('![CommitPulse]')).toBe(true); |
| 34 | + expect(markdownResult).toContain(EXPECTED_BASE_URL); |
44 | 35 |
|
45 | | - it('accepts 6-digit hex with # prefix', () => { |
46 | | - expect(isValidHex('#ffffff')).toBe(true); |
47 | | - expect(isValidHex('#000000')).toBe(true); |
48 | | - }); |
| 36 | + expect(htmlResult.startsWith('<img src=')).toBe(true); |
| 37 | + expect(htmlResult).toContain(EXPECTED_BASE_URL); |
49 | 38 | }); |
50 | 39 |
|
51 | | - describe('invalid hex colors', () => { |
52 | | - it('rejects non-hex characters', () => { |
53 | | - expect(isValidHex('zzzzzz')).toBe(false); |
54 | | - expect(isValidHex('gggggg')).toBe(false); |
55 | | - expect(isValidHex('ff@0000')).toBe(false); |
56 | | - }); |
| 40 | + it('handles complex query strings', () => { |
| 41 | + const complexQuery = 'user=complex%20name&ring=ff0000%2C00ff00&fire=true'; |
| 42 | + const result = getExportSnippet('markdown', complexQuery); |
57 | 43 |
|
58 | | - it('rejects wrong length', () => { |
59 | | - expect(isValidHex('f')).toBe(false); |
60 | | - expect(isValidHex('ff')).toBe(false); |
61 | | - expect(isValidHex('fff')).toBe(false); |
62 | | - expect(isValidHex('fffff')).toBe(false); |
63 | | - expect(isValidHex('fffffff')).toBe(false); |
64 | | - expect(isValidHex('ffffffff')).toBe(false); |
65 | | - }); |
| 44 | + expect(result).toContain(complexQuery); |
| 45 | + expect(result).toBe(``); |
| 46 | + }); |
| 47 | + }); |
66 | 48 |
|
67 | | - it('rejects hex with # but invalid length', () => { |
68 | | - expect(isValidHex('#fff')).toBe(false); |
69 | | - expect(isValidHex('#fffff')).toBe(false); |
70 | | - }); |
| 49 | + describe('getPlaceholderSnippet', () => { |
| 50 | + it('includes placeholder username in markdown', () => { |
| 51 | + const result = getPlaceholderSnippet('markdown'); |
| 52 | + |
| 53 | + expect(result.startsWith('![CommitPulse]')).toBe(true); |
| 54 | + expect(result).toContain('your-github-username'); |
| 55 | + expect(result).toContain(EXPECTED_BASE_URL); |
| 56 | + }); |
71 | 57 |
|
72 | | - it('rejects empty string', () => { |
73 | | - expect(isValidHex('')).toBe(false); |
74 | | - }); |
| 58 | + it('includes placeholder username in html', () => { |
| 59 | + const result = getPlaceholderSnippet('html'); |
75 | 60 |
|
76 | | - it('rejects hex with invalid characters and #', () => { |
77 | | - expect(isValidHex('#zzzzzz')).toBe(false); |
78 | | - expect(isValidHex('#ff@000')).toBe(false); |
79 | | - }); |
| 61 | + expect(result.startsWith('<img src=')).toBe(true); |
| 62 | + expect(result).toContain('your-github-username'); |
| 63 | + expect(result).toContain(EXPECTED_BASE_URL); |
80 | 64 | }); |
81 | 65 | }); |
82 | 66 | }); |
0 commit comments