forked from eatvio/eatvio_app
chore(version): update app version to 1.3.5+85 and improve test coverage reporting in CI
This commit is contained in:
@@ -3,30 +3,42 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('CalendarModel', () {
|
||||
test('создает CalendarModel с правильными значениями', () {
|
||||
test('создает экземпляр с данными', () {
|
||||
const model = CalendarModel(
|
||||
date: '2024-01-01',
|
||||
date: '2024-01-15',
|
||||
isCurrentDayIncludedInTheChosenDietProgression: true,
|
||||
diary: null,
|
||||
);
|
||||
|
||||
expect(model.date, '2024-01-01');
|
||||
expect(model.isCurrentDayIncludedInTheChosenDietProgression, isTrue);
|
||||
expect(model.diary, isNull);
|
||||
expect(model.date, '2024-01-15');
|
||||
expect(model.isCurrentDayIncludedInTheChosenDietProgression, true);
|
||||
expect(model.diary, null);
|
||||
});
|
||||
|
||||
test('fromJson создает CalendarModel из JSON', () {
|
||||
test('fromJson создает модель из JSON', () {
|
||||
final json = {
|
||||
'date': '2024-01-01',
|
||||
'date': '2024-01-15',
|
||||
'is_current_day_included_in_the_chosen_diet_progression': true,
|
||||
'diary': null,
|
||||
};
|
||||
|
||||
final model = CalendarModel.fromJson(json);
|
||||
|
||||
expect(model.date, '2024-01-01');
|
||||
expect(model.isCurrentDayIncludedInTheChosenDietProgression, isTrue);
|
||||
expect(model.date, '2024-01-15');
|
||||
expect(model.isCurrentDayIncludedInTheChosenDietProgression, true);
|
||||
});
|
||||
|
||||
test('toJson преобразует модель в JSON', () {
|
||||
const model = CalendarModel(
|
||||
date: '2024-01-15',
|
||||
isCurrentDayIncludedInTheChosenDietProgression: true,
|
||||
diary: null,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['date'], '2024-01-15');
|
||||
expect(json['is_current_day_included_in_the_chosen_diet_progression'], true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -3,62 +3,51 @@ import 'package:eatvio_app/features/calendar/presentation/bloc/calendar_cubit.da
|
||||
import 'package:eatvio_app/features/calendar/presentation/bloc/calendar_state.dart';
|
||||
import 'package:eatvio_app/features/calendar/repositories/calendar_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
|
||||
import 'calendar_cubit_test.mocks.dart';
|
||||
class MockCalendarRepository extends Mock implements CalendarRepository {}
|
||||
|
||||
@GenerateNiceMocks([MockSpec<CalendarRepository>()])
|
||||
void main() {
|
||||
group('CalendarCubit', () {
|
||||
CalendarCubit? cubit;
|
||||
late CalendarCubit cubit;
|
||||
late MockCalendarRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockCalendarRepository();
|
||||
cubit = CalendarCubit(calendarRepository: mockRepository);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
if (cubit != null && !cubit!.isClosed) {
|
||||
await cubit!.close();
|
||||
cubit = null;
|
||||
}
|
||||
tearDown(() {
|
||||
cubit.close();
|
||||
});
|
||||
|
||||
test('начальное состояние - loading', () {
|
||||
cubit = CalendarCubit(calendarRepository: mockRepository);
|
||||
|
||||
expect(cubit!.state, isA<CalendarStateLoading>());
|
||||
expect(cubit.state, isA<CalendarStateLoading>());
|
||||
});
|
||||
|
||||
test('loadCalendarList - успешная загрузка календаря', () async {
|
||||
cubit = CalendarCubit(calendarRepository: mockRepository);
|
||||
test('loadCalendarList - успешная загрузка', () async {
|
||||
final mockCalendarList = <CalendarModel>[];
|
||||
|
||||
const testCalendar = CalendarModel(
|
||||
date: '2024-01-01',
|
||||
isCurrentDayIncludedInTheChosenDietProgression: true,
|
||||
);
|
||||
when(() => mockRepository.getCalendar())
|
||||
.thenAnswer((_) async => mockCalendarList);
|
||||
|
||||
when(mockRepository.getCalendar())
|
||||
.thenAnswer((_) async => [testCalendar]);
|
||||
await cubit.loadCalendarList();
|
||||
|
||||
await cubit!.loadCalendarList();
|
||||
|
||||
expect(cubit!.state, isA<CalendarStateLoaded>());
|
||||
final loadedState = cubit!.state as CalendarStateLoaded;
|
||||
expect(loadedState.calendarList.length, 1);
|
||||
expect(cubit.state, isA<CalendarStateLoaded>());
|
||||
final loadedState = cubit.state as CalendarStateLoaded;
|
||||
expect(loadedState.calendarList, mockCalendarList);
|
||||
verify(() => mockRepository.getCalendar()).called(1);
|
||||
});
|
||||
|
||||
test('loadCalendarList - обработка ошибки', () async {
|
||||
cubit = CalendarCubit(calendarRepository: mockRepository);
|
||||
when(() => mockRepository.getCalendar())
|
||||
.thenThrow(Exception('Error'));
|
||||
|
||||
when(mockRepository.getCalendar())
|
||||
.thenThrow(Exception('Ошибка загрузки'));
|
||||
await cubit.loadCalendarList();
|
||||
|
||||
await cubit!.loadCalendarList();
|
||||
|
||||
expect(cubit!.state, isA<CalendarStateError>());
|
||||
expect(cubit.state, isA<CalendarStateError>());
|
||||
final errorState = cubit.state as CalendarStateError;
|
||||
expect(errorState.errorMessage, isNotEmpty);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user