forked from eatvio/eatvio_app
chore(version): update app version to 1.3.5+85 and improve test coverage reporting in CI
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/di/app_config_registration.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/sub_cubit/sub_cubit.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/sub_cubit/sub_state.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/widgets/sub_action_button_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'sub_action_button_widget_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([
|
||||
MockSpec<SubCubit>(),
|
||||
MockSpec<ProfileCubit>(),
|
||||
])
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
group('SubActionButtonWidget', () {
|
||||
late MockSubCubit mockSubCubit;
|
||||
late MockProfileCubit mockProfileCubit;
|
||||
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
AppConfigRegistration.registerAppConfig(buildType: AppBuildType.tests);
|
||||
mockSubCubit = MockSubCubit();
|
||||
mockProfileCubit = MockProfileCubit();
|
||||
sl.registerLazySingleton<SubCubit>(() => mockSubCubit);
|
||||
sl.registerLazySingleton<ProfileCubit>(() => mockProfileCubit);
|
||||
});
|
||||
|
||||
Widget createTestWidget(SubActionType actionType) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider<SubCubit>.value(value: mockSubCubit),
|
||||
BlocProvider<ProfileCubit>.value(value: mockProfileCubit),
|
||||
],
|
||||
child: Scaffold(
|
||||
body: SubActionButtonWidget(
|
||||
subActionType: actionType,
|
||||
slug: 'test-slug',
|
||||
name: 'Test User',
|
||||
porfileIcon: 'https://example.com/icon.jpg',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays subscribe button when action type is subscribe', (tester) async {
|
||||
|
||||
await tester.pumpWidget(createTestWidget(SubActionType.subscribe));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SubActionButtonWidget), findsOneWidget);
|
||||
expect(find.text('Подписаться'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays message button when action type is sendMessage', (tester) async {
|
||||
|
||||
await tester.pumpWidget(createTestWidget(SubActionType.sendMessage));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SubActionButtonWidget), findsOneWidget);
|
||||
expect(find.text('Сообщение'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('calls subscribe when subscribe button is tapped', (tester) async {
|
||||
when(mockSubCubit.state).thenReturn(const SubState());
|
||||
when(mockSubCubit.stream).thenAnswer((_) => Stream.value(const SubState()));
|
||||
when(mockSubCubit.subscribe(any)).thenAnswer((_) async {});
|
||||
|
||||
await tester.pumpWidget(createTestWidget(SubActionType.subscribe));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Подписаться'));
|
||||
await tester.pump();
|
||||
|
||||
verify(mockSubCubit.subscribe('test-slug')).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user