forked from eatvio/eatvio_app
chore(dependencies): add webview_flutter_platform_interface package to pubspec.yaml and clean up test files by removing unnecessary whitespace
This commit is contained in:
@@ -0,0 +1,164 @@
|
||||
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/menu/presentation/blocked_user_cubit/blocked_users_cubit.dart';
|
||||
import 'package:eatvio_app/features/menu/presentation/widgets/blocked_user_widget.dart';
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.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 'blocked_user_widget_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<BlockedUsersCubit>()])
|
||||
void main() {
|
||||
group('BlockedUserWidget', () {
|
||||
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'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(ProfileModel profile, BlockedUsersCubit cubit) {
|
||||
return MaterialApp.router(
|
||||
theme: ThemeHelper().themeData(),
|
||||
routerConfig: GoRouter(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => BlocProvider<BlockedUsersCubit>(
|
||||
create: (_) => cubit,
|
||||
child: Scaffold(body: BlockedUserWidget(profile: profile)),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/profile',
|
||||
name: 'profileScreen',
|
||||
builder: (context, state) => Scaffold(body: Text('Profile: ${state.extra}')),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays profile name correctly', (WidgetTester tester) async {
|
||||
await mockNetworkImagesFor(() async {
|
||||
final mockCubit = MockBlockedUsersCubit();
|
||||
const profile = ProfileModel(
|
||||
id: 1,
|
||||
name: 'Blocked User',
|
||||
email: 'blocked@example.com',
|
||||
ratingPlace: null,
|
||||
emailVerifiedAt: null,
|
||||
phoneConfirmationState: 'confirmed',
|
||||
createdAt: null,
|
||||
updatedAt: null,
|
||||
isPublicProfile: false,
|
||||
isBlockedByMe: true,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
slug: 'blocked-user',
|
||||
profilePhotoUrl: '/photo.jpg',
|
||||
roles: ['user'],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
educationResource: null,
|
||||
diplomasAndCertificates: null,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(profile, mockCubit));
|
||||
await tester.pump(); // Initial frame
|
||||
await tester.pump(); // Allow image loading to start
|
||||
|
||||
expect(find.text('Blocked User'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('displays unblock button', (WidgetTester tester) async {
|
||||
await mockNetworkImagesFor(() async {
|
||||
final mockCubit = MockBlockedUsersCubit();
|
||||
const profile = ProfileModel(
|
||||
id: 1,
|
||||
name: 'User',
|
||||
email: 'user@example.com',
|
||||
ratingPlace: null,
|
||||
emailVerifiedAt: null,
|
||||
phoneConfirmationState: 'confirmed',
|
||||
createdAt: null,
|
||||
updatedAt: null,
|
||||
isPublicProfile: false,
|
||||
isBlockedByMe: true,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
slug: 'user',
|
||||
profilePhotoUrl: '/photo.jpg',
|
||||
roles: ['user'],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
educationResource: null,
|
||||
diplomasAndCertificates: null,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(profile, mockCubit));
|
||||
await tester.pump(); // Initial frame
|
||||
await tester.pump(); // Allow image loading to start
|
||||
|
||||
expect(find.text('Убрать'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('calls unblockUser when unblock button is tapped', (WidgetTester tester) async {
|
||||
await mockNetworkImagesFor(() async {
|
||||
final mockCubit = MockBlockedUsersCubit();
|
||||
when(mockCubit.unblockUser(any)).thenAnswer((_) => Future.value());
|
||||
|
||||
const profile = ProfileModel(
|
||||
id: 1,
|
||||
name: 'User',
|
||||
email: 'user@example.com',
|
||||
ratingPlace: null,
|
||||
emailVerifiedAt: null,
|
||||
phoneConfirmationState: 'confirmed',
|
||||
createdAt: null,
|
||||
updatedAt: null,
|
||||
isPublicProfile: false,
|
||||
isBlockedByMe: true,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
slug: 'test-user',
|
||||
profilePhotoUrl: '/photo.jpg',
|
||||
roles: ['user'],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
educationResource: null,
|
||||
diplomasAndCertificates: null,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(profile, mockCubit));
|
||||
await tester.pump(); // Initial frame
|
||||
await tester.pump(); // Allow image loading to start
|
||||
|
||||
await tester.tap(find.text('Убрать'));
|
||||
await tester.pump(); // Process tap
|
||||
await tester.pump(); // Allow async operations
|
||||
|
||||
verify(mockCubit.unblockUser('test-user')).called(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user