forked from eatvio/eatvio_app
feat(tests): increased tests coverage
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
import 'package:eatvio_app/core/app_config.dart';
|
||||
import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/chat/presentation/pages/empty_chat_screen.dart';
|
||||
import 'package:eatvio_app/features/chat/repositories/chat_repository.dart';
|
||||
import 'package:eatvio_app/features/menu/presentation/blocked_user_cubit/blocked_users_cubit.dart';
|
||||
import 'package:eatvio_app/features/menu/presentation/blocked_user_cubit/blocked_users_state.dart';
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:network_image_mock/network_image_mock.dart';
|
||||
|
||||
import 'empty_chat_screen_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<BlockedUsersCubit>()])
|
||||
@GenerateMocks([ChatRepository])
|
||||
void main() {
|
||||
group('EmptyChatScreen smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await sl.reset();
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp.router(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
routerConfig: GoRouter(
|
||||
initialLocation: '/',
|
||||
routes: [
|
||||
GoRoute(path: '/', builder: (context, state) => child),
|
||||
GoRoute(path: '/profile/:slug', name: 'profileScreen', builder: (context, state) => const SizedBox.shrink()),
|
||||
GoRoute(path: '/chat/:uuid', name: 'chatScreen', builder: (context, state) => const SizedBox.shrink()),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders empty chat screen', (tester) async {
|
||||
final blockedUsersCubit = MockBlockedUsersCubit();
|
||||
final chatRepository = MockChatRepository();
|
||||
const blockedState = BlockedUsersStateLoaded(profilesList: []);
|
||||
|
||||
when(blockedUsersCubit.state).thenReturn(blockedState);
|
||||
when(blockedUsersCubit.stream).thenAnswer((_) => Stream.value(blockedState));
|
||||
when(blockedUsersCubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(blockedUsersCubit.getBlockedUsers()).thenAnswer((_) async => Future<void>.value());
|
||||
when(chatRepository.sendMessage(data: anyNamed('data'), slug: anyNamed('slug'))).thenAnswer((_) async => throw UnimplementedError());
|
||||
when(chatRepository.getChatByUserSlug(any)).thenAnswer((_) async => 'test-uuid');
|
||||
|
||||
sl.registerLazySingleton<BlockedUsersCubit>(() => blockedUsersCubit);
|
||||
sl.registerLazySingleton<ChatRepository>(() => chatRepository);
|
||||
|
||||
const user = ProfileModel(
|
||||
id: 1,
|
||||
slug: 'test-user',
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: 'https://example.com/photo.jpg',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
|
||||
await mockNetworkImagesFor(() async {
|
||||
await tester.pumpWidget(wrap(const EmptyChatScreen(user: user)));
|
||||
await tester.pump();
|
||||
});
|
||||
|
||||
expect(find.byType(EmptyChatScreen), findsOneWidget);
|
||||
expect(find.text('Test User'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user