Skip to content

Commit 478ff42

Browse files
test(svg): verify truncateUsername caps long usernames in generateSVG
1 parent e6b5723 commit 478ff42

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

lib/svg/generator.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,41 @@ describe('Radar Scan Line Animation Alignment', () => {
14791479
expect(geometryLong).toEqual(geometryBaseline);
14801480
});
14811481

1482+
it('truncates usernames longer than 12 characters and adds an ellipsis in generateSVG', () => {
1483+
const longUsername = 'averylongusernamethatexceeds20chars'; // 36 characters
1484+
const expectedTruncated = 'AVERYLONGUSE...'; // 12 characters + '...' (in uppercase)
1485+
1486+
const svg = generateSVG(
1487+
mockStats,
1488+
{ user: longUsername, size: 'medium', autoTheme: false } as unknown as BadgeParams,
1489+
mockCalendar
1490+
);
1491+
1492+
const titleMatch = svg.match(/<text[^>]*class="title"[^>]*>([^<]*)<\/text>/);
1493+
expect(titleMatch).not.toBeNull();
1494+
const renderedTitle = titleMatch?.[1];
1495+
1496+
expect(renderedTitle).toBe(expectedTruncated);
1497+
expect(renderedTitle).not.toContain(longUsername.toUpperCase());
1498+
});
1499+
1500+
it('does not truncate short usernames and leaves them without ellipsis in generateSVG', () => {
1501+
const shortUsername = 'abc'; // 3 characters
1502+
1503+
const svg = generateSVG(
1504+
mockStats,
1505+
{ user: shortUsername, size: 'medium', autoTheme: false } as unknown as BadgeParams,
1506+
mockCalendar
1507+
);
1508+
1509+
const titleMatch = svg.match(/<text[^>]*class="title"[^>]*>([^<]*)<\/text>/);
1510+
expect(titleMatch).not.toBeNull();
1511+
const renderedTitle = titleMatch?.[1];
1512+
1513+
expect(renderedTitle).toBe(shortUsername.toUpperCase());
1514+
expect(renderedTitle).not.toContain('...');
1515+
});
1516+
14821517
describe('glow parameter', () => {
14831518
const mockStats: StreakStats = {
14841519
currentStreak: 5,

0 commit comments

Comments
 (0)