3951c65a7a
A thin ring around Send shows the harness account's 5-hour window used share (the most used live window when there is no 5-hour one): barely visible normally, tertiary from 80%, error from 95%. The button's tooltip (hover, long-press on touch) adds every window with its reset time. No ring when the quota is unknown or unsupported. Painted behind the unchanged button, so its size, target, states and animations stay as they were. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
144 lines
3.9 KiB
Dart
144 lines
3.9 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/chat/domain/chat_account_usage.dart';
|
|
import 'package:pipelines_app/features/chat/domain/chat_usage_ring.dart';
|
|
|
|
final _now = DateTime(2026, 11, 30, 12); // a Monday
|
|
|
|
ChatQuotaWindow _window(String id, String label, double used, DateTime? at) =>
|
|
ChatQuotaWindow(
|
|
id: id,
|
|
label: label,
|
|
usedPercent: used,
|
|
resetsAt: at?.millisecondsSinceEpoch ?? 0,
|
|
);
|
|
|
|
ChatAccountUsage _usage(List<ChatQuotaWindow> windows) => ChatAccountUsage(
|
|
harness: 'Claude Code',
|
|
plan: 'max',
|
|
asOf: 0,
|
|
windows: windows,
|
|
unsupported: false,
|
|
);
|
|
|
|
void main() {
|
|
test('shows the 5-hour window even when another is higher', () {
|
|
final ring = chatUsageRing(
|
|
_usage([
|
|
_window('seven_day', 'Weekly', 93, null),
|
|
_window('five_hour', '5-hour', 42, null),
|
|
]),
|
|
_now,
|
|
)!;
|
|
expect(ring.shown.label, '5-hour');
|
|
expect(ring.fraction, closeTo(.42, 1e-9));
|
|
expect(ring.tone, ChatUsageRingTone.quiet);
|
|
});
|
|
|
|
test('a harness labelling its window "5-hour" counts as the 5-hour', () {
|
|
final ring = chatUsageRing(
|
|
_usage([
|
|
_window('secondary', 'Weekly', 70, null),
|
|
_window('primary', '5-hour', 10, null),
|
|
]),
|
|
_now,
|
|
)!;
|
|
expect(ring.shown.id, 'primary');
|
|
});
|
|
|
|
test('without a 5-hour window the most used one is shown', () {
|
|
final ring = chatUsageRing(
|
|
_usage([
|
|
_window('a', 'Daily', 20, null),
|
|
_window('b', 'Weekly', 61, null),
|
|
]),
|
|
_now,
|
|
)!;
|
|
expect(ring.shown.label, 'Weekly');
|
|
});
|
|
|
|
test('tones: quiet below 80, warning from 80, urgent from 95', () {
|
|
ChatUsageRingTone tone(double used) => chatUsageRing(
|
|
_usage([_window('five_hour', '5-hour', used, null)]),
|
|
_now,
|
|
)!.tone;
|
|
expect(tone(79.4), ChatUsageRingTone.quiet);
|
|
expect(tone(80), ChatUsageRingTone.warning);
|
|
expect(tone(94.9), ChatUsageRingTone.warning);
|
|
expect(tone(95), ChatUsageRingTone.urgent);
|
|
expect(tone(130), ChatUsageRingTone.urgent);
|
|
});
|
|
|
|
test('past a cap the ring is full, never more', () {
|
|
final ring = chatUsageRing(
|
|
_usage([_window('five_hour', '5-hour', 130, null)]),
|
|
_now,
|
|
)!;
|
|
expect(ring.fraction, 1);
|
|
});
|
|
|
|
test('no ring for unknown, unsupported or entirely reset quota', () {
|
|
expect(chatUsageRing(null, _now), isNull);
|
|
expect(
|
|
chatUsageRing(
|
|
const ChatAccountUsage(
|
|
harness: 'OpenCode',
|
|
plan: '',
|
|
asOf: 0,
|
|
windows: [],
|
|
unsupported: true,
|
|
),
|
|
_now,
|
|
),
|
|
isNull,
|
|
);
|
|
final past = _now.subtract(const Duration(minutes: 1));
|
|
expect(
|
|
chatUsageRing(_usage([_window('five_hour', '5-hour', 90, past)]), _now),
|
|
isNull,
|
|
);
|
|
});
|
|
|
|
test('a reset 5-hour window falls back to the live ones', () {
|
|
final ring = chatUsageRing(
|
|
_usage([
|
|
_window(
|
|
'five_hour',
|
|
'5-hour',
|
|
90,
|
|
_now.subtract(const Duration(hours: 1)),
|
|
),
|
|
_window('seven_day', 'Weekly', 61, null),
|
|
]),
|
|
_now,
|
|
)!;
|
|
expect(ring.shown.label, 'Weekly');
|
|
expect(ring.windows.map((w) => w.label), ['Weekly']);
|
|
});
|
|
|
|
test('summary names every window with its reset time', () {
|
|
final ring = chatUsageRing(
|
|
_usage([
|
|
_window('five_hour', '5-hour', 42.4, DateTime(2026, 11, 30, 17, 20)),
|
|
_window('seven_day', 'Weekly', 61, DateTime(2026, 12, 3, 9)),
|
|
]),
|
|
_now,
|
|
)!;
|
|
expect(
|
|
chatUsageRingSummary(ring, _now),
|
|
'5-hour 42% · resets 17:20 · Weekly 61% · resets Thu 09:00',
|
|
);
|
|
});
|
|
|
|
test('reset times: today, this week, further out', () {
|
|
expect(chatUsageRingResetTime(DateTime(2026, 11, 30, 8, 5), _now), '08:05');
|
|
expect(
|
|
chatUsageRingResetTime(DateTime(2026, 12, 1, 0, 30), _now),
|
|
'Tue 00:30',
|
|
);
|
|
expect(
|
|
chatUsageRingResetTime(DateTime(2026, 12, 9, 9), _now),
|
|
'9 Dec 09:00',
|
|
);
|
|
});
|
|
}
|