forked from eatvio/eatvio_app
feat(tests): increased tests coverage
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:eatvio_app/features/diets/presentation/cubit/about_diet_cubit.da
|
||||
import 'package:eatvio_app/features/diets/presentation/cubit/about_diet_state.dart';
|
||||
import 'package:eatvio_app/features/diets/repositories/diet_repository.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/profile/models/chosen_diets_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
@@ -10,10 +11,7 @@ import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'about_diet_cubit_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([
|
||||
MockSpec<DietRepository>(),
|
||||
MockSpec<ProfileRepository>(),
|
||||
])
|
||||
@GenerateNiceMocks([MockSpec<DietRepository>(), MockSpec<ProfileRepository>()])
|
||||
void main() {
|
||||
group('AboutDietCubit', () {
|
||||
AboutDietCubit? aboutDietCubit;
|
||||
@@ -33,19 +31,13 @@ void main() {
|
||||
});
|
||||
|
||||
test('начальное состояние - initial', () {
|
||||
aboutDietCubit = AboutDietCubit(
|
||||
dietsRepository: mockDietRepository,
|
||||
profileRepository: mockProfileRepository,
|
||||
);
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
expect(aboutDietCubit!.state, isA<AboutDietState>());
|
||||
});
|
||||
|
||||
test('getDiet - успешная загрузка диеты по slug', () async {
|
||||
aboutDietCubit = AboutDietCubit(
|
||||
dietsRepository: mockDietRepository,
|
||||
profileRepository: mockProfileRepository,
|
||||
);
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
const testDiet = Diet(
|
||||
id: 1,
|
||||
@@ -73,8 +65,7 @@ void main() {
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
when(mockDietRepository.getDietBySlug('test-diet'))
|
||||
.thenAnswer((_) async => testDiet);
|
||||
when(mockDietRepository.getDietBySlug('test-diet')).thenAnswer((_) async => testDiet);
|
||||
|
||||
await aboutDietCubit!.getDiet(slug: 'test-diet');
|
||||
|
||||
@@ -84,10 +75,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('getDiet - успешная загрузка диеты по id', () async {
|
||||
aboutDietCubit = AboutDietCubit(
|
||||
dietsRepository: mockDietRepository,
|
||||
profileRepository: mockProfileRepository,
|
||||
);
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
const testDiet = Diet(
|
||||
id: 1,
|
||||
@@ -115,8 +103,7 @@ void main() {
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
when(mockDietRepository.getDiet(1))
|
||||
.thenAnswer((_) async => testDiet);
|
||||
when(mockDietRepository.getDiet(1)).thenAnswer((_) async => testDiet);
|
||||
|
||||
await aboutDietCubit!.getDiet(id: 1);
|
||||
|
||||
@@ -124,13 +111,9 @@ void main() {
|
||||
});
|
||||
|
||||
test('getDiet - обработка ошибки', () async {
|
||||
aboutDietCubit = AboutDietCubit(
|
||||
dietsRepository: mockDietRepository,
|
||||
profileRepository: mockProfileRepository,
|
||||
);
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
when(mockDietRepository.getDietBySlug(any))
|
||||
.thenThrow(Exception('Ошибка загрузки'));
|
||||
when(mockDietRepository.getDietBySlug(any)).thenThrow(Exception('Ошибка загрузки'));
|
||||
|
||||
await aboutDietCubit!.getDiet(slug: 'test-diet');
|
||||
|
||||
@@ -138,10 +121,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('likeDiet - лайк диеты', () async {
|
||||
aboutDietCubit = AboutDietCubit(
|
||||
dietsRepository: mockDietRepository,
|
||||
profileRepository: mockProfileRepository,
|
||||
);
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
const testDiet = Diet(
|
||||
id: 1,
|
||||
@@ -169,13 +149,8 @@ void main() {
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
when(mockDietRepository.getDietBySlug('test-diet'))
|
||||
.thenAnswer((_) async => testDiet);
|
||||
when(mockDietRepository.likeDiet(1))
|
||||
.thenAnswer((_) async => const DietLikesModel(
|
||||
totalLikes: 11,
|
||||
isLiked: true,
|
||||
));
|
||||
when(mockDietRepository.getDietBySlug('test-diet')).thenAnswer((_) async => testDiet);
|
||||
when(mockDietRepository.likeDiet(1)).thenAnswer((_) async => const DietLikesModel(totalLikes: 11, isLiked: true));
|
||||
|
||||
await aboutDietCubit!.getDiet(slug: 'test-diet');
|
||||
await aboutDietCubit!.likeDiet(1, null);
|
||||
@@ -185,6 +160,545 @@ void main() {
|
||||
final loadedState = aboutDietCubit!.state as DietStateLoaded;
|
||||
expect(loadedState.diet.wasLikedByMe, isTrue);
|
||||
});
|
||||
|
||||
test('initDietPage - успешная инициализация страницы диеты по slug', () async {
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
const testDiet = Diet(
|
||||
id: 1,
|
||||
slug: 'test-diet',
|
||||
name: 'Test Diet',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: DietState.active,
|
||||
type: DietType(veg: true, light: false, carb: false, meat: false),
|
||||
details: 'Test details',
|
||||
dailySchedule: {},
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
when(mockDietRepository.getDietBySlug('test-diet')).thenAnswer((_) async => testDiet);
|
||||
when(mockProfileRepository.getChosenDiets()).thenAnswer((_) async => []);
|
||||
|
||||
await aboutDietCubit!.initDietPage(slug: 'test-diet');
|
||||
|
||||
expect(aboutDietCubit!.state, isA<DietStateLoaded>());
|
||||
final loadedState = aboutDietCubit!.state as DietStateLoaded;
|
||||
expect(loadedState.diet.id, 1);
|
||||
});
|
||||
|
||||
test('initDietPage - устанавливает isCurrentDietStarted когда диета уже начата', () async {
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
const testDiet = Diet(
|
||||
id: 1,
|
||||
slug: 'test-diet',
|
||||
name: 'Test Diet',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: DietState.active,
|
||||
type: DietType(veg: true, light: false, carb: false, meat: false),
|
||||
details: 'Test details',
|
||||
dailySchedule: {},
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
final chosenDiets = [ChosenDietModel(chosenDietID: 1, chosenPlanId: 1, state: 'started', startDate: DateTime(2024, 1, 1), dietId: 1)];
|
||||
|
||||
when(mockDietRepository.getDietBySlug('test-diet')).thenAnswer((_) async => testDiet);
|
||||
when(mockProfileRepository.getChosenDiets()).thenAnswer((_) async => chosenDiets);
|
||||
|
||||
await aboutDietCubit!.initDietPage(slug: 'test-diet');
|
||||
|
||||
expect(aboutDietCubit!.isCurrentDietStarted, true);
|
||||
expect(aboutDietCubit!.hasStartedDiet, true);
|
||||
});
|
||||
|
||||
test('addToFavorite - добавляет диету в избранное', () async {
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
const testDiet = Diet(
|
||||
id: 1,
|
||||
slug: 'test-diet',
|
||||
name: 'Test Diet',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: DietState.active,
|
||||
type: DietType(veg: true, light: false, carb: false, meat: false),
|
||||
details: 'Test details',
|
||||
dailySchedule: {},
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
when(mockDietRepository.getDietBySlug('test-diet')).thenAnswer((_) async => testDiet);
|
||||
const updatedDiet = Diet(
|
||||
id: 1,
|
||||
slug: 'test-diet',
|
||||
name: 'Test Diet',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: DietState.active,
|
||||
type: DietType(veg: true, light: false, carb: false, meat: false),
|
||||
details: 'Test details',
|
||||
dailySchedule: {},
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: true,
|
||||
dailyNutrition: [],
|
||||
);
|
||||
when(mockDietRepository.addToFavorite(1)).thenAnswer((_) async => updatedDiet);
|
||||
|
||||
await aboutDietCubit!.getDiet(slug: 'test-diet');
|
||||
await aboutDietCubit!.addToFavorite(1, null);
|
||||
|
||||
expect(aboutDietCubit!.state, isA<DietStateLoaded>());
|
||||
final loadedState = aboutDietCubit!.state as DietStateLoaded;
|
||||
expect(loadedState.diet.isFavorite, true);
|
||||
|
||||
await Future.delayed(const Duration(milliseconds: 1200));
|
||||
verify(mockDietRepository.addToFavorite(1)).called(1);
|
||||
});
|
||||
|
||||
test('removeFromFavorite - удаляет диету из избранного', () async {
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
const testDiet = Diet(
|
||||
id: 1,
|
||||
slug: 'test-diet',
|
||||
name: 'Test Diet',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: DietState.active,
|
||||
type: DietType(veg: true, light: false, carb: false, meat: false),
|
||||
details: 'Test details',
|
||||
dailySchedule: {},
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: true,
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
when(mockDietRepository.getDietBySlug('test-diet')).thenAnswer((_) async => testDiet);
|
||||
const updatedDiet = Diet(
|
||||
id: 1,
|
||||
slug: 'test-diet',
|
||||
name: 'Test Diet',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: DietState.active,
|
||||
type: DietType(veg: true, light: false, carb: false, meat: false),
|
||||
details: 'Test details',
|
||||
dailySchedule: {},
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
dailyNutrition: [],
|
||||
);
|
||||
when(mockDietRepository.removeFromFavorite(1)).thenAnswer((_) async => updatedDiet);
|
||||
|
||||
await aboutDietCubit!.getDiet(slug: 'test-diet');
|
||||
await aboutDietCubit!.removeFromFavorite(1, null);
|
||||
|
||||
expect(aboutDietCubit!.state, isA<DietStateLoaded>());
|
||||
final loadedState = aboutDietCubit!.state as DietStateLoaded;
|
||||
expect(loadedState.diet.isFavorite, false);
|
||||
|
||||
await Future.delayed(const Duration(milliseconds: 1200));
|
||||
verify(mockDietRepository.removeFromFavorite(1)).called(1);
|
||||
});
|
||||
|
||||
test('startDiet - успешно начинает диету', () async {
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
const testDiet = Diet(
|
||||
id: 1,
|
||||
slug: 'test-diet',
|
||||
name: 'Test Diet',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: DietState.active,
|
||||
type: DietType(veg: true, light: false, carb: false, meat: false),
|
||||
details: 'Test details',
|
||||
dailySchedule: {},
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
when(mockDietRepository.getDietBySlug('test-diet')).thenAnswer((_) async => testDiet);
|
||||
when(mockDietRepository.startDiet(1, any)).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
await aboutDietCubit!.getDiet(slug: 'test-diet');
|
||||
|
||||
final result = await aboutDietCubit!.startDiet(DateTime(2024, 1, 1));
|
||||
|
||||
expect(result, true);
|
||||
verify(mockDietRepository.startDiet(1, any)).called(1);
|
||||
});
|
||||
|
||||
test('startDiet - возвращает false при ошибке', () async {
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
const testDiet = Diet(
|
||||
id: 1,
|
||||
slug: 'test-diet',
|
||||
name: 'Test Diet',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: DietState.active,
|
||||
type: DietType(veg: true, light: false, carb: false, meat: false),
|
||||
details: 'Test details',
|
||||
dailySchedule: {},
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
when(mockDietRepository.getDietBySlug('test-diet')).thenAnswer((_) async => testDiet);
|
||||
when(mockDietRepository.startDiet(1, any)).thenThrow(Exception('Ошибка'));
|
||||
|
||||
await aboutDietCubit!.getDiet(slug: 'test-diet');
|
||||
|
||||
final result = await aboutDietCubit!.startDiet(DateTime(2024, 1, 1));
|
||||
|
||||
expect(result, false);
|
||||
});
|
||||
|
||||
test('cancelDiet - успешно отменяет диету', () async {
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
const testDiet = Diet(
|
||||
id: 1,
|
||||
slug: 'test-diet',
|
||||
name: 'Test Diet',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: DietState.active,
|
||||
type: DietType(veg: true, light: false, carb: false, meat: false),
|
||||
details: 'Test details',
|
||||
dailySchedule: {},
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
when(mockDietRepository.getDietBySlug('test-diet')).thenAnswer((_) async => testDiet);
|
||||
when(mockDietRepository.cancelDiet(1)).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
await aboutDietCubit!.getDiet(slug: 'test-diet');
|
||||
|
||||
final result = await aboutDietCubit!.cancelDiet();
|
||||
|
||||
expect(result, true);
|
||||
verify(mockDietRepository.cancelDiet(1)).called(1);
|
||||
});
|
||||
|
||||
test('cancelDiet - возвращает false при ошибке', () async {
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
const testDiet = Diet(
|
||||
id: 1,
|
||||
slug: 'test-diet',
|
||||
name: 'Test Diet',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: DietState.active,
|
||||
type: DietType(veg: true, light: false, carb: false, meat: false),
|
||||
details: 'Test details',
|
||||
dailySchedule: {},
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
when(mockDietRepository.getDietBySlug('test-diet')).thenAnswer((_) async => testDiet);
|
||||
when(mockDietRepository.cancelDiet(1)).thenThrow(Exception('Ошибка'));
|
||||
|
||||
await aboutDietCubit!.getDiet(slug: 'test-diet');
|
||||
|
||||
final result = await aboutDietCubit!.cancelDiet();
|
||||
|
||||
expect(result, false);
|
||||
});
|
||||
|
||||
test('clearStartedDietsState - очищает состояние начатых диет', () async {
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
const testDiet = Diet(
|
||||
id: 1,
|
||||
slug: 'test-diet',
|
||||
name: 'Test Diet',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: DietState.active,
|
||||
type: DietType(veg: true, light: false, carb: false, meat: false),
|
||||
details: 'Test details',
|
||||
dailySchedule: {},
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
when(mockDietRepository.getDietBySlug('test-diet')).thenAnswer((_) async => testDiet);
|
||||
|
||||
await aboutDietCubit!.getDiet(slug: 'test-diet');
|
||||
aboutDietCubit!.clearStartedDietsState();
|
||||
|
||||
expect(aboutDietCubit!.state, isA<DietStateLoaded>());
|
||||
});
|
||||
|
||||
test('emitCurrentStartedDietsState - устанавливает состояние начатой диеты', () async {
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
const testDiet = Diet(
|
||||
id: 1,
|
||||
slug: 'test-diet',
|
||||
name: 'Test Diet',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: DietState.active,
|
||||
type: DietType(veg: true, light: false, carb: false, meat: false),
|
||||
details: 'Test details',
|
||||
dailySchedule: {},
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
when(mockDietRepository.getDietBySlug('test-diet')).thenAnswer((_) async => testDiet);
|
||||
|
||||
await aboutDietCubit!.getDiet(slug: 'test-diet');
|
||||
aboutDietCubit!.emitCurrentStartedDietsState();
|
||||
|
||||
expect(aboutDietCubit!.state, isA<DietStateLoaded>());
|
||||
final loadedState = aboutDietCubit!.state as DietStateLoaded;
|
||||
expect(loadedState.isStarted, true);
|
||||
});
|
||||
|
||||
test('getDietBySlug - возвращает диету по slug', () async {
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
const testDiet = Diet(
|
||||
id: 1,
|
||||
slug: 'test-diet',
|
||||
name: 'Test Diet',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: DietState.active,
|
||||
type: DietType(veg: true, light: false, carb: false, meat: false),
|
||||
details: 'Test details',
|
||||
dailySchedule: {},
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
when(mockDietRepository.getDietBySlug('test-diet')).thenAnswer((_) async => testDiet);
|
||||
|
||||
final result = await aboutDietCubit!.getDietBySlug('test-diet');
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result!.id, 1);
|
||||
});
|
||||
|
||||
test('getDietBySlug - возвращает null при ошибке', () async {
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
when(mockDietRepository.getDietBySlug('test-diet')).thenThrow(Exception('Ошибка'));
|
||||
|
||||
final result = await aboutDietCubit!.getDietBySlug('test-diet');
|
||||
|
||||
expect(result, isNull);
|
||||
});
|
||||
|
||||
test('setSelectedIndex - устанавливает выбранный индекс', () async {
|
||||
aboutDietCubit = AboutDietCubit(dietsRepository: mockDietRepository, profileRepository: mockProfileRepository);
|
||||
|
||||
const testDiet = Diet(
|
||||
id: 1,
|
||||
slug: 'test-diet',
|
||||
name: 'Test Diet',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: DietState.active,
|
||||
type: DietType(veg: true, light: false, carb: false, meat: false),
|
||||
details: 'Test details',
|
||||
dailySchedule: {
|
||||
1: {
|
||||
1: {1: DailySchedule(name: 'Test', portion: Portion.grams, quantity: 100)},
|
||||
},
|
||||
},
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
when(mockDietRepository.getDietBySlug('test-diet')).thenAnswer((_) async => testDiet);
|
||||
when(mockProfileRepository.getChosenDiets()).thenAnswer((_) async => []);
|
||||
|
||||
await aboutDietCubit!.initDietPage(slug: 'test-diet');
|
||||
aboutDietCubit!.setSelectedIndex(dayNumber: 0, index: 2);
|
||||
|
||||
expect(aboutDietCubit!.state, isA<DietStateLoaded>());
|
||||
final loadedState = aboutDietCubit!.state as DietStateLoaded;
|
||||
expect(loadedState.selectedIndexes[0], 2);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/diets/presentation/widgets/expandable_text.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('ExpandableText smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: S.delegate.supportedLocales,
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders expandable text with short text', (tester) async {
|
||||
await tester.pumpWidget(wrap(const ExpandableText(text: 'Short text', maxLines: 5)));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
expect(find.byType(ExpandableText), findsOneWidget);
|
||||
expect(find.text('Short text'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders expandable text with long text', (tester) async {
|
||||
const longText =
|
||||
'This is a very long text that should be truncated and show an expand button when it exceeds the maximum number of lines specified in the widget.';
|
||||
await tester.pumpWidget(wrap(const ExpandableText(text: longText, maxLines: 5)));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
|
||||
expect(find.byType(ExpandableText), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -4,122 +4,36 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('InfoBouble', () {
|
||||
testWidgets('displays info bouble with children', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: InfoBouble(
|
||||
children: [
|
||||
Text('Test'),
|
||||
Icon(Icons.star),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
group('InfoBouble smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders info bouble', (tester) async {
|
||||
await tester.pumpWidget(wrap(const InfoBouble(children: [Text('Test')])));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(InfoBouble), findsOneWidget);
|
||||
expect(find.text('Test'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders info bouble with multiple children', (tester) async {
|
||||
await tester.pumpWidget(wrap(const InfoBouble(children: [Icon(Icons.star), Text('Test')])));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(InfoBouble), findsOneWidget);
|
||||
expect(find.byIcon(Icons.star), findsOneWidget);
|
||||
expect(find.text('Test'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays with custom background color', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: InfoBouble(
|
||||
backgroundColor: Colors.blue,
|
||||
children: [
|
||||
Text('Test'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(InfoBouble), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays with custom radius', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: InfoBouble(
|
||||
radius: 20,
|
||||
children: [
|
||||
Text('Test'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(InfoBouble), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays with custom padding', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: InfoBouble(
|
||||
padding: EdgeInsets.all(16),
|
||||
children: [
|
||||
Text('Test'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(InfoBouble), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays with custom mainAxisAlignment', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: InfoBouble(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text('Test'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
testWidgets('renders info bouble with custom background color', (tester) async {
|
||||
await tester.pumpWidget(wrap(const InfoBouble(backgroundColor: Colors.blue, children: [Text('Test')])));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(InfoBouble), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/diets/presentation/widgets/type_badges.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('TypeBadges smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: S.delegate.supportedLocales,
|
||||
home: Portal(child: Scaffold(body: child)),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders type badges with diet type', (tester) async {
|
||||
const dietType = DietType(light: true, veg: false, carb: false, meat: false);
|
||||
await tester.pumpWidget(wrap(const TypeBadges(type: dietType, disableDescriptionOfTypes: true)));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
expect(find.byType(TypeBadges), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders type badges with no type', (tester) async {
|
||||
await tester.pumpWidget(wrap(const TypeBadges(disableDescriptionOfTypes: true)));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
expect(find.byType(TypeBadges), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user