Skip to content

Commit 37dabe7

Browse files
authored
test(svg): verify truncateUsername caps long usernames in generateSVG (JhaSourav07#2223)
## Description Fixes JhaSourav07#1082 ## Pillar - [x] 📐 Pillar 2 — Geometric SVG Improvement ## Visual Preview This adds integration tests to assert username truncation behaviors. Long usernames are verified to cap safely with trailing dots (`...`), while short usernames are verified to contain no ellipsis. ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [x] I have made sure that I have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents c261554 + 478ff42 commit 37dabe7

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
@@ -1564,6 +1564,41 @@ describe('Radar Scan Line Animation Alignment', () => {
15641564
expect(geometryLong).toEqual(geometryBaseline);
15651565
});
15661566

1567+
it('truncates usernames longer than 12 characters and adds an ellipsis in generateSVG', () => {
1568+
const longUsername = 'averylongusernamethatexceeds20chars'; // 36 characters
1569+
const expectedTruncated = 'AVERYLONGUSE...'; // 12 characters + '...' (in uppercase)
1570+
1571+
const svg = generateSVG(
1572+
mockStats,
1573+
{ user: longUsername, size: 'medium', autoTheme: false } as unknown as BadgeParams,
1574+
mockCalendar
1575+
);
1576+
1577+
const titleMatch = svg.match(/<text[^>]*class="title"[^>]*>([^<]*)<\/text>/);
1578+
expect(titleMatch).not.toBeNull();
1579+
const renderedTitle = titleMatch?.[1];
1580+
1581+
expect(renderedTitle).toBe(expectedTruncated);
1582+
expect(renderedTitle).not.toContain(longUsername.toUpperCase());
1583+
});
1584+
1585+
it('does not truncate short usernames and leaves them without ellipsis in generateSVG', () => {
1586+
const shortUsername = 'abc'; // 3 characters
1587+
1588+
const svg = generateSVG(
1589+
mockStats,
1590+
{ user: shortUsername, size: 'medium', autoTheme: false } as unknown as BadgeParams,
1591+
mockCalendar
1592+
);
1593+
1594+
const titleMatch = svg.match(/<text[^>]*class="title"[^>]*>([^<]*)<\/text>/);
1595+
expect(titleMatch).not.toBeNull();
1596+
const renderedTitle = titleMatch?.[1];
1597+
1598+
expect(renderedTitle).toBe(shortUsername.toUpperCase());
1599+
expect(renderedTitle).not.toContain('...');
1600+
});
1601+
15671602
describe('glow parameter', () => {
15681603
const mockStats: StreakStats = {
15691604
currentStreak: 5,

0 commit comments

Comments
 (0)