@@ -1303,4 +1303,53 @@ describe('Radar Scan Line Animation Alignment', () => {
13031303 expect ( svg ) . toContain ( 'width="600"' ) ;
13041304 expect ( svg ) . toContain ( 'height="420"' ) ;
13051305 } ) ;
1306+
1307+ it ( 'safely truncates usernames longer than 30 chars with trailing dots without changing CSS geometry' , ( ) => {
1308+ // 1. Arrange: Create usernames (one short baseline, one strictly > 30 chars)
1309+ const shortUsername = 'avi' ;
1310+ const longUsername = 'ThisIsAVeryLongUsernameThatExceedsThirtyCharacters' ;
1311+ const expectedTruncated = longUsername . slice ( 0 , 12 ) + '...' ;
1312+
1313+ const paramsBaseline = {
1314+ user : shortUsername ,
1315+ size : 'medium' ,
1316+ autoTheme : false ,
1317+ } as unknown as BadgeParams ;
1318+ const paramsLong = {
1319+ user : longUsername ,
1320+ size : 'medium' ,
1321+ autoTheme : false ,
1322+ } as unknown as BadgeParams ;
1323+
1324+ // 2. Act: Truncate username and generate SVGs
1325+ const truncatedName = truncateUsername ( longUsername ) ;
1326+ const svgBaseline = generateSVG ( mockStats , paramsBaseline , mockCalendar ) ;
1327+ const svgLong = generateSVG ( mockStats , paramsLong , mockCalendar ) ;
1328+
1329+ // Helper to extract critical SVG geometry attributes
1330+ const extractGeometry = ( svgStr : string ) => {
1331+ const width = svgStr . match ( / w i d t h = " ( [ ^ " ] * ) " / ) ?. [ 1 ] ;
1332+ const height = svgStr . match ( / h e i g h t = " ( [ ^ " ] * ) " / ) ?. [ 1 ] ;
1333+ const viewBox = svgStr . match ( / v i e w B o x = " ( [ ^ " ] * ) " / ) ?. [ 1 ] ;
1334+ return { width, height, viewBox } ;
1335+ } ;
1336+
1337+ // 3. Assertions:
1338+
1339+ // A. Verify exact expected truncation value on the helper utility
1340+ expect ( truncatedName ) . toBe ( expectedTruncated ) ;
1341+
1342+ // B. Verify the visible <text class="title"> tag contains exactly the truncated name and NOT the full username
1343+ const textTitleMatch = svgLong . match ( / < t e x t [ ^ > ] * c l a s s = " t i t l e " [ ^ > ] * > ( [ ^ < ] * ) < \/ t e x t > / ) ;
1344+ expect ( textTitleMatch ) . not . toBeNull ( ) ;
1345+ const renderedTitleText = textTitleMatch ?. [ 1 ] ;
1346+
1347+ expect ( renderedTitleText ) . toBe ( expectedTruncated . toUpperCase ( ) ) ;
1348+ expect ( renderedTitleText ) . not . toContain ( longUsername . toUpperCase ( ) ) ;
1349+
1350+ // C. Verify geometry remains completely unchanged compared to the baseline
1351+ const geometryBaseline = extractGeometry ( svgBaseline ) ;
1352+ const geometryLong = extractGeometry ( svgLong ) ;
1353+ expect ( geometryLong ) . toEqual ( geometryBaseline ) ;
1354+ } ) ;
13061355} ) ;
0 commit comments