forked from eatvio/eatvio_app
feat(tests): increased tests coverage
This commit is contained in:
@@ -2,80 +2,34 @@ import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/add_item_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
void main() {
|
||||
group('AddItemButton', () {
|
||||
testWidgets('displays add button', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: AddItemButton(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(AddItemButton), findsOneWidget);
|
||||
expect(find.byIcon(Icons.add_rounded), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('calls onTap when provided', (tester) async {
|
||||
bool wasCalled = false;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: AddItemButton(
|
||||
onTap: () {
|
||||
wasCalled = true;
|
||||
},
|
||||
group('AddItemButton smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp.router(
|
||||
theme: ThemeHelper().themeData(),
|
||||
routerConfig: GoRouter(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => Scaffold(body: child),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/blog-post-create',
|
||||
name: 'blogPostCreateScreen',
|
||||
builder: (context, state) => const SizedBox.shrink(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
await tester.tap(find.byType(AddItemButton));
|
||||
testWidgets('renders add item button', (tester) async {
|
||||
await tester.pumpWidget(wrap(const AddItemButton()));
|
||||
await tester.pump();
|
||||
|
||||
expect(wasCalled, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('has circular shape', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: AddItemButton(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(AddItemButton), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,130 +4,28 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('AnimatedOptionButton', () {
|
||||
testWidgets('displays animated option button', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: AnimatedOptionButton(
|
||||
text: 'Option 1',
|
||||
isSelected: false,
|
||||
onTap: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
group('AnimatedOptionButton smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
expect(find.byType(AnimatedOptionButton), findsOneWidget);
|
||||
expect(find.text('Option 1'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays selected state', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: AnimatedOptionButton(
|
||||
text: 'Option 1',
|
||||
isSelected: true,
|
||||
onTap: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(AnimatedOptionButton), findsOneWidget);
|
||||
expect(find.text('Option 1'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('calls onTap when tapped', (tester) async {
|
||||
bool tapped = false;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: AnimatedOptionButton(
|
||||
text: 'Option 1',
|
||||
isSelected: false,
|
||||
onTap: () {
|
||||
tapped = true;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byType(AnimatedOptionButton));
|
||||
testWidgets('renders animated option button', (tester) async {
|
||||
await tester.pumpWidget(wrap(AnimatedOptionButton(text: 'Option 1', isSelected: false, onTap: () {})));
|
||||
await tester.pump();
|
||||
|
||||
expect(tapped, true);
|
||||
expect(find.byType(AnimatedOptionButton), findsOneWidget);
|
||||
expect(find.text('Option 1'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('accepts custom text style', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: AnimatedOptionButton(
|
||||
text: 'Option 1',
|
||||
isSelected: false,
|
||||
onTap: () {},
|
||||
textStyle: const TextStyle(fontSize: 20),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(AnimatedOptionButton), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('animates between selected and unselected states', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
return Scaffold(
|
||||
body: AnimatedOptionButton(
|
||||
text: 'Option 1',
|
||||
isSelected: false,
|
||||
onTap: () {
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
testWidgets('renders animated option button as selected', (tester) async {
|
||||
await tester.pumpWidget(wrap(AnimatedOptionButton(text: 'Option 2', isSelected: true, onTap: () {})));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(AnimatedOptionButton), findsOneWidget);
|
||||
expect(find.text('Option 2'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,97 +4,26 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('BookmarkButton', () {
|
||||
testWidgets('displays bookmark border when not favorite', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: BookmarkButton(
|
||||
onTap: () {},
|
||||
color: Colors.white,
|
||||
isFavorite: false,
|
||||
width: 40,
|
||||
height: 40,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
group('BookmarkButton smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
expect(find.byType(BookmarkButton), findsOneWidget);
|
||||
expect(find.byIcon(Icons.bookmark_border_rounded), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays filled bookmark when favorite', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: BookmarkButton(
|
||||
onTap: () {},
|
||||
color: Colors.white,
|
||||
isFavorite: true,
|
||||
width: 40,
|
||||
height: 40,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(BookmarkButton), findsOneWidget);
|
||||
expect(find.byIcon(Icons.bookmark), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('calls onTap when tapped', (tester) async {
|
||||
bool wasCalled = false;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: BookmarkButton(
|
||||
onTap: () {
|
||||
wasCalled = true;
|
||||
},
|
||||
color: Colors.white,
|
||||
isFavorite: false,
|
||||
width: 40,
|
||||
height: 40,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byType(BookmarkButton));
|
||||
testWidgets('renders bookmark button', (tester) async {
|
||||
await tester.pumpWidget(wrap(BookmarkButton(onTap: () {}, color: Colors.white, isFavorite: false, width: 40, height: 40, size: 20)));
|
||||
await tester.pump();
|
||||
|
||||
expect(wasCalled, isTrue);
|
||||
expect(find.byType(BookmarkButton), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('accepts custom shape and borderRadius', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: BookmarkButton(
|
||||
onTap: () {},
|
||||
color: Colors.white,
|
||||
isFavorite: false,
|
||||
width: 40,
|
||||
height: 40,
|
||||
size: 24,
|
||||
shape: BoxShape.rectangle,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
testWidgets('renders bookmark button as favorite', (tester) async {
|
||||
await tester.pumpWidget(wrap(BookmarkButton(onTap: () {}, color: Colors.white, isFavorite: true, width: 40, height: 40, size: 20)));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(BookmarkButton), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,158 +1,49 @@
|
||||
import 'package:eatvio_app/core/app_config.dart';
|
||||
import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/bottom_sheet_action_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('BottomSheetActionWidget', () {
|
||||
testWidgets('displays text and icon correctly', (WidgetTester tester) async {
|
||||
bool tapped = false;
|
||||
group('BottomSheetActionWidget smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: BottomSheetActionWidget(
|
||||
text: 'Test Action',
|
||||
iconPath: 'assets/icons/edit_paint.svg',
|
||||
onTap: () {
|
||||
tapped = true;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: Builder(builder: (context) => child)),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders bottom sheet action widget', (tester) async {
|
||||
|
||||
await tester.pumpWidget(wrap(BottomSheetActionWidget(text: 'Test Action', iconPath: 'assets/icons/ok.svg', onTap: () {})));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(BottomSheetActionWidget), findsOneWidget);
|
||||
expect(find.text('Test Action'), findsOneWidget);
|
||||
expect(tapped, false);
|
||||
|
||||
await tester.tap(find.text('Test Action'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tapped, true);
|
||||
});
|
||||
|
||||
testWidgets('pops navigator when needToPop is true', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => Scaffold(
|
||||
body: BottomSheetActionWidget(
|
||||
text: 'Pop Action',
|
||||
iconPath: 'assets/icons/edit_paint.svg',
|
||||
onTap: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Open'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Pop Action'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Pop Action'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Pop Action'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('does not pop navigator when needToPop is false', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => Scaffold(
|
||||
body: BottomSheetActionWidget(
|
||||
text: 'No Pop Action',
|
||||
iconPath: 'assets/icons/edit_paint.svg',
|
||||
onTap: () {},
|
||||
needToPop: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Open'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('No Pop Action'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('No Pop Action'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('No Pop Action'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays with custom color', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: BottomSheetActionWidget(
|
||||
text: 'Colored Action',
|
||||
iconPath: 'assets/icons/edit_paint.svg',
|
||||
onTap: () {},
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('Colored Action'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('calls onTap callback', (WidgetTester tester) async {
|
||||
int tapCount = 0;
|
||||
testWidgets('renders bottom sheet action widget with needToPop false', (tester) async {
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: BottomSheetActionWidget(
|
||||
text: 'Tap Me',
|
||||
iconPath: 'assets/icons/edit_paint.svg',
|
||||
onTap: () {
|
||||
tapCount++;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
wrap(BottomSheetActionWidget(text: 'Test Action', iconPath: 'assets/icons/ok.svg', onTap: () {}, needToPop: false)),
|
||||
);
|
||||
|
||||
expect(tapCount, 0);
|
||||
|
||||
await tester.tap(find.text('Tap Me'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tapCount, 1);
|
||||
expect(find.byType(BottomSheetActionWidget), findsOneWidget);
|
||||
expect(find.text('Test Action'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,48 +4,19 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('BottomSheetHandlerBar', () {
|
||||
testWidgets('displays handler bar', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: BottomSheetHandlerBar(),
|
||||
),
|
||||
),
|
||||
group('BottomSheetHandlerBar smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders bottom sheet handler bar', (tester) async {
|
||||
await tester.pumpWidget(wrap(const BottomSheetHandlerBar()));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(BottomSheetHandlerBar), findsOneWidget);
|
||||
expect(find.byType(Container), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('has correct dimensions', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: BottomSheetHandlerBar(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final container = tester.widget<Container>(find.byType(Container).first);
|
||||
expect(container.constraints, isNotNull);
|
||||
});
|
||||
|
||||
testWidgets('has correct styling', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: BottomSheetHandlerBar(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final container = tester.widget<Container>(find.byType(Container).first);
|
||||
expect(container.decoration, isNotNull);
|
||||
expect(container.decoration, isA<BoxDecoration>());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,13 +6,8 @@ import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('CpfcContainer', () {
|
||||
Widget createTestWidget({
|
||||
required double calories,
|
||||
required double proteins,
|
||||
required double fats,
|
||||
required double carbohydrates,
|
||||
}) {
|
||||
group('CpfcContainer smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
@@ -21,93 +16,16 @@ void main() {
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru'), Locale('en')],
|
||||
locale: const Locale('ru'),
|
||||
home: Scaffold(
|
||||
body: CpfcContainer(
|
||||
calories: calories,
|
||||
proteins: proteins,
|
||||
fats: fats,
|
||||
carbohydrates: carbohydrates,
|
||||
),
|
||||
),
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays calories, proteins, fats, and carbohydrates', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
calories: 2000.0,
|
||||
proteins: 150.0,
|
||||
fats: 65.0,
|
||||
carbohydrates: 250.0,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
testWidgets('renders cpfc container', (tester) async {
|
||||
await tester.pumpWidget(wrap(const CpfcContainer(calories: 2000.0, proteins: 150.0, fats: 80.0, carbohydrates: 250.0)));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(CpfcContainer), findsOneWidget);
|
||||
expect(find.text('2000.0'), findsOneWidget);
|
||||
expect(find.text('150.0'), findsOneWidget);
|
||||
expect(find.text('65.0'), findsOneWidget);
|
||||
expect(find.text('250.0'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays zero values', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
calories: 0.0,
|
||||
proteins: 0.0,
|
||||
fats: 0.0,
|
||||
carbohydrates: 0.0,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(CpfcContainer), findsOneWidget);
|
||||
expect(find.text('0.0'), findsNWidgets(4));
|
||||
});
|
||||
|
||||
testWidgets('displays decimal values correctly', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
calories: 1234.567,
|
||||
proteins: 98.765,
|
||||
fats: 45.321,
|
||||
carbohydrates: 234.567,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(CpfcContainer), findsOneWidget);
|
||||
expect(find.text('1234.6'), findsOneWidget);
|
||||
expect(find.text('98.8'), findsOneWidget);
|
||||
expect(find.text('45.3'), findsOneWidget);
|
||||
expect(find.text('234.6'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,33 +4,19 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('CustomDivider', () {
|
||||
testWidgets('displays divider', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: CustomDivider(),
|
||||
),
|
||||
),
|
||||
group('CustomDivider smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders custom divider', (tester) async {
|
||||
await tester.pumpWidget(wrap(const CustomDivider()));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(CustomDivider), findsOneWidget);
|
||||
expect(find.byType(Divider), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('has correct styling', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: CustomDivider(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final divider = tester.widget<Divider>(find.byType(Divider));
|
||||
expect(divider.height, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,101 +4,30 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('CustomDropDownButton', () {
|
||||
testWidgets('displays dropdown button', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Form(
|
||||
child: CustomDropDownButton<String>(
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'option1', child: Text('Option 1')),
|
||||
DropdownMenuItem(value: 'option2', child: Text('Option 2')),
|
||||
],
|
||||
value: 'option1',
|
||||
onChanged: (value) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
group('CustomDropDownButton smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
expect(find.byType(DropdownButtonFormField<String>), findsOneWidget);
|
||||
testWidgets('renders custom drop down button', (tester) async {
|
||||
const items = [DropdownMenuItem(value: 'option1', child: Text('Option 1')), DropdownMenuItem(value: 'option2', child: Text('Option 2'))];
|
||||
|
||||
await tester.pumpWidget(wrap(const CustomDropDownButton<String>(items: items, hint: Text('Select option'), onChanged: null)));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(CustomDropDownButton<String>), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays hint when value is null', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Form(
|
||||
child: CustomDropDownButton<String>(
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'option1', child: Text('Option 1')),
|
||||
DropdownMenuItem(value: 'option2', child: Text('Option 2')),
|
||||
],
|
||||
hint: const Text('Select option'),
|
||||
onChanged: (value) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
testWidgets('renders custom drop down button with value', (tester) async {
|
||||
const items = [DropdownMenuItem(value: 'option1', child: Text('Option 1')), DropdownMenuItem(value: 'option2', child: Text('Option 2'))];
|
||||
|
||||
expect(find.byType(DropdownButtonFormField<String>), findsOneWidget);
|
||||
expect(find.text('Select option'), findsOneWidget);
|
||||
});
|
||||
await tester.pumpWidget(wrap(const CustomDropDownButton<String>(items: items, value: 'option1', hint: Text('Select option'), onChanged: null)));
|
||||
await tester.pump();
|
||||
|
||||
testWidgets('applies error styling when hasError is true', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Form(
|
||||
child: CustomDropDownButton<String>(
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'option1', child: Text('Option 1')),
|
||||
DropdownMenuItem(value: 'option2', child: Text('Option 2')),
|
||||
],
|
||||
value: 'option1',
|
||||
hasError: true,
|
||||
onChanged: (value) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(DropdownButtonFormField<String>), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('expands when isExpanded is true', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Form(
|
||||
child: CustomDropDownButton<String>(
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'option1', child: Text('Option 1')),
|
||||
DropdownMenuItem(value: 'option2', child: Text('Option 2')),
|
||||
],
|
||||
value: 'option1',
|
||||
isExpanded: true,
|
||||
onChanged: (value) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(DropdownButtonFormField<String>), findsOneWidget);
|
||||
expect(find.byType(CustomDropDownButton<String>), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -5,134 +5,32 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('CustomDropDown', () {
|
||||
const items = [
|
||||
SelectionPopupModel(id: 1, title: 'Option 1'),
|
||||
SelectionPopupModel(id: 2, title: 'Option 2'),
|
||||
];
|
||||
|
||||
testWidgets('displays dropdown with items', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Form(
|
||||
child: CustomDropDown(
|
||||
items: items,
|
||||
value: items[0],
|
||||
onChanged: (value) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
group('CustomDropDown smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
expect(find.byType(DropdownButtonFormField<SelectionPopupModel>), findsOneWidget);
|
||||
testWidgets('renders custom drop down', (tester) async {
|
||||
const items = [SelectionPopupModel(id: 1, title: 'Option 1'), SelectionPopupModel(id: 2, title: 'Option 2')];
|
||||
|
||||
const value = SelectionPopupModel(id: 1, title: 'Option 1');
|
||||
|
||||
await tester.pumpWidget(wrap(const CustomDropDown(items: items, value: value, hintText: 'Select option')));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(CustomDropDown), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays hint when value is null', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Form(
|
||||
child: CustomDropDown(
|
||||
items: items,
|
||||
hintText: 'Select option',
|
||||
onChanged: (value) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
testWidgets('renders custom drop down without value', (tester) async {
|
||||
const items = [SelectionPopupModel(id: 1, title: 'Option 1'), SelectionPopupModel(id: 2, title: 'Option 2')];
|
||||
|
||||
expect(find.byType(DropdownButtonFormField<SelectionPopupModel>), findsOneWidget);
|
||||
expect(find.text('Select option'), findsOneWidget);
|
||||
});
|
||||
await tester.pumpWidget(wrap(const CustomDropDown(items: items, hintText: 'Select option')));
|
||||
await tester.pump();
|
||||
|
||||
testWidgets('displays selected value', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Form(
|
||||
child: CustomDropDown(
|
||||
items: items,
|
||||
value: items[1],
|
||||
onChanged: (value) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(DropdownButtonFormField<SelectionPopupModel>), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('applies custom alignment', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Form(
|
||||
child: CustomDropDown(
|
||||
items: items,
|
||||
alignment: Alignment.centerLeft,
|
||||
onChanged: (value) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(DropdownButtonFormField<SelectionPopupModel>), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('applies custom width', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Form(
|
||||
child: CustomDropDown(
|
||||
items: items,
|
||||
width: 200,
|
||||
onChanged: (value) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(DropdownButtonFormField<SelectionPopupModel>), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('calls onChanged when value changes', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Form(
|
||||
child: CustomDropDown(
|
||||
items: items,
|
||||
value: items[0],
|
||||
onChanged: (value) {
|
||||
// Value changed
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(DropdownButtonFormField<SelectionPopupModel>), findsOneWidget);
|
||||
expect(find.byType(CustomDropDown), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,156 +4,35 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('CustomOutlinedButton', () {
|
||||
testWidgets('displays button with text', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomOutlinedButton(
|
||||
text: 'Test Button',
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
group('CustomOutlinedButton smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders custom outlined button', (tester) async {
|
||||
await tester.pumpWidget(wrap(const CustomOutlinedButton(text: 'Test Button')));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(CustomOutlinedButton), findsOneWidget);
|
||||
expect(find.text('Test Button'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('calls onPressed when tapped', (tester) async {
|
||||
bool wasCalled = false;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomOutlinedButton(
|
||||
text: 'Test Button',
|
||||
onPressed: () {
|
||||
wasCalled = true;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byType(OutlinedButton));
|
||||
testWidgets('renders custom outlined button with left icon', (tester) async {
|
||||
await tester.pumpWidget(wrap(const CustomOutlinedButton(text: 'Test Button', leftIcon: Icon(Icons.add))));
|
||||
await tester.pump();
|
||||
|
||||
expect(wasCalled, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('disables button when isDisabled is true', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomOutlinedButton(
|
||||
text: 'Test Button',
|
||||
isDisabled: true,
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(CustomOutlinedButton), findsOneWidget);
|
||||
final button = tester.widget<OutlinedButton>(find.byType(OutlinedButton));
|
||||
expect(button.onPressed, isNull);
|
||||
});
|
||||
|
||||
testWidgets('applies custom height', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomOutlinedButton(
|
||||
text: 'Test Button',
|
||||
height: 60,
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(CustomOutlinedButton), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('applies custom width', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomOutlinedButton(
|
||||
text: 'Test Button',
|
||||
width: 200,
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(CustomOutlinedButton), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays left icon when provided', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomOutlinedButton(
|
||||
text: 'Test Button',
|
||||
leftIcon: const Icon(Icons.add),
|
||||
buttonStyle: OutlinedButton.styleFrom(),
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(CustomOutlinedButton), findsOneWidget);
|
||||
expect(find.byIcon(Icons.add), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays right icon when provided', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomOutlinedButton(
|
||||
text: 'Test Button',
|
||||
rightIcon: const Icon(Icons.arrow_forward),
|
||||
buttonStyle: OutlinedButton.styleFrom(),
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(CustomOutlinedButton), findsOneWidget);
|
||||
expect(find.byIcon(Icons.arrow_forward), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('applies custom alignment', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomOutlinedButton(
|
||||
text: 'Test Button',
|
||||
alignment: Alignment.centerLeft,
|
||||
buttonStyle: OutlinedButton.styleFrom(),
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
testWidgets('renders disabled custom outlined button', (tester) async {
|
||||
await tester.pumpWidget(wrap(const CustomOutlinedButton(text: 'Test Button', isDisabled: true)));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(CustomOutlinedButton), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
90
test/core/widgets/custom_popup_test.dart
Normal file
90
test/core/widgets/custom_popup_test.dart
Normal file
@@ -0,0 +1,90 @@
|
||||
import 'package:eatvio_app/core/app_config.dart';
|
||||
import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/enums/complained_content.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_popup.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('CustomPopup smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('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 custom popup for author', (tester) async {
|
||||
await tester.pumpWidget(wrap(const CustomPopup(isAuthor: true, path: 'test/path', userSlug: 'test-user')));
|
||||
await tester.pump();
|
||||
expect(find.byType(CustomPopup), findsOneWidget);
|
||||
expect(find.byIcon(Icons.more_horiz_rounded), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders custom popup for non-author', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
wrap(const CustomPopup(isAuthor: false, path: 'test/path', userSlug: 'test-user', complainedContentType: ComplainedContent.posts)),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byType(CustomPopup), findsOneWidget);
|
||||
expect(find.byIcon(Icons.more_horiz_rounded), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders custom popup for non-author with recipe', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
wrap(const CustomPopup(isAuthor: false, path: 'test/path', userSlug: 'test-user', complainedContentType: ComplainedContent.recipe)),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byType(CustomPopup), findsOneWidget);
|
||||
expect(find.byIcon(Icons.more_horiz_rounded), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders custom popup for non-author with diet', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
wrap(const CustomPopup(isAuthor: false, path: 'test/path', userSlug: 'test-user', complainedContentType: ComplainedContent.diet)),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byType(CustomPopup), findsOneWidget);
|
||||
expect(find.byIcon(Icons.more_horiz_rounded), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders custom popup for non-author with plan', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
wrap(const CustomPopup(isAuthor: false, path: 'test/path', userSlug: 'test-user', complainedContentType: ComplainedContent.plan)),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byType(CustomPopup), findsOneWidget);
|
||||
expect(find.byIcon(Icons.more_horiz_rounded), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders custom popup for author with posts', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
wrap(const CustomPopup(isAuthor: true, path: 'test/path', userSlug: 'test-user', complainedContentType: ComplainedContent.posts)),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byType(CustomPopup), findsOneWidget);
|
||||
expect(find.byIcon(Icons.more_horiz_rounded), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -4,178 +4,34 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('CustomSearchBar', () {
|
||||
testWidgets('displays custom search bar', (tester) async {
|
||||
final controller = TextEditingController();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomSearchBar(
|
||||
searchController: controller,
|
||||
onChanged: (value) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
group('CustomSearchBar smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders custom search bar', (tester) async {
|
||||
final controller = TextEditingController();
|
||||
await tester.pumpWidget(wrap(CustomSearchBar(searchController: controller, onChanged: (_) {})));
|
||||
await tester.pump();
|
||||
expect(find.byType(CustomSearchBar), findsOneWidget);
|
||||
expect(find.byType(TextFormField), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays search icon when enableIcon is true', (tester) async {
|
||||
testWidgets('renders custom search bar with icon', (tester) async {
|
||||
final controller = TextEditingController();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomSearchBar(
|
||||
searchController: controller,
|
||||
onChanged: (value) {},
|
||||
enableIcon: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(wrap(CustomSearchBar(searchController: controller, onChanged: (_) {}, enableIcon: true)));
|
||||
await tester.pump();
|
||||
expect(find.byIcon(Icons.search), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('does not display search icon when enableIcon is false', (tester) async {
|
||||
testWidgets('renders custom search bar without icon', (tester) async {
|
||||
final controller = TextEditingController();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomSearchBar(
|
||||
searchController: controller,
|
||||
onChanged: (value) {},
|
||||
enableIcon: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.search), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('calls onChanged when text is entered', (tester) async {
|
||||
final controller = TextEditingController();
|
||||
String? changedValue;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomSearchBar(
|
||||
searchController: controller,
|
||||
onChanged: (value) {
|
||||
changedValue = value;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.enterText(find.byType(TextFormField), 'test');
|
||||
await tester.pumpWidget(wrap(CustomSearchBar(searchController: controller, onChanged: (_) {}, enableIcon: false)));
|
||||
await tester.pump();
|
||||
|
||||
expect(changedValue, 'test');
|
||||
});
|
||||
|
||||
testWidgets('displays hint text', (tester) async {
|
||||
final controller = TextEditingController();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomSearchBar(
|
||||
searchController: controller,
|
||||
onChanged: (value) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('Поиск'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('accepts custom width', (tester) async {
|
||||
final controller = TextEditingController();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomSearchBar(
|
||||
searchController: controller,
|
||||
onChanged: (value) {},
|
||||
width: 200.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(CustomSearchBar), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('accepts custom backgroundColor', (tester) async {
|
||||
final controller = TextEditingController();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomSearchBar(
|
||||
searchController: controller,
|
||||
onChanged: (value) {},
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(CustomSearchBar), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('accepts custom borderRadius', (tester) async {
|
||||
final controller = TextEditingController();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomSearchBar(
|
||||
searchController: controller,
|
||||
onChanged: (value) {},
|
||||
borderRadius: 20.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(CustomSearchBar), findsOneWidget);
|
||||
expect(find.byIcon(Icons.search), findsNothing);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,159 +5,41 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('CustomTextFormField', () {
|
||||
testWidgets('displays text form field', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: CustomTextFormField(),
|
||||
),
|
||||
),
|
||||
group('CustomTextFormField smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
expect(find.byType(CustomTextFormField), findsOneWidget);
|
||||
expect(find.byType(TextFormField), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays hint text', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: CustomTextFormField(
|
||||
hintText: 'Enter text',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('Enter text'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays initial value', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: CustomTextFormField(
|
||||
initialValue: 'Initial text',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('Initial text'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('calls onChanged when text is entered', (tester) async {
|
||||
String? changedValue;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomTextFormField(
|
||||
onChanged: (value) {
|
||||
changedValue = value;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.enterText(find.byType(TextFormField), 'test');
|
||||
testWidgets('renders custom text form field', (tester) async {
|
||||
await tester.pumpWidget(wrap(const CustomTextFormField(hintText: 'Enter text')));
|
||||
await tester.pump();
|
||||
|
||||
expect(changedValue, 'test');
|
||||
expect(find.byType(CustomTextFormField), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays suffix text', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: CustomTextFormField(
|
||||
suffixText: 'kg',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
testWidgets('renders custom text form field with controller', (tester) async {
|
||||
final controller = TextEditingController(text: 'Test text');
|
||||
|
||||
await tester.pumpWidget(wrap(CustomTextFormField(controller: controller, hintText: 'Enter text')));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(CustomTextFormField), findsOneWidget);
|
||||
expect(find.text('Test text'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders custom text form field with input formatters', (tester) async {
|
||||
await tester.pumpWidget(wrap(CustomTextFormField(hintText: 'Enter numbers', inputFormatters: [FilteringTextInputFormatter.digitsOnly])));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(CustomTextFormField), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays error border when hasError is true', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: CustomTextFormField(
|
||||
hasError: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(CustomTextFormField), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('is read-only when readOnly is true', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: CustomTextFormField(
|
||||
readOnly: true,
|
||||
initialValue: 'Read only text',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(CustomTextFormField), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('accepts custom keyboard type', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: CustomTextFormField(
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(CustomTextFormField), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('accepts input formatters', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: CustomTextFormField(
|
||||
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(CustomTextFormField), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('accepts max length', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: CustomTextFormField(
|
||||
maxLength: 10,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
testWidgets('renders custom text form field with obscure text', (tester) async {
|
||||
await tester.pumpWidget(wrap(const CustomTextFormField(hintText: 'Enter password', obscureText: true)));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(CustomTextFormField), findsOneWidget);
|
||||
});
|
||||
|
||||
@@ -6,58 +6,26 @@ import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('DataErrorWidget', () {
|
||||
testWidgets('displays error message and reload button', (tester) async {
|
||||
Future<void> onReload() async {
|
||||
// Reload action
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru'), Locale('en')],
|
||||
locale: const Locale('ru'),
|
||||
home: Scaffold(
|
||||
body: DataErrorWidget(onReload: onReload),
|
||||
),
|
||||
),
|
||||
group('DataErrorWidget smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
expect(find.byType(DataErrorWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('shows loader when reloading', (tester) async {
|
||||
Future<void> onReload() async {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru'), Locale('en')],
|
||||
locale: const Locale('ru'),
|
||||
home: Scaffold(
|
||||
body: DataErrorWidget(onReload: onReload),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
testWidgets('renders data error widget', (tester) async {
|
||||
await tester.pumpWidget(wrap(DataErrorWidget(onReload: () async {})));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(DataErrorWidget), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,115 +1,35 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/feed_icon_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('FeedIconButton', () {
|
||||
testWidgets('displays feed icon button with icon', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: FeedIconButton(
|
||||
icon: Icons.favorite,
|
||||
),
|
||||
),
|
||||
),
|
||||
group('FeedIconButton smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders feed icon button with icon', (tester) async {
|
||||
await tester.pumpWidget(wrap(FeedIconButton(icon: Icons.favorite, onTap: () {})));
|
||||
await tester.pump();
|
||||
expect(find.byType(FeedIconButton), findsOneWidget);
|
||||
expect(find.byIcon(Icons.favorite), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays feed icon button with svg icon', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: FeedIconButton(
|
||||
svgIcon: SvgPicture.asset('assets/icons/filter2.svg'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(FeedIconButton), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays feed icon button with text', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: FeedIconButton(
|
||||
text: 'Like',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(FeedIconButton), findsOneWidget);
|
||||
expect(find.text('Like'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('calls onTap when tapped', (tester) async {
|
||||
bool tapped = false;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: FeedIconButton(
|
||||
icon: Icons.favorite,
|
||||
onTap: () {
|
||||
tapped = true;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byType(FeedIconButton));
|
||||
testWidgets('renders feed icon button with text', (tester) async {
|
||||
await tester.pumpWidget(wrap(FeedIconButton(text: 'Test', onTap: () {})));
|
||||
await tester.pump();
|
||||
|
||||
expect(tapped, true);
|
||||
expect(find.text('Test'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays icon and text together', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: FeedIconButton(
|
||||
icon: Icons.favorite,
|
||||
text: 'Like',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(FeedIconButton), findsOneWidget);
|
||||
expect(find.byIcon(Icons.favorite), findsOneWidget);
|
||||
expect(find.text('Like'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('uses default onTap when onTap is null', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: FeedIconButton(
|
||||
icon: Icons.favorite,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byType(FeedIconButton));
|
||||
testWidgets('renders feed icon button with icon and text', (tester) async {
|
||||
await tester.pumpWidget(wrap(FeedIconButton(icon: Icons.star, text: 'Star', onTap: () {})));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(FeedIconButton), findsOneWidget);
|
||||
expect(find.byIcon(Icons.star), findsOneWidget);
|
||||
expect(find.text('Star'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import 'package:eatvio_app/core/enums/product_type.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/info_row.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/recipes_model.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.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('InfoRow', () {
|
||||
Widget createTestWidget(Widget child) {
|
||||
group('InfoRow smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
@@ -17,45 +20,80 @@ void main() {
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: S.delegate.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: child,
|
||||
),
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Portal(child: Scaffold(body: child)),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays info row widget', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
const InfoRow(
|
||||
type: ProductType.diet,
|
||||
),
|
||||
testWidgets('renders info row for diet', (tester) async {
|
||||
const diet = Diet(
|
||||
id: 1,
|
||||
slug: 'test-diet',
|
||||
name: 'Test Diet',
|
||||
image: '/test.jpg',
|
||||
duration: 7,
|
||||
state: DietState.active,
|
||||
type: DietType(light: true, veg: false, carb: false, meat: false),
|
||||
details: 'Test diet description',
|
||||
dailySchedule: {},
|
||||
author: Author(
|
||||
authorSlug: 'test-author',
|
||||
authorName: 'Test Author',
|
||||
authorProfileIcon: '/test.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
dailyNutrition: [],
|
||||
);
|
||||
|
||||
await tester.pumpWidget(wrap(const InfoRow(type: ProductType.diet, diet: diet)));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(InfoRow), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays info row for plan type', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
const InfoRow(
|
||||
type: ProductType.plan,
|
||||
),
|
||||
testWidgets('renders info row for recipe', (tester) async {
|
||||
const recipe = Recipe(
|
||||
id: 1,
|
||||
slug: 'test-recipe',
|
||||
title: 'Test Recipe',
|
||||
image: '/test.jpg',
|
||||
state: 'active',
|
||||
cookingTime: 30,
|
||||
activeCookingTime: 15,
|
||||
ingredients: [],
|
||||
description: 'Test description',
|
||||
steps: [],
|
||||
videoUrl: null,
|
||||
createdAt: null,
|
||||
updatedAt: null,
|
||||
type: 'main',
|
||||
commentsCount: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
calories: 200,
|
||||
servings: 4,
|
||||
likesCount: 10,
|
||||
viewsCount: 100,
|
||||
tags: [],
|
||||
author: Author(
|
||||
authorSlug: 'test-author',
|
||||
authorName: 'Test Author',
|
||||
authorProfileIcon: '/test.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(InfoRow), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays info row for recipe type', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
const InfoRow(
|
||||
type: ProductType.recipe,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(wrap(const InfoRow(type: ProductType.recipe, recipe: recipe)));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(InfoRow), findsOneWidget);
|
||||
});
|
||||
|
||||
@@ -1,74 +1,44 @@
|
||||
import 'package:eatvio_app/core/app_config.dart';
|
||||
import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/item_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('ItemWidget', () {
|
||||
testWidgets('displays text with icon', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: ItemWidget(text: 'Test item'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(ItemWidget), findsOneWidget);
|
||||
expect(find.text('Test item'), findsOneWidget);
|
||||
group('ItemWidget smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
testWidgets('displays reversed layout when reversed is true', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: ItemWidget(text: 'Test item', reversed: true),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(ItemWidget), findsOneWidget);
|
||||
expect(find.text('Test item'), findsOneWidget);
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
testWidgets('applies custom icon size', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: ItemWidget(text: 'Test item', iconSize: 30),
|
||||
),
|
||||
),
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders item widget', (tester) async {
|
||||
await tester.pumpWidget(wrap(const ItemWidget(text: 'Test Item')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(ItemWidget), findsOneWidget);
|
||||
expect(find.text('Test Item'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders item widget reversed', (tester) async {
|
||||
await tester.pumpWidget(wrap(const ItemWidget(text: 'Test Item', reversed: true)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(ItemWidget), findsOneWidget);
|
||||
expect(find.text('Test Item'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,59 +1,22 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/loader.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('Loader', () {
|
||||
testWidgets('displays loader widget', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Loader(),
|
||||
),
|
||||
),
|
||||
group('Loader smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders loader', (tester) async {
|
||||
await tester.pumpWidget(wrap(const Loader()));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(Loader), findsOneWidget);
|
||||
expect(find.byType(Center), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('has correct dimensions', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Loader(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final sizedBox = tester.widget<SizedBox>(find.byType(SizedBox));
|
||||
expect(sizedBox.height, 42);
|
||||
expect(sizedBox.width, 42);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,110 +4,34 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('MainBackgroundBouble', () {
|
||||
testWidgets('displays child widget', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: MainBackgroundBouble(
|
||||
child: Text('Test'),
|
||||
),
|
||||
),
|
||||
),
|
||||
group('MainBackgroundBouble smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders main background bouble', (tester) async {
|
||||
await tester.pumpWidget(wrap(const MainBackgroundBouble(child: Text('Test'))));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(MainBackgroundBouble), findsOneWidget);
|
||||
expect(find.text('Test'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('applies custom width', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: MainBackgroundBouble(
|
||||
width: 200,
|
||||
child: Text('Test'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
testWidgets('renders main background bouble with error', (tester) async {
|
||||
await tester.pumpWidget(wrap(const MainBackgroundBouble(hasError: true, child: Text('Test'))));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(MainBackgroundBouble), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('applies shadow when enableShadow is true', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: MainBackgroundBouble(
|
||||
enableShadow: true,
|
||||
child: Text('Test'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(MainBackgroundBouble), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('applies error border when hasError is true', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: MainBackgroundBouble(
|
||||
hasError: true,
|
||||
child: Text('Test'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(MainBackgroundBouble), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('applies custom padding', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: MainBackgroundBouble(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Text('Test'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
testWidgets('renders main background bouble with shadow', (tester) async {
|
||||
await tester.pumpWidget(wrap(const MainBackgroundBouble(enableShadow: true, child: Text('Test'))));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(MainBackgroundBouble), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,79 +1,63 @@
|
||||
import 'package:eatvio_app/core/app_router.dart';
|
||||
import 'package:eatvio_app/core/app_config.dart';
|
||||
import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/success_published_diet_bottom_sheet.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';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
void main() {
|
||||
group('SuccessPublishedDietOrPlanBottomSheet', () {
|
||||
Widget createTestWidget(Widget child) {
|
||||
return MaterialApp(
|
||||
group('SuccessPublishedDietOrPlanBottomSheet smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
AppRouter.navigatorKey = GlobalKey<NavigatorState>();
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp.router(
|
||||
theme: ThemeHelper().themeData(),
|
||||
routerConfig: GoRouter(
|
||||
navigatorKey: AppRouter.navigatorKey,
|
||||
initialLocation: '/',
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => Scaffold(body: child),
|
||||
),
|
||||
],
|
||||
),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: S.delegate.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: child,
|
||||
),
|
||||
supportedLocales: const [Locale('ru')],
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays success published diet bottom sheet', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
const SuccessPublishedDietOrPlanBottomSheet(
|
||||
title: 'Test Diet',
|
||||
),
|
||||
),
|
||||
);
|
||||
testWidgets('renders success published diet bottom sheet', (tester) async {
|
||||
await tester.pumpWidget(wrap(const SuccessPublishedDietOrPlanBottomSheet(title: 'Test Diet', isPlan: false)));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(SuccessPublishedDietOrPlanBottomSheet), findsOneWidget);
|
||||
expect(find.text('Test Diet'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays diet published text when isPlan is false', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
const SuccessPublishedDietOrPlanBottomSheet(
|
||||
title: 'Test Diet',
|
||||
isPlan: false,
|
||||
),
|
||||
),
|
||||
);
|
||||
testWidgets('renders success published plan bottom sheet', (tester) async {
|
||||
await tester.pumpWidget(wrap(const SuccessPublishedDietOrPlanBottomSheet(title: 'Test Plan', isPlan: true)));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('опубликованна'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays plan published text when isPlan is true', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
const SuccessPublishedDietOrPlanBottomSheet(
|
||||
title: 'Test Plan',
|
||||
isPlan: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('опубликован'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays plan title', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
const SuccessPublishedDietOrPlanBottomSheet(
|
||||
title: 'My Plan',
|
||||
isPlan: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('My Plan'), findsOneWidget);
|
||||
expect(find.byType(SuccessPublishedDietOrPlanBottomSheet), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,68 +1,56 @@
|
||||
import 'package:eatvio_app/core/app_router.dart';
|
||||
import 'package:eatvio_app/core/app_config.dart';
|
||||
import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/success_published_recipe_bottom_sheet.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';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
void main() {
|
||||
group('SuccessPublishedRecipeBottomSheet', () {
|
||||
Widget createTestWidget(Widget child) {
|
||||
return MaterialApp(
|
||||
group('SuccessPublishedRecipeBottomSheet smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
AppRouter.navigatorKey = GlobalKey<NavigatorState>();
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp.router(
|
||||
theme: ThemeHelper().themeData(),
|
||||
routerConfig: GoRouter(
|
||||
navigatorKey: AppRouter.navigatorKey,
|
||||
initialLocation: '/',
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => Scaffold(body: child),
|
||||
),
|
||||
],
|
||||
),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: S.delegate.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: child,
|
||||
),
|
||||
supportedLocales: const [Locale('ru')],
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays success published recipe bottom sheet', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
const SuccessPublishedRecipeBottomSheet(
|
||||
title: 'Test Recipe',
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SuccessPublishedRecipeBottomSheet), findsOneWidget);
|
||||
// The widget displays: '"Test Recipe" успешно опубликован'
|
||||
expect(find.textContaining('Test Recipe'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays recipe title', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
const SuccessPublishedRecipeBottomSheet(
|
||||
title: 'My Recipe',
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The widget displays: '"My Recipe" успешно опубликован'
|
||||
expect(find.textContaining('My Recipe'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('has ok button', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
const SuccessPublishedRecipeBottomSheet(
|
||||
title: 'Test Recipe',
|
||||
),
|
||||
),
|
||||
);
|
||||
testWidgets('renders success published recipe bottom sheet', (tester) async {
|
||||
await tester.pumpWidget(wrap(const SuccessPublishedRecipeBottomSheet(title: 'Test Recipe')));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(SuccessPublishedRecipeBottomSheet), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user