diff --git a/src/overview/Hero.test.tsx b/src/overview/Hero.test.tsx index 3c53bf7b..a382ddc4 100644 --- a/src/overview/Hero.test.tsx +++ b/src/overview/Hero.test.tsx @@ -119,7 +119,7 @@ describe("用量", () => { expect(cost).toContain(t.estimated("$0.0020")); expect(cost).toContain(t.shortUnpriced(3)); // 限定符缩小写在金额前面(单独一段),金额照常 - expect(cost).toMatch(/>≥~<\/span>\$0\.032≥<\/span>\$0\.032 { diff --git a/src/overview/Hero.tsx b/src/overview/Hero.tsx index 9a74ede4..1ae51b8f 100644 --- a/src/overview/Hero.tsx +++ b/src/overview/Hero.tsx @@ -414,7 +414,7 @@ function Change({ function CostValue({ c, amount, scope }: { c: ReturnType; amount: number; scope: string }) { if (c.kind !== "amount") return <>—; /* - 指标只有一百多像素宽:「≥~」两个限定符按大数的字号写,「≥~$52.57」就放不下了。限定符 + 指标只有一百多像素宽:限定符按大数的字号写,「≥$52.57」就放不下了。限定符 缩小写在前面,意思不变;一千美元以上不写分,写满几位的整数 */ return ( diff --git a/src/overview/series.test.ts b/src/overview/series.test.ts index baee3f5e..040908cf 100644 --- a/src/overview/series.test.ts +++ b/src/overview/series.test.ts @@ -392,10 +392,10 @@ describe("费用写什么", () => { expect(rankCost(c({ cost: 500, pending: 1 }), t)).toMatchObject({ prefix: "≥", notes: [t.rankPending(1)] }); }); - it("含估算:带「~」,估算的数写在悬停里;两样都有是「≥~」", () => { + it("含估算:带「~」,估算的数写在悬停里;两样都有只写「≥」", () => { expect(rankCost(c({ cost: 500, estimated: 120 }), t)).toEqual({ kind: "amount", prefix: "~", notes: [t.estimated("$0.0001")] }); expect(rankCost(c({ cost: 500, estimated: 120, unpriced: 1 }), t)).toMatchObject({ - prefix: "≥~", + prefix: "≥", notes: [t.estimated("$0.0001"), t.rankUnpriced(1)], }); }); diff --git a/src/overview/series.ts b/src/overview/series.ts index 1e2cca03..3ed31402 100644 --- a/src/overview/series.ts +++ b/src/overview/series.ts @@ -1,4 +1,5 @@ import { densify, monthDay } from "@/format"; +import { costPrefix } from "@/traffic/costCell"; import { usd, type CostBucket, type CostBucketGroup, type Dashboard, type ProviderView, type Summary } from "@/types"; import { LIVE_BUCKET_MS, LIVE_REACH_MS, liveRate, type LiveEnd, type LiveSample } from "./useLive"; import type { overviewText } from "./overview.i18n"; @@ -371,20 +372,12 @@ export function cacheOf(s: Pick { expect(c.notes).toEqual([t.estimatedTip("$0.061")]); }); - it("既有估算又缺了轮次时两个记号都在", () => { + it("既有估算又缺了轮次时只写「≥」,估算了多少照样在悬停里", () => { const c = costCell( session({ cost_micros_estimated: 5_000, priced_turns: 9, unpriced_turns: 1 }), t, ); - expect(c.text).toBe("≥~$0.233"); + expect(c.text).toBe("≥$0.233"); expect(c.notes).toEqual([t.estimatedTip("$0.0050"), t.unpricedTurnsTip(1)]); }); diff --git a/src/traffic/costCell.ts b/src/traffic/costCell.ts index c15f606b..6ac17651 100644 --- a/src/traffic/costCell.ts +++ b/src/traffic/costCell.ts @@ -37,12 +37,21 @@ export function costCell( // **估算不能冒充实测**:合计里有估算的部分,就要带着记号 const estimated = s.cost_micros_estimated > 0; return { - text: (outside.length > 0 ? "≥" : "") + (estimated ? "~" : "") + usd(s.cost_micros), + text: costPrefix(outside.length > 0, estimated) + usd(s.cost_micros), muted: false, notes: [...(estimated ? [t.estimatedTip(usd(s.cost_micros_estimated))] : []), ...outside], }; } +/** + * 金额前面的记号,概览与会话的费用共用:缺了算不出来的请求,金额只是下限(「≥」); + * **估算不能冒充实测**,含估算的带「~」。两样都有只写「≥」:它已经说了不是准数,估算了 + * 多少写在悬停里。 + */ +export function costPrefix(incomplete: boolean, estimated: boolean): string { + return incomplete ? "≥" : estimated ? "~" : ""; +} + /** 会话瀑布里一轮的费用:落了库的那一轮,或者表里还没落库的那一行 */ export interface TurnCost { cost: number | null;