forked from eatvio/eatvio_app
feat(insights): first isights impemetation
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import 'package:eatvio_app/features/profile/models/circumference_model.dart';
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:eatvio_app/features/profile/models/weight_model.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:eatvio_app/features/user_details/presentation/cubit/user_details_cubit.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -28,8 +26,6 @@ void main() {
|
||||
expect(cubit.state.isLoading, isFalse);
|
||||
expect(cubit.state.error, isNull);
|
||||
expect(cubit.state.profileDetails, isNull);
|
||||
expect(cubit.state.weightPoints, isNull);
|
||||
expect(cubit.state.circumferencePoints, isNull);
|
||||
});
|
||||
|
||||
test('getUserDetails - успешная загрузка деталей пользователя', () async {
|
||||
@@ -62,37 +58,8 @@ void main() {
|
||||
activityCoefficient: 1.5,
|
||||
);
|
||||
|
||||
final weightPoints = [
|
||||
WeightModel(
|
||||
id: 1,
|
||||
userId: 1,
|
||||
weight: 70,
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
bmi: 22.9,
|
||||
),
|
||||
];
|
||||
|
||||
final circumferencePoints = [
|
||||
CircumferenceModel(
|
||||
id: 1,
|
||||
userId: 1,
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
),
|
||||
];
|
||||
|
||||
when(mockProfileRepository.getProfileDetailsBySlug(slug))
|
||||
.thenAnswer((_) async => profileDetails);
|
||||
|
||||
when(mockProfileRepository.getWeight(period: '1', slug: slug))
|
||||
.thenAnswer((_) async => weightPoints);
|
||||
|
||||
when(mockProfileRepository.getCircumferences(period: '1', slug: slug))
|
||||
.thenAnswer((_) async => circumferencePoints);
|
||||
|
||||
cubit.getUserDetails(slug);
|
||||
|
||||
@@ -119,75 +86,6 @@ void main() {
|
||||
expect(cubit.state.error, equals(error.toString()));
|
||||
expect(cubit.state.isLoading, isFalse);
|
||||
});
|
||||
|
||||
test('getChartData - успешная загрузка данных графика', () async {
|
||||
const slug = 'test-user';
|
||||
const period = '1';
|
||||
|
||||
final weightPoints = [
|
||||
WeightModel(
|
||||
id: 1,
|
||||
userId: 1,
|
||||
weight: 70,
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
bmi: 22.9,
|
||||
),
|
||||
WeightModel(
|
||||
id: 2,
|
||||
userId: 1,
|
||||
weight: 71,
|
||||
createdAt: DateTime.now().add(const Duration(days: 1)),
|
||||
updatedAt: DateTime.now().add(const Duration(days: 1)),
|
||||
bmi: 23.2,
|
||||
),
|
||||
];
|
||||
|
||||
final circumferencePoints = [
|
||||
CircumferenceModel(
|
||||
id: 1,
|
||||
userId: 1,
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
),
|
||||
];
|
||||
|
||||
when(mockProfileRepository.getWeight(period: period, slug: slug))
|
||||
.thenAnswer((_) async => weightPoints);
|
||||
|
||||
when(mockProfileRepository.getCircumferences(period: period, slug: slug))
|
||||
.thenAnswer((_) async => circumferencePoints);
|
||||
|
||||
cubit.getChartData(period: period, slug: slug);
|
||||
|
||||
// Ждем завершения асинхронных операций
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
expect(cubit.state.weightPoints, equals(weightPoints));
|
||||
expect(cubit.state.circumferencePoints, equals(circumferencePoints));
|
||||
verify(mockProfileRepository.getWeight(period: period, slug: slug)).called(1);
|
||||
verify(mockProfileRepository.getCircumferences(period: period, slug: slug)).called(1);
|
||||
});
|
||||
|
||||
test('getChartData - обработка ошибки', () async {
|
||||
const slug = 'test-user';
|
||||
const period = '1';
|
||||
final error = Exception('Ошибка загрузки');
|
||||
|
||||
when(mockProfileRepository.getWeight(period: period, slug: slug))
|
||||
.thenThrow(error);
|
||||
|
||||
cubit.getChartData(period: period, slug: slug);
|
||||
|
||||
// Ждем завершения асинхронных операций
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
expect(cubit.state.error, equals(error.toString()));
|
||||
expect(cubit.state.isLoading, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user