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,90 +1,92 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/create_diet/presentation/widgets/error_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('ValidationErrorWidget', () {
testWidgets('displays error message', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: ValidationErrorWidget(error: 'Test error message'),
),
),
);
expect(find.byType(ValidationErrorWidget), findsOneWidget);
expect(find.text('Test error message'), findsOneWidget);
});
testWidgets('displays error icon', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: ValidationErrorWidget(error: 'Test error'),
),
),
);
expect(find.byType(ValidationErrorWidget), findsOneWidget);
});
testWidgets('handles long error messages', (tester) async {
final longError = 'A' * 100;
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ValidationErrorWidget(error: longError),
),
),
);
expect(find.byType(ValidationErrorWidget), findsOneWidget);
expect(find.text(longError), findsOneWidget);
});
testWidgets('displays empty error message', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: ValidationErrorWidget(error: ''),
),
),
);
expect(find.byType(ValidationErrorWidget), findsOneWidget);
});
});
}
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/create_diet/presentation/widgets/error_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('ValidationErrorWidget', () {
testWidgets('displays error message', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: ValidationErrorWidget(error: 'Test error message'),
),
),
);
expect(find.byType(ValidationErrorWidget), findsOneWidget);
expect(find.text('Test error message'), findsOneWidget);
});
testWidgets('displays error icon', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: ValidationErrorWidget(error: 'Test error'),
),
),
);
expect(find.byType(ValidationErrorWidget), findsOneWidget);
});
testWidgets('handles long error messages', (tester) async {
final longError = 'A' * 100;
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ValidationErrorWidget(error: longError),
),
),
);
expect(find.byType(ValidationErrorWidget), findsOneWidget);
expect(find.text(longError), findsOneWidget);
});
testWidgets('displays empty error message', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: ValidationErrorWidget(error: ''),
),
),
);
expect(find.byType(ValidationErrorWidget), findsOneWidget);
});
});
}

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);
});
});
}

View File

@@ -1,127 +1,129 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/diets/presentation/widgets/info_bouble.dart';
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),
],
),
),
),
);
expect(find.byType(InfoBouble), findsOneWidget);
expect(find.text('Test'), findsOneWidget);
expect(find.byIcon(Icons.star), 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'),
],
),
),
),
);
expect(find.byType(InfoBouble), findsOneWidget);
});
});
}
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/diets/presentation/widgets/info_bouble.dart';
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),
],
),
),
),
);
expect(find.byType(InfoBouble), findsOneWidget);
expect(find.text('Test'), findsOneWidget);
expect(find.byIcon(Icons.star), 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'),
],
),
),
),
);
expect(find.byType(InfoBouble), findsOneWidget);
});
});
}

View File

@@ -1,157 +1,159 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/feed/presentation/widgets/choice_chip_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('ChoiceChipWidget', () {
testWidgets('displays chip with label', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: const ['Option 1', 'Option 2'],
index: 0,
selectedChipIndex: 0,
onSelected: (selected) {},
),
),
),
);
expect(find.byType(ChoiceChipWidget), findsOneWidget);
expect(find.text('Option 1'), findsOneWidget);
});
testWidgets('shows selected state when index matches selectedChipIndex', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: const ['Option 1', 'Option 2'],
index: 0,
selectedChipIndex: 0,
onSelected: (selected) {},
),
),
),
);
expect(find.byType(ChoiceChipWidget), findsOneWidget);
final chip = tester.widget<ChoiceChip>(find.byType(ChoiceChip));
expect(chip.selected, isTrue);
});
testWidgets('shows unselected state when index does not match', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: const ['Option 1', 'Option 2'],
index: 1,
selectedChipIndex: 0,
onSelected: (selected) {},
),
),
),
);
expect(find.byType(ChoiceChipWidget), findsOneWidget);
final chip = tester.widget<ChoiceChip>(find.byType(ChoiceChip));
expect(chip.selected, isFalse);
});
testWidgets('applies custom padding', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: const ['Option 1'],
index: 0,
selectedChipIndex: 0,
padding: const EdgeInsets.all(16),
onSelected: (selected) {},
),
),
),
);
expect(find.byType(ChoiceChipWidget), findsOneWidget);
});
testWidgets('applies custom colors', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: const ['Option 1'],
index: 0,
selectedChipIndex: 0,
activeColor: Colors.blue,
inactiveColor: Colors.grey,
onSelected: (selected) {},
),
),
),
);
expect(find.byType(ChoiceChipWidget), findsOneWidget);
});
testWidgets('calls onSelected when tapped', (tester) async {
bool wasCalled = false;
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: const ['Option 1'],
index: 0,
selectedChipIndex: 0,
onSelected: (selected) {
wasCalled = true;
},
),
),
),
);
await tester.tap(find.byType(ChoiceChip));
await tester.pump();
expect(wasCalled, isTrue);
});
});
}
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/feed/presentation/widgets/choice_chip_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('ChoiceChipWidget', () {
testWidgets('displays chip with label', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: const ['Option 1', 'Option 2'],
index: 0,
selectedChipIndex: 0,
onSelected: (selected) {},
),
),
),
);
expect(find.byType(ChoiceChipWidget), findsOneWidget);
expect(find.text('Option 1'), findsOneWidget);
});
testWidgets('shows selected state when index matches selectedChipIndex', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: const ['Option 1', 'Option 2'],
index: 0,
selectedChipIndex: 0,
onSelected: (selected) {},
),
),
),
);
expect(find.byType(ChoiceChipWidget), findsOneWidget);
final chip = tester.widget<ChoiceChip>(find.byType(ChoiceChip));
expect(chip.selected, isTrue);
});
testWidgets('shows unselected state when index does not match', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: const ['Option 1', 'Option 2'],
index: 1,
selectedChipIndex: 0,
onSelected: (selected) {},
),
),
),
);
expect(find.byType(ChoiceChipWidget), findsOneWidget);
final chip = tester.widget<ChoiceChip>(find.byType(ChoiceChip));
expect(chip.selected, isFalse);
});
testWidgets('applies custom padding', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: const ['Option 1'],
index: 0,
selectedChipIndex: 0,
padding: const EdgeInsets.all(16),
onSelected: (selected) {},
),
),
),
);
expect(find.byType(ChoiceChipWidget), findsOneWidget);
});
testWidgets('applies custom colors', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: const ['Option 1'],
index: 0,
selectedChipIndex: 0,
activeColor: Colors.blue,
inactiveColor: Colors.grey,
onSelected: (selected) {},
),
),
),
);
expect(find.byType(ChoiceChipWidget), findsOneWidget);
});
testWidgets('calls onSelected when tapped', (tester) async {
bool wasCalled = false;
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: const ['Option 1'],
index: 0,
selectedChipIndex: 0,
onSelected: (selected) {
wasCalled = true;
},
),
),
),
);
await tester.tap(find.byType(ChoiceChip));
await tester.pump();
expect(wasCalled, isTrue);
});
});
}

View File

@@ -1,69 +1,71 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/feed/presentation/widgets/filter_badge.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('FilterBadge', () {
testWidgets('displays filter badge widget', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: FilterBadge(
filterBottomSheet: Text('Filter Bottom Sheet'),
),
),
),
);
expect(find.byType(FilterBadge), findsOneWidget);
expect(find.byType(GestureDetector), findsOneWidget);
});
testWidgets('opens bottom sheet when tapped', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: FilterBadge(
filterBottomSheet: Text('Filter Bottom Sheet'),
),
),
),
);
await tester.tap(find.byType(FilterBadge));
await tester.pumpAndSettle();
expect(find.text('Filter Bottom Sheet'), findsOneWidget);
});
});
}
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/feed/presentation/widgets/filter_badge.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('FilterBadge', () {
testWidgets('displays filter badge widget', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: FilterBadge(
filterBottomSheet: Text('Filter Bottom Sheet'),
),
),
),
);
expect(find.byType(FilterBadge), findsOneWidget);
expect(find.byType(GestureDetector), findsOneWidget);
});
testWidgets('opens bottom sheet when tapped', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: FilterBadge(
filterBottomSheet: Text('Filter Bottom Sheet'),
),
),
),
);
await tester.tap(find.byType(FilterBadge));
await tester.pumpAndSettle();
expect(find.text('Filter Bottom Sheet'), findsOneWidget);
});
});
}

View File

@@ -1,77 +1,79 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/finances_and_consultations_archive/presentation/widgets/status_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('StatusWidget', () {
testWidgets('displays canceled status', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: StatusWidget(status: Status.canceled),
),
),
);
expect(find.byType(StatusWidget), findsOneWidget);
expect(find.text('Отменён'), findsOneWidget);
});
testWidgets('displays success status', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: StatusWidget(status: Status.success),
),
),
);
expect(find.byType(StatusWidget), findsOneWidget);
expect(find.text('Успешно'), findsOneWidget);
});
testWidgets('displays inProgress status', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: StatusWidget(status: Status.inProgress),
),
),
);
expect(find.byType(StatusWidget), findsOneWidget);
expect(find.text('В процессе'), findsOneWidget);
});
});
}
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/finances_and_consultations_archive/presentation/widgets/status_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('StatusWidget', () {
testWidgets('displays canceled status', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: StatusWidget(status: Status.canceled),
),
),
);
expect(find.byType(StatusWidget), findsOneWidget);
expect(find.text('Отменён'), findsOneWidget);
});
testWidgets('displays success status', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: StatusWidget(status: Status.success),
),
),
);
expect(find.byType(StatusWidget), findsOneWidget);
expect(find.text('Успешно'), findsOneWidget);
});
testWidgets('displays inProgress status', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: const Scaffold(
body: StatusWidget(status: Status.inProgress),
),
),
);
expect(find.byType(StatusWidget), findsOneWidget);
expect(find.text('В процессе'), findsOneWidget);
});
});
}

View File

@@ -1,70 +1,72 @@
import 'package:eatvio_app/features/glossary/models/glossary_model.dart';
import 'package:eatvio_app/features/glossary/repositories/glossary_repository.dart';
import 'package:eatvio_app/features/glossary/services/glossary_service.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
class MockGlossaryService extends Mock implements GlossaryService {}
void main() {
group('GlossaryRepository', () {
late GlossaryRepository repository;
late MockGlossaryService mockService;
setUp(() {
mockService = MockGlossaryService();
repository = GlossaryRepository(glossaryService: mockService);
});
test('getGlossaryListByQuery - успешный запрос', () async {
const query = 'test';
final mockGlossaries = <GlossaryModel>[];
final mockPagination = GlossaryPaginationModel(glossariesList: mockGlossaries);
when(() => mockService.getGlossaryByQuery(query: query))
.thenAnswer((_) async => mockPagination);
final result = await repository.getGlossaryListByQuery(query);
expect(result, mockGlossaries);
verify(() => mockService.getGlossaryByQuery(query: query)).called(1);
});
test('getGlossaryListByQuery - пробрасывает ошибку', () async {
const query = 'test';
when(() => mockService.getGlossaryByQuery(query: query))
.thenThrow(Exception('Error'));
expect(() => repository.getGlossaryListByQuery(query), throwsException);
});
});
}
import 'package:eatvio_app/features/glossary/models/glossary_model.dart';
import 'package:eatvio_app/features/glossary/repositories/glossary_repository.dart';
import 'package:eatvio_app/features/glossary/services/glossary_service.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
class MockGlossaryService extends Mock implements GlossaryService {}
void main() {
group('GlossaryRepository', () {
late GlossaryRepository repository;
late MockGlossaryService mockService;
setUp(() {
mockService = MockGlossaryService();
repository = GlossaryRepository(glossaryService: mockService);
});
test('getGlossaryListByQuery - успешный запрос', () async {
const query = 'test';
final mockGlossaries = <GlossaryModel>[];
final mockPagination = GlossaryPaginationModel(glossariesList: mockGlossaries);
when(() => mockService.getGlossaryByQuery(query: query))
.thenAnswer((_) async => mockPagination);
final result = await repository.getGlossaryListByQuery(query);
expect(result, mockGlossaries);
verify(() => mockService.getGlossaryByQuery(query: query)).called(1);
});
test('getGlossaryListByQuery - пробрасывает ошибку', () async {
const query = 'test';
when(() => mockService.getGlossaryByQuery(query: query))
.thenThrow(Exception('Error'));
expect(() => repository.getGlossaryListByQuery(query), throwsException);
});
});
}

View File

@@ -1,79 +1,81 @@
import 'package:dio/dio.dart';
import 'package:eatvio_app/features/notifications/service/notifications_service.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import '../../../fixtures/fixture_reader.dart';
import 'notifications_service_test.mocks.dart';
@GenerateNiceMocks([MockSpec<Dio>()])
void main() {
group('NotificationsService', () {
late NotificationsService notificationsService;
late MockDio mockDio;
setUp(() {
mockDio = MockDio();
notificationsService = NotificationsService(mockDio);
});
test('getNotifications - возвращает уведомления', () async {
const page = 1;
final json = FixtureReader.readAsMap('notifications/notifications_response.json');
final response = Response(
data: {
'data': json['notifications'],
'current_page': json['pagination']['current_page'],
'last_page': json['pagination']['last_page'],
'per_page': 10,
'total': 1,
},
statusCode: 200,
requestOptions: RequestOptions(path: '/api/profile/notifications'),
);
when(mockDio.get(any))
.thenAnswer((_) async => response);
final result = await notificationsService.getNotifications(page: page);
expect(result, isA<Map<String, dynamic>?>());
expect(result, isNotNull);
expect(result!['notifications'], isA<List>());
verify(mockDio.get(any)).called(1);
});
test('markNotificationsAsRead - помечает уведомления как прочитанные', () async {
final response = Response(
data: {},
statusCode: 200,
requestOptions: RequestOptions(path: '/api/profile/mark_notifications_as_readed'),
);
when(mockDio.post(any))
.thenAnswer((_) async => response);
await notificationsService.markNotificationsAsRead();
verify(mockDio.post(any)).called(1);
});
});
}
import 'package:dio/dio.dart';
import 'package:eatvio_app/features/notifications/service/notifications_service.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import '../../../fixtures/fixture_reader.dart';
import 'notifications_service_test.mocks.dart';
@GenerateNiceMocks([MockSpec<Dio>()])
void main() {
group('NotificationsService', () {
late NotificationsService notificationsService;
late MockDio mockDio;
setUp(() {
mockDio = MockDio();
notificationsService = NotificationsService(mockDio);
});
test('getNotifications - возвращает уведомления', () async {
const page = 1;
final json = FixtureReader.readAsMap('notifications/notifications_response.json');
final response = Response(
data: {
'data': json['notifications'],
'current_page': json['pagination']['current_page'],
'last_page': json['pagination']['last_page'],
'per_page': 10,
'total': 1,
},
statusCode: 200,
requestOptions: RequestOptions(path: '/api/profile/notifications'),
);
when(mockDio.get(any))
.thenAnswer((_) async => response);
final result = await notificationsService.getNotifications(page: page);
expect(result, isA<Map<String, dynamic>?>());
expect(result, isNotNull);
expect(result!['notifications'], isA<List>());
verify(mockDio.get(any)).called(1);
});
test('markNotificationsAsRead - помечает уведомления как прочитанные', () async {
final response = Response(
data: {},
statusCode: 200,
requestOptions: RequestOptions(path: '/api/profile/mark_notifications_as_readed'),
);
when(mockDio.post(any))
.thenAnswer((_) async => response);
await notificationsService.markNotificationsAsRead();
verify(mockDio.post(any)).called(1);
});
});
}