Skip to content

Commit 98377f2

Browse files
committed
handle leading 0 in driver rating badge introduced by iRacing
1 parent 09c8382 commit 98377f2

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/frontend/components/Standings/DriverRatingBadge/DriverRatingBadge.spec.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,25 @@ describe('DriverRatingBadge', () => {
5656
);
5757
expect(container.textContent).toBe('R 0.0k');
5858
});
59+
60+
it('removes leading zeros from license number when before non-zero digit', () => {
61+
const { container } = render(
62+
<DriverRatingBadge license="A 02.99" rating={5000} />
63+
);
64+
expect(container.textContent).toBe('A 2.99 5.0k');
65+
});
66+
67+
it('keeps single zero before decimal point', () => {
68+
const { container } = render(
69+
<DriverRatingBadge license="A 0.99" rating={5000} />
70+
);
71+
expect(container.textContent).toBe('A 0.99 5.0k');
72+
});
73+
74+
it('handles multiple leading zeros', () => {
75+
const { container } = render(
76+
<DriverRatingBadge license="B 0003.45" rating={5000} />
77+
);
78+
expect(container.textContent).toBe('B 3.45 5.0k');
79+
});
5980
});

src/frontend/components/Standings/DriverRatingBadge/DriverRatingBadge.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const AllRatings: Story = {
2929
<DriverRatingBadge license="C 2.99" rating={2999} />
3030
<DriverRatingBadge license="D 1.99" rating={1999} />
3131
<DriverRatingBadge license="R 0.99" rating={999} />
32+
<DriverRatingBadge license="R 02.99" rating={999} />
3233
</div>
3334
),
3435
};

src/frontend/components/Standings/DriverRatingBadge/DriverRatingBadge.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ export const DriverRatingBadge = ({
1919
let fixed = 1;
2020
if (rating >= 10000) fixed = 0;
2121
const simplifiedRating = (rating / 1000).toFixed(fixed);
22+
23+
// Format the license string to remove leading zeros only when they're before a non-zero digit
24+
const formattedLicense = license?.replace(/([A-Z]) 0+([1-9]\d*\.\d+)/, '$1 $2') || 'R';
25+
2226
return (
2327
<div
2428
className={`text-center text-white w-16 border-solid rounded-md text-xs m-0 px-1 border-2 ${color}`}
2529
>
26-
{license} {simplifiedRating}k
30+
{formattedLicense} {simplifiedRating}k
2731
</div>
2832
);
2933
};

0 commit comments

Comments
 (0)