Trim trailing zeros on qualifying-points values
Display fractional QP with up to 2 decimals and trailing zeros trimmed (1.50→1.5, 0.50→0.5) in both the Discord embed (formatQPValue) and the web UI (formatQP) so the two surfaces stay consistent. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011U7mTxDVK2cH8E2BWjCiUv
This commit is contained in:
parent
3f16d5e1d3
commit
cab161424e
4 changed files with 15 additions and 9 deletions
|
|
@ -14,7 +14,7 @@ const scoringRules = {
|
|||
};
|
||||
|
||||
describe("QualifyingPointsStandings", () => {
|
||||
it("renders fractional QP to hundredths", () => {
|
||||
it("renders fractional QP to at most hundredths with trailing zeros trimmed", () => {
|
||||
render(
|
||||
<QualifyingPointsStandings
|
||||
standings={[
|
||||
|
|
@ -52,7 +52,8 @@ describe("QualifyingPointsStandings", () => {
|
|||
);
|
||||
|
||||
expect(screen.getByText("14.67 QP")).toBeInTheDocument();
|
||||
expect(screen.getByText("0.50 QP")).toBeInTheDocument();
|
||||
// 0.50 trims its trailing zero to 0.5; 14.67 and 0.43 are unaffected.
|
||||
expect(screen.getByText("0.5 QP")).toBeInTheDocument();
|
||||
expect(screen.getByText("0.43 QP")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -55,7 +55,9 @@ interface QualifyingPointsStandingsProps {
|
|||
function formatQP(raw: string): string {
|
||||
const n = parseFloat(raw);
|
||||
if (isNaN(n)) return "—";
|
||||
return n % 1 === 0 ? n.toString() : n.toFixed(2);
|
||||
// At most 2 decimals, trailing zeros trimmed (1.50→1.5). Mirrors the Discord
|
||||
// embed's formatQPValue (app/services/discord.ts) so the site and Discord agree.
|
||||
return parseFloat(n.toFixed(2)).toString();
|
||||
}
|
||||
|
||||
export function QualifyingPointsStandings({
|
||||
|
|
|
|||
|
|
@ -857,11 +857,13 @@ describe("sendQualifyingPointsUpdateNotification", () => {
|
|||
});
|
||||
|
||||
const desc = getDescription();
|
||||
// Mirrors the web UI's formatQP: fractional QP renders with 2 decimals ("1.50"),
|
||||
// never rounded to an integer. The Points Awarded line no longer carries a "+".
|
||||
expect(desc).toContain("• **Novak Djokovic (snarkymcgee)** — 1.50 QP");
|
||||
// Mirrors the web UI's formatQP: fractional QP renders with up to 2 decimals and
|
||||
// trailing zeros trimmed ("1.5"), never rounded to an integer. The Points Awarded
|
||||
// line no longer carries a "+".
|
||||
expect(desc).toContain("• **Novak Djokovic (snarkymcgee)** — 1.5 QP");
|
||||
expect(desc).not.toContain("+");
|
||||
expect(desc).not.toContain("2 QP");
|
||||
expect(desc).not.toContain("1.50");
|
||||
});
|
||||
|
||||
it("excludes participants ranked outside the top 8 from the Drafted Participants section", async () => {
|
||||
|
|
|
|||
|
|
@ -66,11 +66,12 @@ function escapeMarkdown(text: string): string {
|
|||
/**
|
||||
* Format a QP value for display. QP is genuinely fractional (e.g. a tennis R16 loser
|
||||
* earns 1.5 QP from the 9–16 split), so we must NOT round: show whole numbers plainly
|
||||
* and fractional values to 2 decimals. Mirrors the web UI's formatQP
|
||||
* (app/components/scoring/QualifyingPointsStandings.tsx) so Discord and the site agree.
|
||||
* and fractional values to at most 2 decimals with trailing zeros trimmed (1.50→1.5).
|
||||
* Mirrors the web UI's formatQP (app/components/scoring/QualifyingPointsStandings.tsx)
|
||||
* so Discord and the site agree.
|
||||
*/
|
||||
function formatQPValue(n: number): string {
|
||||
return n % 1 === 0 ? n.toString() : n.toFixed(2);
|
||||
return parseFloat(n.toFixed(2)).toString();
|
||||
}
|
||||
|
||||
export interface StandingEntry {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue