[verified] feat: tighten dashboard capacity signals

This commit is contained in:
2026-05-09 17:12:55 +09:00
parent 1fb40fd5fe
commit bfa8bb69f5
7 changed files with 122 additions and 19 deletions

View File

@@ -0,0 +1,18 @@
import { describe, expect, test } from 'bun:test';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
const appSource = readFileSync(join(import.meta.dir, '../src/App.tsx'), 'utf8');
describe('dashboard account capacity bars', () => {
test('renders compact per-account capacity bars without verbose labels', () => {
expect(appSource).toContain('const accountWindows = extractUsageWindows(account.usage);');
expect(appSource).toContain('const accountCapacityBars = [');
expect(appSource).toContain("className=\"space-y-2\"");
expect(appSource).toContain('indicatorClassName={getUsageProgressTone(progressValue)}');
expect(appSource).toContain("className=\"min-w-10 text-right text-xs font-medium text-slate-400\"");
expect(appSource).not.toContain('Account capacity');
expect(appSource).not.toContain('Primary window used');
expect(appSource).not.toContain('Secondary window used');
});
});

View File

@@ -11,7 +11,11 @@ describe('dashboard unified capacity windows', () => {
expect(appSource).toContain('Secondary window');
expect(appSource).toContain('const windowCards = [');
expect(appSource).toContain("} => item.window !== null,");
expect(appSource).toContain('item.window.limitWindowSeconds !== null ? (');
expect(appSource).toContain('getUsageProgressTone(progressValue)');
expect(appSource).toContain('const fastestResetAt = getFastestResetAt(');
expect(appSource).toContain('Replenishes at');
expect(appSource).not.toContain('Window data from');
expect(appSource).not.toContain('Resets ');
expect(appSource).not.toContain('<CardTitle>Usage metrics</CardTitle>');
expect(appSource).not.toContain('flattenNumericMetrics(summaryQuery.data?.aggregatedUsage).slice(0, 6)');
expect(appSource).not.toContain('const firstMetric = metricCards[0]?.value ?? 0;');

View File

@@ -10,6 +10,8 @@ describe('dashboard card copy', () => {
expect(appSource).toContain('<CardTitle>Connected OpenAI accounts</CardTitle>');
expect(appSource).toContain('Primary window');
expect(appSource).toContain('Secondary window');
expect(appSource).toContain('Replenishes at');
expect(appSource).not.toContain('Window data from');
expect(appSource).not.toContain('<CardTitle>Usage metrics</CardTitle>');
expect(appSource).toContain(">Merged by default. Inspect each account below.<");
expect(appSource).not.toContain(

View File

@@ -5,9 +5,9 @@ import { join } from 'node:path';
const appSource = readFileSync(join(import.meta.dir, '../src/App.tsx'), 'utf8');
describe('mobile overflow guards', () => {
test('unified capacity window cards stay in a responsive two-column grid', () => {
expect(appSource).toContain('className="grid gap-4 md:grid-cols-2"');
expect(appSource).toContain('className="rounded-2xl border border-white/10 bg-white/4 p-4"');
test('unified capacity window cards stay in a responsive full-height two-column grid', () => {
expect(appSource).toContain('className="grid flex-1 gap-4 md:auto-rows-fr md:grid-cols-2"');
expect(appSource).toContain('className="flex h-full flex-col justify-between rounded-2xl border border-white/10 bg-white/4 p-4"');
expect(appSource).toContain('className="text-sm text-slate-400">{item.title}</div>');
});

View File

@@ -2,6 +2,8 @@ import { describe, expect, test } from 'bun:test';
import {
extractUsageWindows,
formatDurationSeconds,
getFastestResetAt,
getUsageProgressTone,
summarizeUsageWindows,
} from '../src/lib/utils';
@@ -42,6 +44,22 @@ describe('usage window helpers', () => {
expect(formatDurationSeconds(null)).toBe('Unknown window');
});
test('maps usage thresholds to warning progress colors', () => {
expect(getUsageProgressTone(49)).toContain('from-sky-400');
expect(getUsageProgressTone(50)).toContain('from-amber-400');
expect(getUsageProgressTone(80)).toContain('from-rose-500');
});
test('picks the fastest reset time across available windows', () => {
expect(
getFastestResetAt([
'2026-05-09T12:00:00.000Z',
null,
'2026-05-09T10:00:00.000Z',
]),
).toBe('2026-05-09T10:00:00.000Z');
});
test('summarizes windows across multiple account payloads without summing percentages', () => {
const windows = summarizeUsageWindows([
{