Skip to content

Commit 392b7c3

Browse files
authored
test(utils): check username truncator boundary robustness (JhaSourav07#1563) (JhaSourav07#1665)
## Description Fixes JhaSourav07#1563 Added a boundary robustness test for username truncation behavior in the SVG generator. The new test verifies that usernames longer than 30 characters are safely truncated with trailing dots while ensuring SVG layout and geometry remain valid. ## Pillar * [ ] 🎨 Pillar 1 — New Theme Design * [ ] 📐 Pillar 2 — Geometric SVG Improvement * [ ] 🕐 Pillar 3 — Timezone Logic Optimization * [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A (test-only changes) ## 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`). * [ ] 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): ...`). * [ ] I have updated `README.md` if I added a new theme or URL parameter. * [x] I have started the repo. * [x] I have made sure that i have only one commit to merge in this PR. * [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard (not applicable for test-only changes). * [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support. ## Test Validation Command executed: ```bash npx vitest run lib/svg/generator.test.ts ``` Result: ```text ✓ lib/svg/generator.test.ts Test Files 1 passed (1) Tests 102 passed (102) ``` ## Files Changed * lib/svg/generator.test.ts ## Notes * Added one new boundary-focused test block. * Verified truncation behavior for usernames longer than 30 characters. * Verified SVG geometry remains valid after truncation. * No production code changes were made.
2 parents b082945 + cb1c19e commit 392b7c3

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

lib/svg/generator.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,4 +1283,24 @@ describe('Radar Scan Line Animation Alignment', () => {
12831283
// 5. Assert: Ensure the original string was actually modified
12841284
expect(result).not.toEqual(longUsername);
12851285
});
1286+
1287+
it('renders long usernames as truncated SVG labels without breaking geometry', () => {
1288+
const longUsername = 'ThisIsAVeryLongUsernameThatExceedsThirtyCharacters';
1289+
const svg = generateSVG(
1290+
{
1291+
currentStreak: 10,
1292+
longestStreak: 20,
1293+
totalContributions: 200,
1294+
todayDate: '2024-06-12',
1295+
},
1296+
{ user: longUsername, size: 'medium', autoTheme: false } as unknown as BadgeParams,
1297+
mockCalendar
1298+
);
1299+
1300+
expect(svg).toContain('...');
1301+
expect(svg).not.toContain(longUsername.toUpperCase());
1302+
expect(svg).toContain('text-anchor="middle"');
1303+
expect(svg).toContain('width="600"');
1304+
expect(svg).toContain('height="420"');
1305+
});
12861306
});

0 commit comments

Comments
 (0)