Chat: show the active Claude account in the send tooltip, menu and limit banner
usage.account now carries the email and organization of the account Claude Code is signed in to (from its initialize account, or the saved account just switched to), sent at process start and after a switch. The app shows it as the send tooltip's usage prefix, the Claude account menu subtitle, the usage-limit banner's status line and the info sheet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_auto_continue.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_controller.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_usage_limit_banner.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_account_usage.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/segmented_bar_overflow.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'chat_composer_bar_fixtures.dart';
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
// The active Claude account is named wherever the chat shows its account:
|
||||
// the send button's tooltip, the Claude account menu item and the
|
||||
// usage-limit banner. It comes from usage.account.email.
|
||||
|
||||
const _email = 'sam@caplens.example';
|
||||
|
||||
JsonMap _usage({double? five, String email = _email}) {
|
||||
final now = DateTime.now();
|
||||
return {
|
||||
'session_id': 's',
|
||||
'kind': 'usage',
|
||||
'usage': {
|
||||
'account': {
|
||||
'harness': 'Claude Code',
|
||||
'plan': 'max',
|
||||
'email': email,
|
||||
'organization': 'Caplens',
|
||||
'windows': [
|
||||
if (five != null)
|
||||
{
|
||||
'id': 'five_hour',
|
||||
'label': '5-hour',
|
||||
'used_percent': five,
|
||||
'resets_at': now
|
||||
.add(const Duration(hours: 2))
|
||||
.millisecondsSinceEpoch,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
String? _sendTooltip(WidgetTester tester) => tester
|
||||
.widget<Tooltip>(
|
||||
find.ancestor(
|
||||
of: find.byIcon(Icons.arrow_upward),
|
||||
matching: find.byType(Tooltip),
|
||||
),
|
||||
)
|
||||
.message;
|
||||
|
||||
void main() {
|
||||
setUp(() => SharedPreferences.setMockInitialValues({}));
|
||||
|
||||
test('usage.account names the account, even before any quota', () {
|
||||
final named = chatAccountUsage(_usage()['usage']['account']);
|
||||
expect(named?.email, _email);
|
||||
expect(named?.organization, 'Caplens');
|
||||
expect(named?.windows, isEmpty);
|
||||
// No email (an API key) and no quota: nothing to show.
|
||||
expect(chatAccountUsage({'harness': 'Claude Code', 'email': ''}), isNull);
|
||||
});
|
||||
|
||||
testWidgets('the send tooltip leads its usage line with the account', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = ComposerBarGateway();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
gateway.emitEvent(_usage());
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(_sendTooltip(tester), 'Send\n$_email');
|
||||
gateway.emitEvent(_usage(five: 42));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(_sendTooltip(tester), startsWith('Send\n$_email · 5-hour 42% · '));
|
||||
// Assistive technology still names the button by its label alone.
|
||||
expect(find.bySemanticsLabel('Send'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the Claude account menu item shows the active account', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: 's',
|
||||
session: const {'id': 's', 'backend': 'claude', 'directory': '/x'},
|
||||
syncToken: 0,
|
||||
onBack: () {},
|
||||
drafts: MemoryChatDraftStore(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
gateway.emitEvent(_usage());
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(segmentedMoreKey).hitTestable().first);
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
expect(find.text('Claude account'), findsOneWidget);
|
||||
expect(find.text(_email), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the usage-limit banner names the account that hit it', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway();
|
||||
final thread = ChatThreadController(gateway, 's');
|
||||
final composer = ChatComposerController(gateway, 's');
|
||||
addTearDown(gateway.close);
|
||||
addTearDown(thread.dispose);
|
||||
addTearDown(composer.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
ChatUsageLimitBanner(
|
||||
thread: thread,
|
||||
composer: composer,
|
||||
autoContinue: ChatAutoContinue(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
gateway.emitEvent(_usage(five: 100));
|
||||
await tester.pumpAndSettle();
|
||||
final status = tester.widget<Text>(
|
||||
find.byKey(const Key('chat-usage-limit-status')),
|
||||
);
|
||||
expect(status.data, startsWith('$_email · Resets at '));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user