refactor: 重构聊天数据层至core并简化首页UI
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:social_app/app/di/injection.dart';
|
||||
import 'package:social_app/app/router/app_router.dart';
|
||||
import 'package:social_app/app/router/app_routes.dart';
|
||||
import 'package:social_app/data/network/i_api_client.dart';
|
||||
import 'package:social_app/core/chat/chat_api.dart';
|
||||
import 'package:social_app/features/chat/presentation/bloc/chat_bloc.dart';
|
||||
import 'package:social_app/features/auth/presentation/bloc/auth_state.dart';
|
||||
|
||||
@@ -13,7 +14,7 @@ void main() {
|
||||
if (sl.isRegistered<ChatBloc>()) {
|
||||
await sl.unregister<ChatBloc>();
|
||||
}
|
||||
sl.registerSingleton<ChatBloc>(ChatBloc(apiClient: _FakeApiClient()));
|
||||
sl.registerSingleton<ChatBloc>(ChatBloc(chatApi: _FakeChatApi()));
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
@@ -43,6 +44,17 @@ void main() {
|
||||
expect(result, AppRoutes.homeMain);
|
||||
});
|
||||
|
||||
test('keeps authenticated home access on home route', () {
|
||||
final result = resolveAuthRedirect(
|
||||
authState: const AuthAuthenticated(
|
||||
user: AuthUser(id: 'u1', phone: '13800138000'),
|
||||
),
|
||||
matchedLocation: AppRoutes.homeMain,
|
||||
);
|
||||
|
||||
expect(result, isNull);
|
||||
});
|
||||
|
||||
test('redirects auth checking state to boot route', () {
|
||||
final result = resolveAuthRedirect(
|
||||
authState: AuthLoading(),
|
||||
@@ -69,37 +81,50 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
class _FakeApiClient implements IApiClient {
|
||||
class _FakeChatApi implements ChatApi {
|
||||
@override
|
||||
Future<Response<T>> delete<T>(String path, {data, Options? options}) {
|
||||
Future<void> cancelRun({required String threadId, required String runId}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Response<T>> get<T>(String path, {Options? options}) {
|
||||
Future<Map<String, dynamic>> createRun(Map<String, dynamic> runInput) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Stream<String>> getSseLines(
|
||||
String path, {
|
||||
Map<String, String>? headers,
|
||||
Future<Map<String, dynamic>> fetchHistory({
|
||||
String? threadId,
|
||||
DateTime? beforeDate,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Response<T>> patch<T>(String path, {data, Options? options}) {
|
||||
Future<Uint8List> fetchAttachmentPreview(String previewPath) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Response<T>> post<T>(String path, {data, Options? options}) {
|
||||
Future<Stream<String>> streamRunEvents(
|
||||
String threadId, {
|
||||
String? lastEventId,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Response<T>> put<T>(String path, {data, Options? options}) {
|
||||
Future<String> transcribeAudio(String filePath) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> uploadAttachment({
|
||||
required String threadId,
|
||||
required String filename,
|
||||
required String mimeType,
|
||||
required Uint8List bytes,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user