Skip to content

Commit 3ec3e38

Browse files
authored
test: add regression tests for SVG structural cleanliness and duplicate render blocks (JhaSourav07#2145)
## Description Fixes JhaSourav07#2104 Added comprehensive regression tests to prevent malformed SVG structures from being reintroduced. Tests verify: - Exactly one root `<svg>` and closing `</svg>` tag (no nested wrappers) - No duplicate `renderHeader` or `renderStyle` calls - No duplicate `<style>` blocks - Proper structural cleanliness This ensures the SVG structural bug never resurfaces. ## Pillar - [x] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [ ] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview GitHub theme badge now displays with `#238636` accent color, matching the official documentation. ## 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=Pranav-IIITM&theme=github`). - [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 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. - [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 644ae7e + 65bf704 commit 3ec3e38

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

lib/svg/generator.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,50 @@ describe('deterministicRandom', () => {
16751675
});
16761676
});
16771677

1678+
describe('SVG Structural Validity and Cleanliness', () => {
1679+
const mockStats: StreakStats = {
1680+
currentStreak: 5,
1681+
longestStreak: 10,
1682+
totalContributions: 100,
1683+
todayDate: '2024-06-12',
1684+
};
1685+
const mockCalendar = {
1686+
weeks: [
1687+
{
1688+
contributionDays: [
1689+
{ contributionCount: 0, date: '2024-06-10' },
1690+
{ contributionCount: 5, date: '2024-06-11' },
1691+
{ contributionCount: 15, date: '2024-06-12' },
1692+
],
1693+
},
1694+
],
1695+
} as ContributionCalendar;
1696+
1697+
it('generateSVG output contains exactly one root <svg> element and exactly one closing </svg> tag', () => {
1698+
const svg = generateSVG(mockStats, { user: 'avi' } as unknown as BadgeParams, mockCalendar);
1699+
const openCount = (svg.match(/<svg/gi) || []).length;
1700+
const closeCount = (svg.match(/<\/svg>/gi) || []).length;
1701+
expect(openCount).toBe(1);
1702+
expect(closeCount).toBe(1);
1703+
});
1704+
1705+
it('generateSVG output contains exactly one style block', () => {
1706+
const svg = generateSVG(mockStats, { user: 'avi' } as unknown as BadgeParams, mockCalendar);
1707+
const styleOpenCount = (svg.match(/<style>/gi) || []).length;
1708+
const styleCloseCount = (svg.match(/<\/style>/gi) || []).length;
1709+
expect(styleOpenCount).toBe(1);
1710+
expect(styleCloseCount).toBe(1);
1711+
});
1712+
1713+
it('generateSVG does not contain duplicate renderHeader or renderStyle outputs', () => {
1714+
const svg = generateSVG(mockStats, { user: 'avi' } as unknown as BadgeParams, mockCalendar);
1715+
const titleCount = (svg.match(/<title id="cp-title-avi">/g) || []).length;
1716+
expect(titleCount).toBe(1);
1717+
const styleImportCount = (svg.match(/@import url/g) || []).length;
1718+
expect(styleImportCount).toBe(1);
1719+
});
1720+
});
1721+
16781722
describe('buildTowerPaths', () => {
16791723
it('returns correct paths for scale 1', () => {
16801724
const paths = buildTowerPaths(15, 1);

0 commit comments

Comments
 (0)