refactor: clean up imports and improve code readability across various files

This commit is contained in:
mso7nueh
2025-12-24 17:54:35 +03:00
parent 3d774267ca
commit e158d812e4
41 changed files with 4699 additions and 4613 deletions

View File

@@ -1,99 +1,101 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/chosen_diet_widget.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('ChosenDietWidgetContent', () {
Widget createTestWidget(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('displays chosen diet widget content', (tester) async {
await tester.pumpWidget(
createTestWidget(
const ChosenDietWidgetContent(
currentDietDay: 5,
dietName: 'Test Diet',
dietDuration: 14,
dietId: 1,
),
),
);
expect(find.byType(ChosenDietWidgetContent), findsOneWidget);
expect(find.text('Test Diet'), findsOneWidget);
});
testWidgets('displays current day and duration', (tester) async {
await tester.pumpWidget(
createTestWidget(
const ChosenDietWidgetContent(
currentDietDay: 7,
dietName: 'Test Diet',
dietDuration: 21,
dietId: 1,
),
),
);
expect(find.byType(ChosenDietWidgetContent), findsOneWidget);
});
testWidgets('displays diet name with underline', (tester) async {
await tester.pumpWidget(
createTestWidget(
const ChosenDietWidgetContent(
currentDietDay: 1,
dietName: 'My Diet',
dietDuration: 7,
dietId: 1,
),
),
);
expect(find.text('My Diet'), findsOneWidget);
});
});
}
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/chosen_diet_widget.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('ChosenDietWidgetContent', () {
Widget createTestWidget(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('displays chosen diet widget content', (tester) async {
await tester.pumpWidget(
createTestWidget(
const ChosenDietWidgetContent(
currentDietDay: 5,
dietName: 'Test Diet',
dietDuration: 14,
dietId: 1,
),
),
);
expect(find.byType(ChosenDietWidgetContent), findsOneWidget);
expect(find.text('Test Diet'), findsOneWidget);
});
testWidgets('displays current day and duration', (tester) async {
await tester.pumpWidget(
createTestWidget(
const ChosenDietWidgetContent(
currentDietDay: 7,
dietName: 'Test Diet',
dietDuration: 21,
dietId: 1,
),
),
);
expect(find.byType(ChosenDietWidgetContent), findsOneWidget);
});
testWidgets('displays diet name with underline', (tester) async {
await tester.pumpWidget(
createTestWidget(
const ChosenDietWidgetContent(
currentDietDay: 1,
dietName: 'My Diet',
dietDuration: 7,
dietId: 1,
),
),
);
expect(find.text('My Diet'), findsOneWidget);
});
});
}

View File

@@ -1,77 +1,79 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/comment_container.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('CommentContainer', () {
testWidgets('displays comment text', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: CommentContainer(comment: 'Test comment'),
),
),
);
expect(find.byType(CommentContainer), findsOneWidget);
expect(find.text('Test comment'), findsOneWidget);
});
testWidgets('displays empty comment', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: CommentContainer(comment: ''),
),
),
);
expect(find.byType(CommentContainer), findsOneWidget);
});
testWidgets('displays long comment', (tester) async {
const longComment = 'This is a very long comment that should be displayed properly in the container';
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: CommentContainer(comment: longComment),
),
),
);
expect(find.byType(CommentContainer), findsOneWidget);
expect(find.text(longComment), findsOneWidget);
});
});
}
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/comment_container.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('CommentContainer', () {
testWidgets('displays comment text', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: CommentContainer(comment: 'Test comment'),
),
),
);
expect(find.byType(CommentContainer), findsOneWidget);
expect(find.text('Test comment'), findsOneWidget);
});
testWidgets('displays empty comment', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: CommentContainer(comment: ''),
),
),
);
expect(find.byType(CommentContainer), findsOneWidget);
});
testWidgets('displays long comment', (tester) async {
const longComment = 'This is a very long comment that should be displayed properly in the container';
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: CommentContainer(comment: longComment),
),
),
);
expect(find.byType(CommentContainer), findsOneWidget);
expect(find.text(longComment), findsOneWidget);
});
});
}

View File

@@ -1,72 +1,74 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/finish_day_button_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('FinishDayButtonWidget', () {
testWidgets('displays finish day button', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: FinishDayButtonWidget(
onPressed: () async {},
),
),
),
);
expect(find.byType(FinishDayButtonWidget), findsOneWidget);
expect(find.text('Закончить день'), findsOneWidget);
});
testWidgets('calls onPressed when tapped', (tester) async {
bool wasCalled = false;
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: FinishDayButtonWidget(
onPressed: () async {
wasCalled = true;
},
),
),
),
);
await tester.tap(find.text('Закончить день'));
await tester.pump();
expect(wasCalled, isTrue);
});
});
}
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/finish_day_button_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('FinishDayButtonWidget', () {
testWidgets('displays finish day button', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: FinishDayButtonWidget(
onPressed: () async {},
),
),
),
);
expect(find.byType(FinishDayButtonWidget), findsOneWidget);
expect(find.text('Закончить день'), findsOneWidget);
});
testWidgets('calls onPressed when tapped', (tester) async {
bool wasCalled = false;
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: FinishDayButtonWidget(
onPressed: () async {
wasCalled = true;
},
),
),
),
);
await tester.tap(find.text('Закончить день'));
await tester.pump();
expect(wasCalled, isTrue);
});
});
}

View File

@@ -1,109 +1,111 @@
import 'package:eatvio_app/features/diary/models/diary_day_model.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/meal_summary_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('MealSummaryWidget', () {
testWidgets('displays meal summary with totals', (tester) async {
final portions = <PortionModel>[];
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: MealSummaryWidget(
portions: portions,
mealNumber: 1,
),
),
),
);
expect(find.byType(MealSummaryWidget), findsOneWidget);
});
testWidgets('hides when all totals are zero', (tester) async {
final portions = <PortionModel>[];
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: MealSummaryWidget(
portions: portions,
mealNumber: 1,
),
),
),
);
await tester.pumpAndSettle();
// Widget should be hidden (SizedBox.shrink) when totals are zero
expect(find.byType(MealSummaryWidget), findsOneWidget);
});
testWidgets('displays meal number', (tester) async {
final portions = <PortionModel>[];
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: MealSummaryWidget(
portions: portions,
mealNumber: 3,
),
),
),
);
expect(find.byType(MealSummaryWidget), findsOneWidget);
});
});
group('MealSummaryWidget.calculateMealTotals', () {
test('returns zero totals for empty portions list', () {
final result = MealSummaryWidget.calculateMealTotals([]);
expect(result['calories'], 0.0);
expect(result['proteins'], 0.0);
expect(result['fats'], 0.0);
expect(result['carbohydrates'], 0.0);
});
test('returns correct map structure', () {
final result = MealSummaryWidget.calculateMealTotals([]);
expect(result.containsKey('calories'), isTrue);
expect(result.containsKey('proteins'), isTrue);
expect(result.containsKey('fats'), isTrue);
expect(result.containsKey('carbohydrates'), isTrue);
});
});
}
import 'package:eatvio_app/features/diary/models/diary_day_model.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/meal_summary_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('MealSummaryWidget', () {
testWidgets('displays meal summary with totals', (tester) async {
final portions = <PortionModel>[];
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: MealSummaryWidget(
portions: portions,
mealNumber: 1,
),
),
),
);
expect(find.byType(MealSummaryWidget), findsOneWidget);
});
testWidgets('hides when all totals are zero', (tester) async {
final portions = <PortionModel>[];
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: MealSummaryWidget(
portions: portions,
mealNumber: 1,
),
),
),
);
await tester.pumpAndSettle();
// Widget should be hidden (SizedBox.shrink) when totals are zero
expect(find.byType(MealSummaryWidget), findsOneWidget);
});
testWidgets('displays meal number', (tester) async {
final portions = <PortionModel>[];
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: MealSummaryWidget(
portions: portions,
mealNumber: 3,
),
),
),
);
expect(find.byType(MealSummaryWidget), findsOneWidget);
});
});
group('MealSummaryWidget.calculateMealTotals', () {
test('returns zero totals for empty portions list', () {
final result = MealSummaryWidget.calculateMealTotals([]);
expect(result['calories'], 0.0);
expect(result['proteins'], 0.0);
expect(result['fats'], 0.0);
expect(result['carbohydrates'], 0.0);
});
test('returns correct map structure', () {
final result = MealSummaryWidget.calculateMealTotals([]);
expect(result.containsKey('calories'), isTrue);
expect(result.containsKey('proteins'), isTrue);
expect(result.containsKey('fats'), isTrue);
expect(result.containsKey('carbohydrates'), isTrue);
});
});
}

View File

@@ -1,61 +1,63 @@
import 'package:eatvio_app/features/diary/presentation/widgets/product_loader_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('ProductLoaderWidget', () {
testWidgets('displays product loader widget', (tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: ProductLoaderWidget(),
),
),
);
expect(find.byType(ProductLoaderWidget), findsOneWidget);
expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
});
testWidgets('displays ListTile with activity indicator', (tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: ProductLoaderWidget(),
),
),
);
expect(find.byType(ListTile), findsOneWidget);
expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
});
});
}
import 'package:eatvio_app/features/diary/presentation/widgets/product_loader_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('ProductLoaderWidget', () {
testWidgets('displays product loader widget', (tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: ProductLoaderWidget(),
),
),
);
expect(find.byType(ProductLoaderWidget), findsOneWidget);
expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
});
testWidgets('displays ListTile with activity indicator', (tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: ProductLoaderWidget(),
),
),
);
expect(find.byType(ListTile), findsOneWidget);
expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
});
});
}