forked from eatvio/eatvio_app
Merge branch 'mso7nueh-main'
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:eatvio_app/features/auth/entities/auth_result_entity.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:vk_id/vk_id.dart';
|
||||
|
||||
void main() {
|
||||
group('AuthResultEntity', () {
|
||||
@@ -100,5 +101,21 @@ void main() {
|
||||
expect(GenderEnum.female, isNotNull);
|
||||
expect(GenderEnum.notSet, isNotNull);
|
||||
});
|
||||
|
||||
test('fromVkGender returns correct enum for VkSex.male', () {
|
||||
expect(GenderEnum.fromVkGender(VkSex.male), GenderEnum.male);
|
||||
});
|
||||
|
||||
test('fromVkGender returns correct enum for VkSex.female', () {
|
||||
expect(GenderEnum.fromVkGender(VkSex.female), GenderEnum.female);
|
||||
});
|
||||
|
||||
test('fromVkGender returns correct enum for VkSex.notStated', () {
|
||||
expect(GenderEnum.fromVkGender(VkSex.notStated), GenderEnum.notSet);
|
||||
});
|
||||
|
||||
test('fromVkGender returns null for null VkSex', () {
|
||||
expect(GenderEnum.fromVkGender(null), null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -123,6 +123,200 @@ void main() {
|
||||
// Состояние должно быть error из-за ошибки загрузки профиля
|
||||
expect(cubit!.state, isA<ProfileAvatarStateError>());
|
||||
});
|
||||
|
||||
test('getMyProfile - обработка ошибки при получении деталей профиля', () async {
|
||||
cubit = ProfileAvatarCubit(profileRepository: mockRepository);
|
||||
|
||||
const testProfile = 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/icon.jpg',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
|
||||
when(mockRepository.getMyProfile())
|
||||
.thenAnswer((_) async => testProfile);
|
||||
when(mockRepository.getMyProfileDetails())
|
||||
.thenThrow(Exception('Ошибка загрузки деталей'));
|
||||
|
||||
await cubit!.getMyProfile();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
// Если детали не загрузились, выбрасывается исключение и состояние становится error
|
||||
expect(cubit!.state, isA<ProfileAvatarStateError>());
|
||||
});
|
||||
|
||||
test('getMyProfile - обработка ошибки при получении профиля', () async {
|
||||
cubit = ProfileAvatarCubit(profileRepository: mockRepository);
|
||||
|
||||
when(mockRepository.getMyProfile())
|
||||
.thenThrow(Exception('Ошибка загрузки профиля'));
|
||||
|
||||
await cubit!.getMyProfile();
|
||||
|
||||
// Состояние должно быть error
|
||||
expect(cubit!.state, isA<ProfileAvatarStateError>());
|
||||
final errorState = cubit!.state as ProfileAvatarStateError;
|
||||
expect(errorState.errorMessage, contains('Ошибка загрузки профиля'));
|
||||
});
|
||||
|
||||
test('getMyProfile - успешная загрузка с женским полом', () async {
|
||||
cubit = ProfileAvatarCubit(profileRepository: mockRepository);
|
||||
|
||||
const testProfile = 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/icon.jpg',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
|
||||
const testProfileDetails = ProfileDetailsModel(
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'female',
|
||||
country: 'Russia',
|
||||
city: 'Moscow',
|
||||
lang: 'ru',
|
||||
weight: 60.0,
|
||||
height: 165,
|
||||
chestCircumference: 90,
|
||||
waistCircumference: 70,
|
||||
hipCircumference: 95,
|
||||
bloodPressureUp: 110,
|
||||
bloodPressureDown: 70,
|
||||
hasHypo: false,
|
||||
hasHyper: false,
|
||||
aboutAlergy: 'No allergies',
|
||||
aboutTakingPils: 'No pills',
|
||||
aboutSportHobbies: 'Yoga',
|
||||
favoriteFoods: 'Vegetables',
|
||||
unfavoriteFoods: 'Meat',
|
||||
additionalInfo: 'Additional info',
|
||||
isMoodFillable: true,
|
||||
isBedtimeFillable: true,
|
||||
activityCoefficient: 1.2,
|
||||
);
|
||||
|
||||
when(mockRepository.getMyProfile())
|
||||
.thenAnswer((_) async => testProfile);
|
||||
when(mockRepository.getMyProfileDetails())
|
||||
.thenAnswer((_) async => testProfileDetails);
|
||||
|
||||
ProfileAvatarState? loadedState;
|
||||
final subscription = cubit!.stream.listen((state) {
|
||||
if (state is ProfileAvatarStateLoaded) {
|
||||
loadedState = state;
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
await cubit!.getMyProfile();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
} catch (e) {
|
||||
// Игнорируем ошибки плагинов
|
||||
} finally {
|
||||
await subscription.cancel();
|
||||
}
|
||||
|
||||
expect(loadedState, isNotNull);
|
||||
});
|
||||
|
||||
test('getMyProfile - успешная загрузка с различными форматами даты рождения', () async {
|
||||
cubit = ProfileAvatarCubit(profileRepository: mockRepository);
|
||||
|
||||
const testProfile = 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/icon.jpg',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
|
||||
// Тест с датой рождения в будущем (для проверки расчета возраста)
|
||||
const testProfileDetails = ProfileDetailsModel(
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
birthdate: '2000-06-15',
|
||||
gender: 'male',
|
||||
country: 'Russia',
|
||||
city: 'Moscow',
|
||||
lang: 'ru',
|
||||
weight: 70.0,
|
||||
height: 175,
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: false,
|
||||
hasHyper: false,
|
||||
aboutAlergy: 'No allergies',
|
||||
aboutTakingPils: 'No pills',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Fruits',
|
||||
unfavoriteFoods: 'Fast food',
|
||||
additionalInfo: 'Additional info',
|
||||
isMoodFillable: true,
|
||||
isBedtimeFillable: true,
|
||||
activityCoefficient: 1.5,
|
||||
);
|
||||
|
||||
when(mockRepository.getMyProfile())
|
||||
.thenAnswer((_) async => testProfile);
|
||||
when(mockRepository.getMyProfileDetails())
|
||||
.thenAnswer((_) async => testProfileDetails);
|
||||
|
||||
ProfileAvatarState? loadedState;
|
||||
final subscription = cubit!.stream.listen((state) {
|
||||
if (state is ProfileAvatarStateLoaded) {
|
||||
loadedState = state;
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
await cubit!.getMyProfile();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
} catch (e) {
|
||||
// Игнорируем ошибки плагинов
|
||||
} finally {
|
||||
await subscription.cancel();
|
||||
}
|
||||
|
||||
expect(loadedState, isNotNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
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/core/widgets/loader.dart';
|
||||
import 'package:eatvio_app/features/consultant_rating/models/rating_model.dart';
|
||||
import 'package:eatvio_app/features/consultant_rating/presentation/widgets/rating_history_widget.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
|
||||
void main() {
|
||||
group('RatingHistoryWidget', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Portal(
|
||||
child: Scaffold(body: SingleChildScrollView(child: child)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display loader when isLoading is true', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const widget = RatingHistoryWidget(isLoading: true, ratingHistory: []);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Loader), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display rating history items when isLoading is false', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final ratingHistory = [
|
||||
RatingModel(
|
||||
type: RatingEnum.addedRecipe,
|
||||
amount: 10,
|
||||
date: DateTime(2024, 1, 1),
|
||||
),
|
||||
RatingModel(
|
||||
type: RatingEnum.addedBlogPost,
|
||||
amount: 5,
|
||||
date: DateTime(2024, 1, 2),
|
||||
),
|
||||
];
|
||||
final widget = RatingHistoryWidget(isLoading: false, ratingHistory: ratingHistory);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Loader), findsNothing);
|
||||
expect(find.byType(ListView), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display empty list when ratingHistory is empty', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const widget = RatingHistoryWidget(isLoading: false, ratingHistory: []);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Loader), findsNothing);
|
||||
expect(find.byType(ListView), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display all rating types correctly', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final ratingHistory = [
|
||||
RatingModel(type: RatingEnum.addedRecipe, amount: 1, date: DateTime.now()),
|
||||
RatingModel(type: RatingEnum.addedPublicDiet, amount: 2, date: DateTime.now()),
|
||||
RatingModel(type: RatingEnum.addedBlogPost, amount: 3, date: DateTime.now()),
|
||||
RatingModel(type: RatingEnum.invitedUser, amount: 4, date: DateTime.now()),
|
||||
RatingModel(type: RatingEnum.hasMedicalDegree, amount: 5, date: DateTime.now()),
|
||||
RatingModel(type: RatingEnum.consulted, amount: 6, date: DateTime.now()),
|
||||
RatingModel(type: RatingEnum.addedGlossary, amount: 7, date: DateTime.now()),
|
||||
];
|
||||
final widget = RatingHistoryWidget(isLoading: false, ratingHistory: ratingHistory);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(ListView), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
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/core/widgets/loader.dart';
|
||||
import 'package:eatvio_app/features/consultant_rating/models/statistics_model.dart';
|
||||
import 'package:eatvio_app/features/consultant_rating/presentation/widgets/statistic_widget.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
|
||||
void main() {
|
||||
group('StatisticWidget', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Portal(
|
||||
child: Scaffold(body: SingleChildScrollView(child: child)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display loader when isLoading is true', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const widget = StatisticWidget(isLoading: true, statistics: null);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Loader), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display statistics when isLoading is false and statistics provided', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final statistics = StatisticsModel(
|
||||
countReferal: 10,
|
||||
blogPostsCount: 5,
|
||||
recipesCount: 3,
|
||||
dietsCount: 2,
|
||||
consultationsCount: 8,
|
||||
qwe: 1,
|
||||
);
|
||||
final widget = StatisticWidget(isLoading: false, statistics: statistics);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Loader), findsNothing);
|
||||
expect(find.text('10'), findsOneWidget);
|
||||
expect(find.text('5'), findsOneWidget);
|
||||
expect(find.text('3'), findsOneWidget);
|
||||
expect(find.text('2'), findsOneWidget);
|
||||
expect(find.text('8'), findsOneWidget);
|
||||
expect(find.text('1'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display zeros when statistics is null', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const widget = StatisticWidget(isLoading: false, statistics: null);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Loader), findsNothing);
|
||||
expect(find.text('0'), findsNWidgets(6));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/core/enums/filters_comparison_enum.dart';
|
||||
import 'package:eatvio_app/features/consultations/models/consultation_model.dart';
|
||||
import 'package:eatvio_app/features/consultations/services/consultation_service.dart';
|
||||
import 'package:eatvio_app/features/finances_and_consultations_archive/models/consultant_finance_model.dart';
|
||||
@@ -6,89 +8,281 @@ import 'package:eatvio_app/features/finances_and_consultations_archive/models/us
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../../fixtures/fixture_reader.dart';
|
||||
import 'consultation_service_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<Dio>()])
|
||||
@GenerateMocks([Dio])
|
||||
void main() {
|
||||
group('ConsultationService', () {
|
||||
late ConsultationService consultationService;
|
||||
late ConsultationService service;
|
||||
late MockDio mockDio;
|
||||
|
||||
setUp(() {
|
||||
mockDio = MockDio();
|
||||
consultationService = ConsultationService(mockDio);
|
||||
service = ConsultationService(mockDio);
|
||||
});
|
||||
|
||||
test('getConsultations - возвращает список консультаций', () async {
|
||||
final json = FixtureReader.readAsMap('consultations/consultation_pagination_response.json');
|
||||
final response = Response(
|
||||
data: json,
|
||||
statusCode: 200,
|
||||
requestOptions: RequestOptions(path: '/api/consultations'),
|
||||
test('getConsultations - успешное получение консультаций', () async {
|
||||
final mockData = {
|
||||
'data': [],
|
||||
'links': {},
|
||||
'meta': {'current_page': 1, 'last_page': 1, 'total': 0, 'per_page': 10},
|
||||
};
|
||||
|
||||
when(mockDio.get('/api/consultations', queryParameters: anyNamed('queryParameters'))).thenAnswer(
|
||||
(_) async => Response(
|
||||
requestOptions: RequestOptions(path: '/api/consultations'),
|
||||
statusCode: 200,
|
||||
data: mockData,
|
||||
),
|
||||
);
|
||||
|
||||
when(mockDio.get(any, queryParameters: anyNamed('queryParameters')))
|
||||
.thenAnswer((_) async => response);
|
||||
|
||||
final result = await consultationService.getConsultations();
|
||||
final result = await service.getConsultations();
|
||||
|
||||
expect(result, isA<ConsultationPaginationModel>());
|
||||
expect(result.data.length, 1);
|
||||
verify(mockDio.get(any, queryParameters: anyNamed('queryParameters'))).called(1);
|
||||
verify(
|
||||
mockDio.get(
|
||||
'/api/consultations',
|
||||
queryParameters: {
|
||||
'filters[last_state][\$notIn][]': const [
|
||||
'initied',
|
||||
'in_coordination',
|
||||
'start_date_has_been_set',
|
||||
'pending_payment',
|
||||
'canceled_by_the_initiator',
|
||||
'charge_was_collected',
|
||||
],
|
||||
'sort[]': 'created_at:desc',
|
||||
},
|
||||
),
|
||||
).called(1);
|
||||
});
|
||||
|
||||
test('getStatistics - возвращает статистику', () async {
|
||||
final json = FixtureReader.readAsMap('consultations/statistic_response.json');
|
||||
final response = Response(
|
||||
data: json,
|
||||
statusCode: 200,
|
||||
requestOptions: RequestOptions(path: '/api/consultations/statistics'),
|
||||
test('getConsultations - пробрасывает ошибку', () async {
|
||||
when(mockDio.get(any, queryParameters: anyNamed('queryParameters'))).thenThrow(DioException(requestOptions: RequestOptions(path: '/api/consultations')));
|
||||
|
||||
expect(() => service.getConsultations(), throwsA(isA<DioException>()));
|
||||
});
|
||||
|
||||
test('getFilteredConsultations - успешное получение с фильтрами notInArray', () async {
|
||||
final mockData = {
|
||||
'data': [],
|
||||
'links': {},
|
||||
'meta': {'current_page': 1, 'last_page': 1, 'total': 0, 'per_page': 10},
|
||||
};
|
||||
|
||||
when(mockDio.get('/api/consultations', queryParameters: anyNamed('queryParameters'))).thenAnswer(
|
||||
(_) async => Response(
|
||||
requestOptions: RequestOptions(path: '/api/consultations'),
|
||||
statusCode: 200,
|
||||
data: mockData,
|
||||
),
|
||||
);
|
||||
|
||||
when(mockDio.get(any))
|
||||
.thenAnswer((_) async => response);
|
||||
final result = await service.getFilteredConsultations(stateComparison: FiltersComparisonEnum.notInArray);
|
||||
|
||||
final result = await consultationService.getStatistics();
|
||||
expect(result, isA<ConsultationPaginationModel>());
|
||||
verify(
|
||||
mockDio.get(
|
||||
'/api/consultations',
|
||||
queryParameters: {
|
||||
'filters[last_state][\$notIn][]': const [
|
||||
'initied',
|
||||
'in_coordination',
|
||||
'start_date_has_been_set',
|
||||
'pending_payment',
|
||||
'canceled_by_the_initiator',
|
||||
'charge_was_collected',
|
||||
],
|
||||
'sort[]': 'created_at:desc',
|
||||
},
|
||||
),
|
||||
).called(1);
|
||||
});
|
||||
|
||||
test('getFilteredConsultations - успешное получение с фильтром state', () async {
|
||||
final mockData = {
|
||||
'data': [],
|
||||
'links': {},
|
||||
'meta': {'current_page': 1, 'last_page': 1, 'total': 0, 'per_page': 10},
|
||||
};
|
||||
|
||||
when(mockDio.get('/api/consultations', queryParameters: anyNamed('queryParameters'))).thenAnswer(
|
||||
(_) async => Response(
|
||||
requestOptions: RequestOptions(path: '/api/consultations'),
|
||||
statusCode: 200,
|
||||
data: mockData,
|
||||
),
|
||||
);
|
||||
|
||||
final result = await service.getFilteredConsultations(state: 'done', stateComparison: FiltersComparisonEnum.equal);
|
||||
|
||||
expect(result, isA<ConsultationPaginationModel>());
|
||||
verify(mockDio.get('/api/consultations', queryParameters: {'filters[last_state][\$eq]': 'done', 'sort[]': 'created_at:desc'})).called(1);
|
||||
});
|
||||
|
||||
test('getFilteredConsultations - успешное получение с фильтром date', () async {
|
||||
final mockData = {
|
||||
'data': [],
|
||||
'links': {},
|
||||
'meta': {'current_page': 1, 'last_page': 1, 'total': 0, 'per_page': 10},
|
||||
};
|
||||
|
||||
when(mockDio.get('/api/consultations', queryParameters: anyNamed('queryParameters'))).thenAnswer(
|
||||
(_) async => Response(
|
||||
requestOptions: RequestOptions(path: '/api/consultations'),
|
||||
statusCode: 200,
|
||||
data: mockData,
|
||||
),
|
||||
);
|
||||
|
||||
final result = await service.getFilteredConsultations(date: '2024-01-01', dateComparison: FiltersComparisonEnum.greaterThan);
|
||||
|
||||
expect(result, isA<ConsultationPaginationModel>());
|
||||
verify(mockDio.get('/api/consultations', queryParameters: {'filters[start_date][\$gt]': '2024-01-01', 'sort[]': 'created_at:desc'})).called(1);
|
||||
});
|
||||
|
||||
test('getFilteredConsultations - пробрасывает ошибку', () async {
|
||||
when(mockDio.get(any, queryParameters: anyNamed('queryParameters'))).thenThrow(DioException(requestOptions: RequestOptions(path: '/api/consultations')));
|
||||
|
||||
expect(() => service.getFilteredConsultations(), throwsA(isA<DioException>()));
|
||||
});
|
||||
|
||||
test('getStatistics - успешное получение статистики', () async {
|
||||
final mockData = {'total': 10, 'in_progress': 5, 'finished': 3, 'canceled': 2};
|
||||
|
||||
when(mockDio.get('/api/consultations/statistics')).thenAnswer(
|
||||
(_) async => Response(
|
||||
requestOptions: RequestOptions(path: '/api/consultations/statistics'),
|
||||
statusCode: 200,
|
||||
data: mockData,
|
||||
),
|
||||
);
|
||||
|
||||
final result = await service.getStatistics();
|
||||
|
||||
expect(result, isA<StatisticModel>());
|
||||
expect(result.total, 10);
|
||||
verify(mockDio.get(any)).called(1);
|
||||
expect(result.inProgress, 5);
|
||||
expect(result.finished, 3);
|
||||
expect(result.canceled, 2);
|
||||
verify(mockDio.get('/api/consultations/statistics')).called(1);
|
||||
});
|
||||
|
||||
test('getConsultantFinances - возвращает финансы консультанта', () async {
|
||||
final response = Response(
|
||||
data: {'data': []},
|
||||
statusCode: 200,
|
||||
requestOptions: RequestOptions(path: '/api/finances/my_finances'),
|
||||
test('getStatistics - пробрасывает ошибку', () async {
|
||||
when(mockDio.get('/api/consultations/statistics')).thenThrow(DioException(requestOptions: RequestOptions(path: '/api/consultations/statistics')));
|
||||
|
||||
expect(() => service.getStatistics(), throwsA(isA<DioException>()));
|
||||
});
|
||||
|
||||
test('getConsultantFinances - успешное получение финансов', () async {
|
||||
final mockData = {
|
||||
'data': [
|
||||
{
|
||||
'start_date': '2024-01-01T00:00:00Z',
|
||||
'bank_id': 'bank-1',
|
||||
'title': 'Consultation',
|
||||
'clientName': 'Client Name',
|
||||
'duration': 60,
|
||||
'payment_price': 100000,
|
||||
'payment_status': 'COMPLETED',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
when(mockDio.get('/api/finances/my_finances', queryParameters: anyNamed('queryParameters'))).thenAnswer(
|
||||
(_) async => Response(
|
||||
requestOptions: RequestOptions(path: '/api/finances/my_finances'),
|
||||
statusCode: 200,
|
||||
data: mockData,
|
||||
),
|
||||
);
|
||||
|
||||
when(mockDio.get(any, queryParameters: anyNamed('queryParameters')))
|
||||
.thenAnswer((_) async => response);
|
||||
|
||||
final result = await consultationService.getConsultantFinances(null, null);
|
||||
final result = await service.getConsultantFinances(null, null);
|
||||
|
||||
expect(result, isA<List<ConsultantFinanceModel>>());
|
||||
verify(mockDio.get(any, queryParameters: anyNamed('queryParameters'))).called(1);
|
||||
expect(result.length, 1);
|
||||
verify(mockDio.get('/api/finances/my_finances', queryParameters: {'sort[]': 'start_date:desc'})).called(1);
|
||||
});
|
||||
|
||||
test('getUserPurchases - возвращает покупки пользователя', () async {
|
||||
final response = Response(
|
||||
data: {'data': []},
|
||||
statusCode: 200,
|
||||
requestOptions: RequestOptions(path: '/api/finances/my_purchases'),
|
||||
test('getConsultantFinances - успешное получение с фильтром date', () async {
|
||||
final mockData = {'data': []};
|
||||
|
||||
when(mockDio.get('/api/finances/my_finances', queryParameters: anyNamed('queryParameters'))).thenAnswer(
|
||||
(_) async => Response(
|
||||
requestOptions: RequestOptions(path: '/api/finances/my_finances'),
|
||||
statusCode: 200,
|
||||
data: mockData,
|
||||
),
|
||||
);
|
||||
|
||||
when(mockDio.get(any, queryParameters: anyNamed('queryParameters')))
|
||||
.thenAnswer((_) async => response);
|
||||
final result = await service.getConsultantFinances('2024-01-01', FiltersComparisonEnum.equal);
|
||||
|
||||
final result = await consultationService.getUserPurchases(null, null);
|
||||
expect(result, isA<List<ConsultantFinanceModel>>());
|
||||
verify(mockDio.get('/api/finances/my_finances', queryParameters: {'filters[start_date][\$eq]': '2024-01-01', 'sort[]': 'start_date:desc'})).called(1);
|
||||
});
|
||||
|
||||
test('getConsultantFinances - пробрасывает ошибку', () async {
|
||||
when(
|
||||
mockDio.get(any, queryParameters: anyNamed('queryParameters')),
|
||||
).thenThrow(DioException(requestOptions: RequestOptions(path: '/api/finances/my_finances')));
|
||||
|
||||
expect(() => service.getConsultantFinances(null, null), throwsA(isA<DioException>()));
|
||||
});
|
||||
|
||||
test('getUserPurchases - успешное получение покупок', () async {
|
||||
final mockData = {
|
||||
'data': [
|
||||
{
|
||||
'start_date': '2024-01-01T00:00:00Z',
|
||||
'bank_id': 'bank-1',
|
||||
'title': 'Plan Title',
|
||||
'consultantName': 'Consultant Name',
|
||||
'duration': 30,
|
||||
'price': 1000,
|
||||
'chosen_plan_last_state': 'paid',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
when(mockDio.get('/api/finances/my_purchases', queryParameters: anyNamed('queryParameters'))).thenAnswer(
|
||||
(_) async => Response(
|
||||
requestOptions: RequestOptions(path: '/api/finances/my_purchases'),
|
||||
statusCode: 200,
|
||||
data: mockData,
|
||||
),
|
||||
);
|
||||
|
||||
final result = await service.getUserPurchases(null, null);
|
||||
|
||||
expect(result, isA<List<UserPurchasesModel>>());
|
||||
verify(mockDio.get(any, queryParameters: anyNamed('queryParameters'))).called(1);
|
||||
expect(result.length, 1);
|
||||
verify(mockDio.get('/api/finances/my_purchases', queryParameters: {'sort[]': 'start_date:desc'})).called(1);
|
||||
});
|
||||
|
||||
test('getUserPurchases - успешное получение с фильтром date', () async {
|
||||
final mockData = {'data': []};
|
||||
|
||||
when(mockDio.get('/api/finances/my_purchases', queryParameters: anyNamed('queryParameters'))).thenAnswer(
|
||||
(_) async => Response(
|
||||
requestOptions: RequestOptions(path: '/api/finances/my_purchases'),
|
||||
statusCode: 200,
|
||||
data: mockData,
|
||||
),
|
||||
);
|
||||
|
||||
final result = await service.getUserPurchases('2024-01-01', FiltersComparisonEnum.greaterThan);
|
||||
|
||||
expect(result, isA<List<UserPurchasesModel>>());
|
||||
verify(mockDio.get('/api/finances/my_purchases', queryParameters: {'filters[start_date][\$gt]': '2024-01-01', 'sort[]': 'start_date:desc'})).called(1);
|
||||
});
|
||||
|
||||
test('getUserPurchases - пробрасывает ошибку', () async {
|
||||
when(
|
||||
mockDio.get(any, queryParameters: anyNamed('queryParameters')),
|
||||
).thenThrow(DioException(requestOptions: RequestOptions(path: '/api/finances/my_purchases')));
|
||||
|
||||
expect(() => service.getUserPurchases(null, null), throwsA(isA<DioException>()));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -66,3 +66,8 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -75,3 +75,8 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -53,3 +53,8 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -48,3 +48,8 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -85,3 +85,8 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -37,3 +37,8 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
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/core/widgets/custom_outlined_button.dart';
|
||||
import 'package:eatvio_app/features/diets/presentation/cubit/about_diet_cubit.dart';
|
||||
import 'package:eatvio_app/features/diets/presentation/widgets/cancel_diet_bottom_sheet.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
|
||||
import 'cancel_diet_bottom_sheet_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<AboutDietCubit>()])
|
||||
void main() {
|
||||
group('CancelDietBottomSheet', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child, AboutDietCubit cubit) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Portal(
|
||||
child: BlocProvider<AboutDietCubit>(
|
||||
create: (_) => cubit,
|
||||
child: Scaffold(body: child),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display cancel diet bottom sheet with default title', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockAboutDietCubit();
|
||||
final widget = CancelDietBottomSheet(
|
||||
aboutDietCubit: mockCubit,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget, mockCubit));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(CancelDietBottomSheet), findsOneWidget);
|
||||
expect(find.byType(CustomOutlinedButton), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display cancel diet bottom sheet with custom title', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockAboutDietCubit();
|
||||
final widget = CancelDietBottomSheet(
|
||||
aboutDietCubit: mockCubit,
|
||||
title: 'Custom title',
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget, mockCubit));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(CancelDietBottomSheet), findsOneWidget);
|
||||
expect(find.text('Custom title'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display cancel diet bottom sheet with diet name', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockAboutDietCubit();
|
||||
final widget = CancelDietBottomSheet(
|
||||
aboutDietCubit: mockCubit,
|
||||
dietName: 'Test Diet',
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget, mockCubit));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(CancelDietBottomSheet), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -103,3 +103,8 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
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/core/widgets/custom_outlined_button.dart';
|
||||
import 'package:eatvio_app/features/diets/presentation/cubit/about_diet_cubit.dart';
|
||||
import 'package:eatvio_app/features/diets/presentation/widgets/start_diet_bottom_sheet.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
|
||||
import 'start_diet_bottom_sheet_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<AboutDietCubit>()])
|
||||
void main() {
|
||||
group('StartDietBottomSheet', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child, AboutDietCubit cubit) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Portal(
|
||||
child: BlocProvider<AboutDietCubit>(
|
||||
create: (_) => cubit,
|
||||
child: Scaffold(body: child),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display start diet bottom sheet', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockAboutDietCubit();
|
||||
final widget = StartDietBottomSheet(
|
||||
aboutDietCubit: mockCubit,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget, mockCubit));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(StartDietBottomSheet), findsOneWidget);
|
||||
expect(find.byType(CustomOutlinedButton), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -133,3 +133,8 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -45,3 +45,8 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -53,3 +53,8 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -46,3 +46,8 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -189,6 +189,225 @@ void main() {
|
||||
|
||||
verify(mockWsManager.newNotificationsStream).called(1);
|
||||
});
|
||||
|
||||
test('loadMoreNotifications - обработка ошибки при загрузке', () async {
|
||||
final notifications = [
|
||||
ChosenPlanStartedToClientNotification(
|
||||
type: NotificationType.chosenPlanStartedToClientNotification,
|
||||
planName: 'Plan 1',
|
||||
planId: 1,
|
||||
isRead: false,
|
||||
createdAt: DateTime.now(),
|
||||
),
|
||||
];
|
||||
|
||||
when(mockNotificationsRepository.getNotifications(page: 1))
|
||||
.thenAnswer((_) async => {
|
||||
'notifications': notifications,
|
||||
'pagination': {'current_page': 1, 'last_page': 2},
|
||||
});
|
||||
|
||||
when(mockNotificationsRepository.getNotifications(page: 2))
|
||||
.thenThrow(Exception('Ошибка загрузки'));
|
||||
|
||||
await cubit.getNotifications();
|
||||
await cubit.loadMoreNotifications();
|
||||
|
||||
final state = cubit.state;
|
||||
expect(state, isA<NotificationsStateLoaded>());
|
||||
if (state is NotificationsStateLoaded) {
|
||||
expect(state.isLoadingMore, false);
|
||||
}
|
||||
});
|
||||
|
||||
test('loadMoreNotifications - не загружает если уже загружается', () async {
|
||||
final notifications = [
|
||||
ChosenPlanStartedToClientNotification(
|
||||
type: NotificationType.chosenPlanStartedToClientNotification,
|
||||
planName: 'Plan 1',
|
||||
planId: 1,
|
||||
isRead: false,
|
||||
createdAt: DateTime.now(),
|
||||
),
|
||||
];
|
||||
|
||||
when(mockNotificationsRepository.getNotifications(page: 1))
|
||||
.thenAnswer((_) async => {
|
||||
'notifications': notifications,
|
||||
'pagination': {'current_page': 1, 'last_page': 2},
|
||||
});
|
||||
|
||||
when(mockNotificationsRepository.getNotifications(page: 2))
|
||||
.thenAnswer((_) async {
|
||||
await Future.delayed(const Duration(milliseconds: 50));
|
||||
return {
|
||||
'notifications': notifications,
|
||||
'pagination': {'current_page': 2, 'last_page': 2},
|
||||
};
|
||||
});
|
||||
|
||||
await cubit.getNotifications();
|
||||
|
||||
// Вызываем loadMoreNotifications дважды быстро
|
||||
final future1 = cubit.loadMoreNotifications();
|
||||
// Небольшая задержка, чтобы первый вызов успел установить isLoadingMore
|
||||
await Future.delayed(const Duration(milliseconds: 10));
|
||||
final future2 = cubit.loadMoreNotifications();
|
||||
|
||||
await future1;
|
||||
await future2;
|
||||
|
||||
// Должен быть вызван только один раз, так как второй вызов должен быть заблокирован isLoadingMore
|
||||
verify(mockNotificationsRepository.getNotifications(page: 2)).called(1);
|
||||
});
|
||||
|
||||
test('markNotificationsAsRead - обработка ошибки', () async {
|
||||
final notifications = [
|
||||
ChosenPlanStartedToClientNotification(
|
||||
type: NotificationType.chosenPlanStartedToClientNotification,
|
||||
planName: 'Plan 1',
|
||||
planId: 1,
|
||||
isRead: false,
|
||||
createdAt: DateTime.now(),
|
||||
),
|
||||
];
|
||||
|
||||
when(mockNotificationsRepository.getNotifications(page: 1))
|
||||
.thenAnswer((_) async => {
|
||||
'notifications': notifications,
|
||||
'pagination': {'current_page': 1, 'last_page': 1},
|
||||
});
|
||||
|
||||
when(mockNotificationsRepository.markNotificationsAsRead())
|
||||
.thenThrow(Exception('Ошибка пометки'));
|
||||
|
||||
await cubit.getNotifications();
|
||||
await cubit.markNotificationsAsRead();
|
||||
|
||||
final state = cubit.state;
|
||||
expect(state, isA<NotificationsStateLoaded>());
|
||||
if (state is NotificationsStateLoaded) {
|
||||
expect(state.isLoading, false);
|
||||
}
|
||||
});
|
||||
|
||||
test('getNotifications - возвращает null от репозитория', () async {
|
||||
when(mockNotificationsRepository.getNotifications(page: 1))
|
||||
.thenAnswer((_) async => null);
|
||||
|
||||
await cubit.getNotifications();
|
||||
|
||||
// Состояние должно остаться empty
|
||||
expect(cubit.state, isA<NotificationsStateEmpty>());
|
||||
});
|
||||
|
||||
test('loadMoreNotifications - возвращает null от репозитория', () async {
|
||||
final notifications = [
|
||||
ChosenPlanStartedToClientNotification(
|
||||
type: NotificationType.chosenPlanStartedToClientNotification,
|
||||
planName: 'Plan 1',
|
||||
planId: 1,
|
||||
isRead: false,
|
||||
createdAt: DateTime.now(),
|
||||
),
|
||||
];
|
||||
|
||||
when(mockNotificationsRepository.getNotifications(page: 1))
|
||||
.thenAnswer((_) async => {
|
||||
'notifications': notifications,
|
||||
'pagination': {'current_page': 1, 'last_page': 2},
|
||||
});
|
||||
|
||||
when(mockNotificationsRepository.getNotifications(page: 2))
|
||||
.thenAnswer((_) async => null);
|
||||
|
||||
await cubit.getNotifications();
|
||||
await cubit.loadMoreNotifications();
|
||||
|
||||
final state = cubit.state;
|
||||
expect(state, isA<NotificationsStateLoaded>());
|
||||
if (state is NotificationsStateLoaded) {
|
||||
expect(state.isLoadingMore, false);
|
||||
expect(state.notifications.length, 1); // Только первая страница
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
test('getNotifications - проверяет hasUnreadNotifications', () async {
|
||||
final notifications = [
|
||||
ChosenPlanStartedToClientNotification(
|
||||
type: NotificationType.chosenPlanStartedToClientNotification,
|
||||
planName: 'Plan 1',
|
||||
planId: 1,
|
||||
isRead: false,
|
||||
createdAt: DateTime.now(),
|
||||
),
|
||||
ChosenPlanStartedToClientNotification(
|
||||
type: NotificationType.chosenPlanStartedToClientNotification,
|
||||
planName: 'Plan 2',
|
||||
planId: 2,
|
||||
isRead: true,
|
||||
createdAt: DateTime.now(),
|
||||
),
|
||||
];
|
||||
|
||||
final result = {
|
||||
'notifications': notifications,
|
||||
'pagination': {
|
||||
'current_page': 1,
|
||||
'last_page': 1,
|
||||
},
|
||||
};
|
||||
|
||||
when(mockNotificationsRepository.getNotifications(page: 1))
|
||||
.thenAnswer((_) async => result);
|
||||
|
||||
await cubit.getNotifications();
|
||||
|
||||
final state = cubit.state;
|
||||
expect(state, isA<NotificationsStateLoaded>());
|
||||
if (state is NotificationsStateLoaded) {
|
||||
expect(state.hasUnreadNotifications, true); // Есть непрочитанное
|
||||
}
|
||||
});
|
||||
|
||||
test('getNotifications - hasUnreadNotifications false когда все прочитаны', () async {
|
||||
final notifications = [
|
||||
ChosenPlanStartedToClientNotification(
|
||||
type: NotificationType.chosenPlanStartedToClientNotification,
|
||||
planName: 'Plan 1',
|
||||
planId: 1,
|
||||
isRead: true,
|
||||
createdAt: DateTime.now(),
|
||||
),
|
||||
ChosenPlanStartedToClientNotification(
|
||||
type: NotificationType.chosenPlanStartedToClientNotification,
|
||||
planName: 'Plan 2',
|
||||
planId: 2,
|
||||
isRead: true,
|
||||
createdAt: DateTime.now(),
|
||||
),
|
||||
];
|
||||
|
||||
final result = {
|
||||
'notifications': notifications,
|
||||
'pagination': {
|
||||
'current_page': 1,
|
||||
'last_page': 1,
|
||||
},
|
||||
};
|
||||
|
||||
when(mockNotificationsRepository.getNotifications(page: 1))
|
||||
.thenAnswer((_) async => result);
|
||||
|
||||
await cubit.getNotifications();
|
||||
|
||||
final state = cubit.state;
|
||||
expect(state, isA<NotificationsStateLoaded>());
|
||||
if (state is NotificationsStateLoaded) {
|
||||
expect(state.hasUnreadNotifications, false); // Все прочитаны
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1023,3 +1023,8 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
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/core/widgets/custom_outlined_button.dart';
|
||||
import 'package:eatvio_app/features/order_info/presentation/widgets/collect_charge_banner.dart';
|
||||
import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart';
|
||||
import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart' show PlanModel, PlanType;
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart' show Author;
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
void main() {
|
||||
group('CollectChargeBanner', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child) {
|
||||
return MaterialApp.router(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
routerConfig: GoRouter(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => Portal(
|
||||
child: Scaffold(body: SingleChildScrollView(child: child)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display collect charge banner with plan name and price', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final chosenPlan = ChosenPlanModel(
|
||||
id: 1,
|
||||
optionType: 'standard',
|
||||
startDate: DateTime.now(),
|
||||
chosenPlanState: ChosenPlanStateEnum.stateDone,
|
||||
chatId: 'chat-1',
|
||||
consultantId: 1,
|
||||
plan: const PlanModel(
|
||||
id: 1,
|
||||
slug: 'test-plan',
|
||||
name: 'Test Plan',
|
||||
image: 'test.jpg',
|
||||
duration: 30,
|
||||
state: 'active',
|
||||
type: PlanType(fit: true, slim: false, behavior: false, wellness: false),
|
||||
details: 'Test details',
|
||||
packetsCount: 1,
|
||||
author: Author(authorSlug: '', authorName: '', authorProfileIcon: '', authorIsMe: false),
|
||||
totalLikes: 0,
|
||||
totalViews: 0,
|
||||
totalComments: 0,
|
||||
isFavorite: false,
|
||||
minPriceOfOptions: 100.0,
|
||||
maxPriceOfOptions: 500.0,
|
||||
wasLikedByMe: false,
|
||||
),
|
||||
);
|
||||
const price = 1000.0;
|
||||
final widget = CollectChargeBanner(chosenPlan: chosenPlan, price: price);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(CollectChargeBanner), findsOneWidget);
|
||||
expect(find.byType(CustomOutlinedButton), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should have button that navigates to card settings', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final chosenPlan = ChosenPlanModel(
|
||||
id: 1,
|
||||
optionType: 'standard',
|
||||
startDate: DateTime.now(),
|
||||
chosenPlanState: ChosenPlanStateEnum.stateDone,
|
||||
chatId: 'chat-1',
|
||||
consultantId: 1,
|
||||
plan: const PlanModel(
|
||||
id: 1,
|
||||
slug: 'test-plan',
|
||||
name: 'Test Plan',
|
||||
image: 'test.jpg',
|
||||
duration: 30,
|
||||
state: 'active',
|
||||
type: PlanType(fit: true, slim: false, behavior: false, wellness: false),
|
||||
details: 'Test details',
|
||||
packetsCount: 1,
|
||||
author: Author(authorSlug: '', authorName: '', authorProfileIcon: '', authorIsMe: false),
|
||||
totalLikes: 0,
|
||||
totalViews: 0,
|
||||
totalComments: 0,
|
||||
isFavorite: false,
|
||||
minPriceOfOptions: 100.0,
|
||||
maxPriceOfOptions: 500.0,
|
||||
wasLikedByMe: false,
|
||||
),
|
||||
);
|
||||
const price = 1000.0;
|
||||
final widget = CollectChargeBanner(chosenPlan: chosenPlan, price: price);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert - проверяем, что кнопка существует
|
||||
expect(find.byType(CustomOutlinedButton), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
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/order_info/cubit/order_info_cubit.dart';
|
||||
import 'package:eatvio_app/features/order_info/presentation/widgets/payment_banner.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'payment_banner_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<OrderInfoCubit>()])
|
||||
void main() {
|
||||
group('PaymentBanner', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child, OrderInfoCubit cubit) {
|
||||
return MaterialApp.router(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
routerConfig: GoRouter(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => Portal(
|
||||
child: BlocProvider<OrderInfoCubit>(
|
||||
create: (_) => cubit,
|
||||
child: Scaffold(body: SingleChildScrollView(child: child)),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display payment banner with successful payment', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockOrderInfoCubit();
|
||||
const widget = PaymentBanner(successfulPayment: true);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget, mockCubit));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PaymentBanner), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display payment banner with failed payment', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockOrderInfoCubit();
|
||||
const widget = PaymentBanner(successfulPayment: false);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget, mockCubit));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PaymentBanner), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
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/order_info/presentation/widgets/plan_props.dart';
|
||||
import 'package:eatvio_app/features/order_info/presentation/widgets/plan_status_box.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
|
||||
void main() {
|
||||
group('PlanProps', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Portal(
|
||||
child: Scaffold(body: SingleChildScrollView(child: child)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display plan props with all information', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const planDuration = 30;
|
||||
const planPrice = 1000.0;
|
||||
const planStatus = PlanStatusValues.paid;
|
||||
const widget = PlanProps(
|
||||
planDuration: planDuration,
|
||||
planPrice: planPrice,
|
||||
planStatus: planStatus,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PlanProps), findsOneWidget);
|
||||
expect(find.byType(PlanStatusBox), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display plan props with pending payment status', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const planDuration = 15;
|
||||
const planPrice = 500.0;
|
||||
const planStatus = PlanStatusValues.pendingPayment;
|
||||
const widget = PlanProps(
|
||||
planDuration: planDuration,
|
||||
planPrice: planPrice,
|
||||
planStatus: planStatus,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PlanProps), findsOneWidget);
|
||||
expect(find.byType(PlanStatusBox), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display plan props with payment failed status', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const planDuration = 7;
|
||||
const planPrice = 200.0;
|
||||
const planStatus = PlanStatusValues.paymentFailed;
|
||||
const widget = PlanProps(
|
||||
planDuration: planDuration,
|
||||
planPrice: planPrice,
|
||||
planStatus: planStatus,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PlanProps), findsOneWidget);
|
||||
expect(find.byType(PlanStatusBox), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
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/order_info/presentation/widgets/plan_state.dart';
|
||||
import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
|
||||
void main() {
|
||||
group('PlanState', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Portal(
|
||||
child: Scaffold(body: SingleChildScrollView(child: child)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display plan state without personal diet', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const widget = PlanState(
|
||||
state: ChosenPlanStateEnum.statePaid,
|
||||
hasPersonalDiet: false,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PlanState), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display plan state with personal diet', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const widget = PlanState(
|
||||
state: ChosenPlanStateEnum.statePaid,
|
||||
hasPersonalDiet: true,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PlanState), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display different states correctly', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const widget = PlanState(
|
||||
state: ChosenPlanStateEnum.stateInProgress,
|
||||
hasPersonalDiet: false,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PlanState), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display done state', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const widget = PlanState(
|
||||
state: ChosenPlanStateEnum.stateDone,
|
||||
hasPersonalDiet: false,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PlanState), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display state with personal diet set', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const widget = PlanState(
|
||||
state: ChosenPlanStateEnum.personalDietSet,
|
||||
hasPersonalDiet: true,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PlanState), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,69 +5,146 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../../../fixtures/fixture_reader.dart';
|
||||
import 'personal_diet_suggestion_service_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<Dio>()])
|
||||
@GenerateMocks([Dio])
|
||||
void main() {
|
||||
group('PersonalDietSuggestionService', () {
|
||||
late PersonalDietSuggestionService personalDietSuggestionService;
|
||||
late PersonalDietSuggestionService service;
|
||||
late MockDio mockDio;
|
||||
|
||||
setUp(() {
|
||||
mockDio = MockDio();
|
||||
personalDietSuggestionService = PersonalDietSuggestionService(mockDio);
|
||||
service = PersonalDietSuggestionService(mockDio);
|
||||
});
|
||||
|
||||
test('getConsultationWithPersonalDiets - возвращает консультации с персональными диетами', () async {
|
||||
final json = FixtureReader.readAsMap('consultations/consultation_pagination_response.json');
|
||||
final response = Response(
|
||||
data: json,
|
||||
statusCode: 200,
|
||||
requestOptions: RequestOptions(path: '/api/consultations'),
|
||||
);
|
||||
test('getConsultationWithPersonalDiets - успешное получение консультаций', () async {
|
||||
final mockData = {
|
||||
'data': [],
|
||||
'links': {},
|
||||
'meta': {
|
||||
'current_page': 1,
|
||||
'last_page': 1,
|
||||
'total': 0,
|
||||
'per_page': 10,
|
||||
},
|
||||
};
|
||||
|
||||
when(mockDio.get(any, queryParameters: anyNamed('queryParameters')))
|
||||
.thenAnswer((_) async => response);
|
||||
when(mockDio.get(
|
||||
'/api/consultations',
|
||||
queryParameters: anyNamed('queryParameters'),
|
||||
)).thenAnswer((_) async => Response(
|
||||
requestOptions: RequestOptions(path: '/api/consultations'),
|
||||
statusCode: 200,
|
||||
data: mockData,
|
||||
));
|
||||
|
||||
final result = await personalDietSuggestionService.getConsultationWithPersonalDiets();
|
||||
final result = await service.getConsultationWithPersonalDiets();
|
||||
|
||||
expect(result, isA<ConsultationPaginationModel>());
|
||||
verify(mockDio.get(any, queryParameters: anyNamed('queryParameters'))).called(1);
|
||||
verify(mockDio.get(
|
||||
'/api/consultations',
|
||||
queryParameters: {
|
||||
'filters[plan][has_personal_diet][\$personal_diet]': '1',
|
||||
'filters[last_state][\$notIn][]': [
|
||||
'done',
|
||||
'charge_was_collected',
|
||||
'complained',
|
||||
'last_day_finished',
|
||||
'canceled_by_the_initiator',
|
||||
'inited'
|
||||
],
|
||||
'sort[]': 'start_date:desc',
|
||||
},
|
||||
)).called(1);
|
||||
});
|
||||
|
||||
test('attachPersonalDiet - прикрепляет персональную диету', () async {
|
||||
test('getConsultationWithPersonalDiets - пробрасывает ошибку', () async {
|
||||
when(mockDio.get(
|
||||
any,
|
||||
queryParameters: anyNamed('queryParameters'),
|
||||
)).thenThrow(DioException(
|
||||
requestOptions: RequestOptions(path: '/api/consultations'),
|
||||
));
|
||||
|
||||
expect(
|
||||
() => service.getConsultationWithPersonalDiets(),
|
||||
throwsA(isA<DioException>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('attachPersonalDiet - успешное прикрепление диеты', () async {
|
||||
const consultationId = 1;
|
||||
const dietId = 2;
|
||||
final response = Response(
|
||||
data: {},
|
||||
statusCode: 200,
|
||||
|
||||
when(mockDio.post(
|
||||
'/api/chosen_plans/$consultationId/attach_diet',
|
||||
data: anyNamed('data'),
|
||||
)).thenAnswer((_) async => Response(
|
||||
requestOptions: RequestOptions(path: '/api/chosen_plans/$consultationId/attach_diet'),
|
||||
statusCode: 200,
|
||||
));
|
||||
|
||||
await service.attachPersonalDiet(consultationId: consultationId, dietId: dietId);
|
||||
|
||||
verify(mockDio.post(
|
||||
'/api/chosen_plans/$consultationId/attach_diet',
|
||||
data: {'diet_id': dietId},
|
||||
)).called(1);
|
||||
});
|
||||
|
||||
test('attachPersonalDiet - пробрасывает ошибку', () async {
|
||||
const consultationId = 1;
|
||||
const dietId = 2;
|
||||
|
||||
when(mockDio.post(
|
||||
any,
|
||||
data: anyNamed('data'),
|
||||
)).thenThrow(DioException(
|
||||
requestOptions: RequestOptions(path: '/api/chosen_plans/$consultationId/attach_diet'),
|
||||
));
|
||||
|
||||
expect(
|
||||
() => service.attachPersonalDiet(consultationId: consultationId, dietId: dietId),
|
||||
throwsA(isA<DioException>()),
|
||||
);
|
||||
|
||||
when(mockDio.post(any, data: anyNamed('data')))
|
||||
.thenAnswer((_) async => response);
|
||||
|
||||
await personalDietSuggestionService.attachPersonalDiet(consultationId: consultationId, dietId: dietId);
|
||||
|
||||
verify(mockDio.post(any, data: anyNamed('data'))).called(1);
|
||||
});
|
||||
|
||||
test('reattachPersonalDiet - переприкрепляет персональную диету', () async {
|
||||
test('reattachPersonalDiet - успешное повторное прикрепление диеты', () async {
|
||||
const consultationId = 1;
|
||||
const dietId = 2;
|
||||
final response = Response(
|
||||
data: {},
|
||||
statusCode: 200,
|
||||
const dietId = 3;
|
||||
|
||||
when(mockDio.post(
|
||||
'/api/chosen_plans/$consultationId/re_attach_diet',
|
||||
data: anyNamed('data'),
|
||||
)).thenAnswer((_) async => Response(
|
||||
requestOptions: RequestOptions(path: '/api/chosen_plans/$consultationId/re_attach_diet'),
|
||||
statusCode: 200,
|
||||
));
|
||||
|
||||
await service.reattachPersonalDiet(consultationId: consultationId, dietId: dietId);
|
||||
|
||||
verify(mockDio.post(
|
||||
'/api/chosen_plans/$consultationId/re_attach_diet',
|
||||
data: {'diet_id': dietId},
|
||||
)).called(1);
|
||||
});
|
||||
|
||||
test('reattachPersonalDiet - пробрасывает ошибку', () async {
|
||||
const consultationId = 1;
|
||||
const dietId = 3;
|
||||
|
||||
when(mockDio.post(
|
||||
any,
|
||||
data: anyNamed('data'),
|
||||
)).thenThrow(DioException(
|
||||
requestOptions: RequestOptions(path: '/api/chosen_plans/$consultationId/re_attach_diet'),
|
||||
));
|
||||
|
||||
expect(
|
||||
() => service.reattachPersonalDiet(consultationId: consultationId, dietId: dietId),
|
||||
throwsA(isA<DioException>()),
|
||||
);
|
||||
|
||||
when(mockDio.post(any, data: anyNamed('data')))
|
||||
.thenAnswer((_) async => response);
|
||||
|
||||
await personalDietSuggestionService.reattachPersonalDiet(consultationId: consultationId, dietId: dietId);
|
||||
|
||||
verify(mockDio.post(any, data: anyNamed('data'))).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
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/profile/models/weight_model.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/widgets/imt_chart_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
|
||||
void main() {
|
||||
group('ImtChartWidget', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
await initializeDateFormatting('ru', null);
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Portal(
|
||||
child: Scaffold(body: SingleChildScrollView(child: child)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display chart with empty weight points', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const widget = ImtChartWidget(weightPoints: []);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
|
||||
// Assert
|
||||
expect(find.byType(ImtChartWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display chart with single weight point', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final weightPoints = [
|
||||
WeightModel(
|
||||
id: 1,
|
||||
userId: 1,
|
||||
weight: 70,
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
bmi: 23.5,
|
||||
),
|
||||
];
|
||||
final widget = ImtChartWidget(weightPoints: weightPoints);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
|
||||
// Assert
|
||||
expect(find.byType(ImtChartWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display chart with multiple weight points and show increase arrow', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final now = DateTime.now();
|
||||
final weightPoints = [
|
||||
WeightModel(
|
||||
id: 1,
|
||||
userId: 1,
|
||||
weight: 70,
|
||||
createdAt: now.subtract(const Duration(days: 7)),
|
||||
updatedAt: now.subtract(const Duration(days: 7)),
|
||||
bmi: 23.0,
|
||||
),
|
||||
WeightModel(
|
||||
id: 2,
|
||||
userId: 1,
|
||||
weight: 72,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
bmi: 24.0,
|
||||
),
|
||||
];
|
||||
final widget = ImtChartWidget(weightPoints: weightPoints);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
|
||||
// Assert
|
||||
expect(find.byType(ImtChartWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display chart with multiple weight points and show decrease arrow', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final now = DateTime.now();
|
||||
final weightPoints = [
|
||||
WeightModel(
|
||||
id: 1,
|
||||
userId: 1,
|
||||
weight: 72,
|
||||
createdAt: now.subtract(const Duration(days: 7)),
|
||||
updatedAt: now.subtract(const Duration(days: 7)),
|
||||
bmi: 24.0,
|
||||
),
|
||||
WeightModel(
|
||||
id: 2,
|
||||
userId: 1,
|
||||
weight: 70,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
bmi: 23.0,
|
||||
),
|
||||
];
|
||||
final widget = ImtChartWidget(weightPoints: weightPoints);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
|
||||
// Assert
|
||||
expect(find.byType(ImtChartWidget), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
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/registration/models/user_registration_model.dart';
|
||||
import 'package:eatvio_app/features/registration/presentation/bloc/registration_cubit/registration_cubit.dart';
|
||||
import 'package:eatvio_app/features/registration/presentation/pages/phone_screen.dart';
|
||||
import 'package:eatvio_app/features/registration/repositories/registration_repository.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:mockito/annotations.dart';
|
||||
import 'package:eatvio_app/core/prefs.dart';
|
||||
|
||||
import 'phone_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RegistrationRepository, Prefs])
|
||||
void main() {
|
||||
group('PhoneScreen', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child, RegistrationCubit cubit) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: BlocProvider<RegistrationCubit>(
|
||||
create: (_) => cubit,
|
||||
child: Scaffold(body: child),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display phone screen with empty phone', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockRepository = MockRegistrationRepository();
|
||||
final cubit = RegistrationCubit(
|
||||
registrationRepository: mockRepository,
|
||||
prefs: MockPrefs(),
|
||||
);
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'test@example.com',
|
||||
password: 'password',
|
||||
passwordConfirmation: 'password',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 70,
|
||||
height: 175,
|
||||
phone: '',
|
||||
chestCircumference: 90,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 95,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: '',
|
||||
aboutTakingPils: '',
|
||||
aboutSportHobbies: '',
|
||||
favoriteFoods: '',
|
||||
unfavoriteFoods: '',
|
||||
additionalInfo: '',
|
||||
);
|
||||
const widget = PhoneScreen(sheet: sheet);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget, cubit));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PhoneScreen), findsOneWidget);
|
||||
expect(find.text('Номер телефона'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display phone screen with pre-filled phone', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockRepository = MockRegistrationRepository();
|
||||
final cubit = RegistrationCubit(
|
||||
registrationRepository: mockRepository,
|
||||
prefs: MockPrefs(),
|
||||
);
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'test@example.com',
|
||||
password: 'password',
|
||||
passwordConfirmation: 'password',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 70,
|
||||
height: 175,
|
||||
phone: '+7 (999) 123 45 67',
|
||||
chestCircumference: 90,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 95,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: '',
|
||||
aboutTakingPils: '',
|
||||
aboutSportHobbies: '',
|
||||
favoriteFoods: '',
|
||||
unfavoriteFoods: '',
|
||||
additionalInfo: '',
|
||||
);
|
||||
const widget = PhoneScreen(sheet: sheet);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget, cubit));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PhoneScreen), findsOneWidget);
|
||||
expect(find.text('+7 (999) 123 45 67'), findsOneWidget);
|
||||
|
||||
cubit.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
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/registration/presentation/bloc/verify_email_cubit/verify_email_cubit.dart';
|
||||
import 'package:eatvio_app/features/registration/presentation/bloc/verify_email_cubit/verify_email_state.dart';
|
||||
import 'package:eatvio_app/features/registration/presentation/widgets/change_email_dialog.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'change_email_dialog_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<VerifyEmailCubit>()])
|
||||
void main() {
|
||||
group('ChangeEmailDialog', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => Column(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => child,
|
||||
);
|
||||
},
|
||||
child: const Text('Show Dialog'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display dialog with current email pre-filled', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockVerifyEmailCubit();
|
||||
when(mockCubit.state).thenReturn(const VerifyEmailState());
|
||||
const currentEmail = 'test@example.com';
|
||||
final widget = ChangeEmailDialog(
|
||||
currentEmail: currentEmail,
|
||||
verifyEmailCubit: mockCubit,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.tap(find.text('Show Dialog'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.text('Сменить email'), findsOneWidget);
|
||||
expect(find.text(currentEmail), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should show error for empty email', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockVerifyEmailCubit();
|
||||
when(mockCubit.state).thenReturn(const VerifyEmailState());
|
||||
const currentEmail = 'test@example.com';
|
||||
final widget = ChangeEmailDialog(
|
||||
currentEmail: currentEmail,
|
||||
verifyEmailCubit: mockCubit,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.tap(find.text('Show Dialog'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textField = find.byType(TextField);
|
||||
await tester.enterText(textField, '');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.text('Введите email'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should close dialog when Отмена button is tapped', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockVerifyEmailCubit();
|
||||
when(mockCubit.state).thenReturn(const VerifyEmailState());
|
||||
const currentEmail = 'test@example.com';
|
||||
final widget = ChangeEmailDialog(
|
||||
currentEmail: currentEmail,
|
||||
verifyEmailCubit: mockCubit,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.tap(find.text('Show Dialog'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Отмена'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.text('Сменить email'), findsNothing);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
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/registration/presentation/bloc/verify_email_cubit/verify_email_cubit.dart';
|
||||
import 'package:eatvio_app/features/registration/presentation/widgets/code_not_received_dialog.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
|
||||
import 'code_not_received_dialog_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<VerifyEmailCubit>()])
|
||||
void main() {
|
||||
group('CodeNotReceivedDialog', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => Column(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => child,
|
||||
);
|
||||
},
|
||||
child: const Text('Show Dialog'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display dialog with correct text', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockVerifyEmailCubit();
|
||||
const currentEmail = 'test@example.com';
|
||||
final widget = CodeNotReceivedDialog(
|
||||
currentEmail: currentEmail,
|
||||
verifyEmailCubit: mockCubit,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.tap(find.text('Show Dialog'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.text('Почему может не приходить код?'), findsOneWidget);
|
||||
expect(find.text('Понятно'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should close dialog when Понятно button is tapped', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockVerifyEmailCubit();
|
||||
const currentEmail = 'test@example.com';
|
||||
final widget = CodeNotReceivedDialog(
|
||||
currentEmail: currentEmail,
|
||||
verifyEmailCubit: mockCubit,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.tap(find.text('Show Dialog'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Понятно'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.text('Почему может не приходить код?'), findsNothing);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
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/registration_v2/cubit/registration_cubit.dart';
|
||||
import 'package:eatvio_app/features/registration_v2/cubit/registration_state.dart';
|
||||
import 'package:eatvio_app/features/registration_v2/presentation/widgets/password_field.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'password_field_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<RegistrationCubitV2>()])
|
||||
void main() {
|
||||
group('PasswordField', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child, RegistrationCubitV2 cubit) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Portal(
|
||||
child: BlocProvider<RegistrationCubitV2>(
|
||||
create: (_) => cubit,
|
||||
child: Scaffold(body: child),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display password field with password from state', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockRegistrationCubitV2();
|
||||
const testPassword = 'testPassword123';
|
||||
when(mockCubit.state).thenReturn(
|
||||
RegistrationStateV2(password: testPassword),
|
||||
);
|
||||
final widget = PasswordField(cubit: mockCubit);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget, mockCubit));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PasswordField), findsOneWidget);
|
||||
expect(find.text(testPassword), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should show copy icon initially', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockRegistrationCubitV2();
|
||||
when(mockCubit.state).thenReturn(
|
||||
RegistrationStateV2(password: 'test'),
|
||||
);
|
||||
final widget = PasswordField(cubit: mockCubit);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget, mockCubit));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PasswordField), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
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/registration_v2/cubit/registration_cubit.dart';
|
||||
import 'package:eatvio_app/features/registration_v2/cubit/registration_state.dart';
|
||||
import 'package:eatvio_app/features/registration_v2/presentation/widgets/show_successful_registration_bottom_sheet.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'show_successful_registration_bottom_sheet_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<RegistrationCubitV2>()])
|
||||
void main() {
|
||||
group('ShowSuccessfulRegistrationBottomSheet', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child, RegistrationCubitV2 cubit) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Portal(
|
||||
child: BlocProvider<RegistrationCubitV2>(
|
||||
create: (_) => cubit,
|
||||
child: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => ElevatedButton(
|
||||
onPressed: () {
|
||||
showRegistrationBottomSheet(context, cubit, true);
|
||||
},
|
||||
child: const Text('Show Bottom Sheet'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display success bottom sheet when isSuccess is true', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockRegistrationCubitV2();
|
||||
when(mockCubit.state).thenReturn(
|
||||
RegistrationStateV2(password: 'testPassword'),
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(const SizedBox(), mockCubit));
|
||||
await tester.tap(find.text('Show Bottom Sheet'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(RegistrationBottomSheet), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display error bottom sheet when isSuccess is false', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockRegistrationCubitV2();
|
||||
when(mockCubit.state).thenReturn(
|
||||
RegistrationStateV2(),
|
||||
);
|
||||
|
||||
Widget createTestWidgetError(Widget child, RegistrationCubitV2 cubit) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Portal(
|
||||
child: BlocProvider<RegistrationCubitV2>(
|
||||
create: (_) => cubit,
|
||||
child: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => ElevatedButton(
|
||||
onPressed: () {
|
||||
showRegistrationBottomSheet(context, cubit, false);
|
||||
},
|
||||
child: const Text('Show Bottom Sheet'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidgetError(const SizedBox(), mockCubit));
|
||||
await tester.tap(find.text('Show Bottom Sheet'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(RegistrationBottomSheet), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user