diff --git a/src/client/index.ts b/src/client/index.ts index 294de62..ec454b9 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -119,9 +119,9 @@ select.cc-input{appearance:none;-webkit-appearance:none;-moz-appearance:none;box .cc-usageHint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5} .cc-usageError{align-items:center;gap:8px;color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5;display:flex} .cc-usageStats{grid-template-columns:repeat(auto-fit,minmax(120px,1fr));gap:8px;display:grid} -.cc-usageStat{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);border-radius:8px;padding:8px 10px;flex-direction:column;gap:2px;display:flex} +.cc-usageStat{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);border-radius:8px;padding:8px 10px;flex-direction:column;gap:2px;display:flex;min-width:0} .cc-usageStatLabel{color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:1.5} -.cc-usageStatValue{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4} +.cc-usageStatValue{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4;min-width:0;overflow-wrap:anywhere} .cc-usageStatSub{color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:1.5} .cc-usageWindows{flex-direction:column;gap:16px;display:flex} .cc-usageWindow{flex-direction:column;gap:6px;display:flex} diff --git a/src/client/section.tsx b/src/client/section.tsx index c6ce45c..3cd5706 100644 --- a/src/client/section.tsx +++ b/src/client/section.tsx @@ -27,7 +27,7 @@ import type { AccountItemState, CatalogModelOption, RuleItemState, SettingsPageS import type { CommandCodeLoginFailureReason } from '../login-wire.ts' import type { LoginPageState } from './login.ts' import type { UsagePageState } from './usage.ts' -import { formatMoney, formatMoneyExact, formatResetAt, formatTokensCompact, windowRatio } from './usage.ts' +import { formatMoney, formatMoneyExact, formatPercent, formatResetAt, formatTokensCompact, windowRatio } from './usage.ts' import { PLUGIN_RELEASES_URL, PLUGIN_VERSION } from './version.ts' import { checkForUpdate, localStorageUpdateStore } from './update.ts' @@ -540,7 +540,7 @@ function AccountReport({ entry, fetchedAt, t, onRemove }: { value={String(report.usage.completedCount)} sub={`${t('usageFailed')} ${report.usage.failedCount}`} /> - + { assert.equal(result.kind, 'success') assert.match(result.text, /mars-sea/) assert.match(result.text, /935 次/) - assert.match(result.text, /成功率 100%/) + assert.match(result.text, /成功率 100.00%/) assert.match(result.text, /\$1\.3187/) assert.match(result.text, /\$8\.68/) assert.match(result.text, /5 小时/) @@ -232,7 +232,7 @@ test('command renders a full usage report in en', async () => { assert.equal(result.kind, 'success') assert.match(result.text, /mars-sea/) assert.match(result.text, /Requests 935/) - assert.match(result.text, /success rate 100%/) + assert.match(result.text, /success rate 100.00%/) assert.match(result.text, /\$1\.3187/) assert.match(result.text, /\$8\.68/) assert.match(result.text, /5-hour/) diff --git a/tests/usage-client.test.ts b/tests/usage-client.test.ts index e811fea..8568007 100644 --- a/tests/usage-client.test.ts +++ b/tests/usage-client.test.ts @@ -13,6 +13,7 @@ import { CommandCodeUsageController, formatMoney, formatMoneyExact, + formatPercent, formatResetAt, formatTokensCompact, windowRatio, @@ -148,6 +149,13 @@ test('formatTokensCompact renders K/M/B suffixes', () => { assert.equal(formatTokensCompact(3_000_000_000), '3.0B') }) +test('formatPercent renders a percentage with 2 decimals', () => { + assert.equal(formatPercent(99.9882890268181), '99.99%') + assert.equal(formatPercent(100), '100.00%') + assert.equal(formatPercent(99), '99.00%') + assert.equal(formatPercent(0), '0.00%') +}) + test('windowRatio clamps into [0, 1] and treats cap 0 as empty', () => { assert.equal(windowRatio(1.5, 5), 0.3) assert.equal(windowRatio(10, 5), 1)