feat: 优化 Agent 运行时与聊天设置体验
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:social_app/core/di/injection.dart';
|
||||
import 'package:social_app/features/auth/data/auth_repository.dart';
|
||||
import 'package:social_app/features/auth/presentation/bloc/auth_bloc.dart';
|
||||
import 'package:social_app/features/auth/presentation/bloc/auth_event.dart';
|
||||
import 'package:social_app/features/auth/presentation/bloc/auth_state.dart';
|
||||
import 'package:social_app/features/settings/ui/screens/change_password_screen.dart';
|
||||
|
||||
class MockAuthRepository extends Mock implements AuthRepository {}
|
||||
|
||||
void main() {
|
||||
late MockAuthRepository mockAuthRepository;
|
||||
late AuthBloc authBloc;
|
||||
|
||||
setUp(() async {
|
||||
mockAuthRepository = MockAuthRepository();
|
||||
await sl.reset();
|
||||
sl.registerSingleton<AuthRepository>(mockAuthRepository);
|
||||
|
||||
authBloc = AuthBloc(mockAuthRepository);
|
||||
authBloc.add(
|
||||
const AuthLoggedIn(
|
||||
user: AuthUser(id: 'user-1', email: 'tester@example.com'),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await authBloc.close();
|
||||
await sl.reset();
|
||||
});
|
||||
|
||||
Future<void> pumpScreen(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
BlocProvider<AuthBloc>.value(
|
||||
value: authBloc,
|
||||
child: const MaterialApp(home: ChangePasswordScreen()),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
testWidgets('确认修改按钮在验证码发送前不可点击', (tester) async {
|
||||
when(
|
||||
() => mockAuthRepository.requestPasswordReset(any()),
|
||||
).thenAnswer((_) async {});
|
||||
|
||||
await pumpScreen(tester);
|
||||
|
||||
final confirmButton = tester.widget<ElevatedButton>(
|
||||
find.widgetWithText(ElevatedButton, '确认修改'),
|
||||
);
|
||||
expect(confirmButton.onPressed, isNull);
|
||||
expect(find.text('完成验证码验证后可提交密码修改'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('发送验证码倒计时期间不会重复触发请求', (tester) async {
|
||||
final completer = Completer<void>();
|
||||
when(
|
||||
() => mockAuthRepository.requestPasswordReset(any()),
|
||||
).thenAnswer((_) => completer.future);
|
||||
|
||||
await pumpScreen(tester);
|
||||
|
||||
await tester.tap(find.text('发送验证码'));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('60 秒后可重发'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('60 秒后可重发'));
|
||||
await tester.pump();
|
||||
|
||||
verify(
|
||||
() => mockAuthRepository.requestPasswordReset('tester@example.com'),
|
||||
).called(1);
|
||||
|
||||
completer.complete();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:social_app/features/settings/ui/widgets/account_section_card.dart';
|
||||
import 'package:social_app/features/settings/ui/widgets/account_surface_scaffold.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('AccountSectionCard renders title and description', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: AccountSectionCard(
|
||||
title: '基础信息',
|
||||
description: '请填写公开展示资料',
|
||||
child: Text('内容区'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('基础信息'), findsOneWidget);
|
||||
expect(find.text('请填写公开展示资料'), findsOneWidget);
|
||||
expect(find.text('内容区'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('AccountSurfaceScaffold renders header and footer', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AccountSurfaceScaffold(
|
||||
title: '编辑资料',
|
||||
subtitle: '管理账户公开信息',
|
||||
body: const Text('主体内容'),
|
||||
footer: const Text('底部操作区'),
|
||||
onBack: () {},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('编辑资料'), findsOneWidget);
|
||||
expect(find.text('管理账户公开信息'), findsOneWidget);
|
||||
expect(find.text('主体内容'), findsOneWidget);
|
||||
expect(find.text('底部操作区'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user