refactor(tests): replace 'final' with 'const' for improved performance in various test files

This commit is contained in:
mso7nueh
2025-12-08 11:32:40 +03:00
parent c2a506cdbf
commit 746d366c18
56 changed files with 199 additions and 254 deletions

View File

@@ -9,7 +9,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: AddItemButton(),
),
),
@@ -44,7 +44,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: AddItemButton(),
),
),

View File

@@ -73,7 +73,7 @@ void main() {
text: 'Option 1',
isSelected: false,
onTap: () {},
textStyle: TextStyle(fontSize: 20),
textStyle: const TextStyle(fontSize: 20),
),
),
),

View File

@@ -27,12 +27,12 @@ void main() {
body: BaseButton(
text: 'Test Button',
onPressed: () {},
buttonStyle: ButtonStyle(),
buttonTextStyle: TextStyle(),
buttonStyle: const ButtonStyle(),
buttonTextStyle: const TextStyle(),
isDisabled: false,
height: 50.0,
width: 100.0,
margin: EdgeInsets.all(10),
margin: const EdgeInsets.all(10),
alignment: Alignment.center,
),
),

View File

@@ -9,7 +9,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: BottomSheetHandlerBar(),
),
),
@@ -23,7 +23,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: BottomSheetHandlerBar(),
),
),

View File

@@ -16,10 +16,10 @@ void main() {
onPressed: () {
showBottomSheetWithBlur(
context: context,
child: Text('Test Content'),
child: const Text('Test Content'),
);
},
child: Text('Show Bottom Sheet'),
child: const Text('Show Bottom Sheet'),
),
);
},
@@ -44,11 +44,11 @@ void main() {
onPressed: () {
showBottomSheetWithBlur(
context: context,
child: Text('Test Content'),
child: const Text('Test Content'),
hasBlur: false,
);
},
child: Text('Show Bottom Sheet'),
child: const Text('Show Bottom Sheet'),
),
);
},
@@ -73,11 +73,11 @@ void main() {
onPressed: () {
showBottomSheetWithBlur(
context: context,
child: Text('Test Content'),
child: const Text('Test Content'),
height: 300.0,
);
},
child: Text('Show Bottom Sheet'),
child: const Text('Show Bottom Sheet'),
),
);
},
@@ -102,10 +102,10 @@ void main() {
onPressed: () {
showBottomSheetWithBlur(
context: context,
child: Text('Test Content'),
child: const Text('Test Content'),
);
},
child: Text('Show Bottom Sheet'),
child: const Text('Show Bottom Sheet'),
),
);
},
@@ -118,7 +118,7 @@ void main() {
expect(find.text('Test Content'), findsOneWidget);
await tester.tapAt(Offset(0, 0));
await tester.tapAt(const Offset(0, 0));
await tester.pumpAndSettle();
expect(find.text('Test Content'), findsNothing);

View File

@@ -15,7 +15,7 @@ void main() {
}) {
return MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,

View File

@@ -9,7 +9,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: CustomDivider(),
),
),
@@ -23,7 +23,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: CustomDivider(),
),
),

View File

@@ -12,7 +12,7 @@ void main() {
home: Scaffold(
body: Form(
child: CustomDropDownButton<String>(
items: [
items: const [
DropdownMenuItem(value: 'option1', child: Text('Option 1')),
DropdownMenuItem(value: 'option2', child: Text('Option 2')),
],
@@ -35,11 +35,11 @@ void main() {
home: Scaffold(
body: Form(
child: CustomDropDownButton<String>(
items: [
items: const [
DropdownMenuItem(value: 'option1', child: Text('Option 1')),
DropdownMenuItem(value: 'option2', child: Text('Option 2')),
],
hint: Text('Select option'),
hint: const Text('Select option'),
onChanged: (value) {},
),
),
@@ -59,7 +59,7 @@ void main() {
home: Scaffold(
body: Form(
child: CustomDropDownButton<String>(
items: [
items: const [
DropdownMenuItem(value: 'option1', child: Text('Option 1')),
DropdownMenuItem(value: 'option2', child: Text('Option 2')),
],
@@ -83,7 +83,7 @@ void main() {
home: Scaffold(
body: Form(
child: CustomDropDownButton<String>(
items: [
items: const [
DropdownMenuItem(value: 'option1', child: Text('Option 1')),
DropdownMenuItem(value: 'option2', child: Text('Option 2')),
],

View File

@@ -6,7 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
group('CustomDropDown', () {
final items = [
const items = [
SelectionPopupModel(id: 1, title: 'Option 1'),
SelectionPopupModel(id: 2, title: 'Option 2'),
];

View File

@@ -104,7 +104,7 @@ void main() {
home: Scaffold(
body: CustomOutlinedButton(
text: 'Test Button',
leftIcon: Icon(Icons.add),
leftIcon: const Icon(Icons.add),
buttonStyle: OutlinedButton.styleFrom(),
onPressed: () {},
),
@@ -124,7 +124,7 @@ void main() {
home: Scaffold(
body: CustomOutlinedButton(
text: 'Test Button',
rightIcon: Icon(Icons.arrow_forward),
rightIcon: const Icon(Icons.arrow_forward),
buttonStyle: OutlinedButton.styleFrom(),
onPressed: () {},
),

View File

@@ -10,7 +10,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: CustomTextFormField(),
),
),
@@ -24,7 +24,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: CustomTextFormField(
hintText: 'Enter text',
),
@@ -39,7 +39,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: CustomTextFormField(
initialValue: 'Initial text',
),
@@ -75,7 +75,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: CustomTextFormField(
suffixText: 'kg',
),
@@ -90,7 +90,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: CustomTextFormField(
hasError: true,
),
@@ -105,7 +105,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: CustomTextFormField(
readOnly: true,
initialValue: 'Read only text',
@@ -121,7 +121,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: CustomTextFormField(
keyboardType: TextInputType.number,
),
@@ -151,7 +151,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: CustomTextFormField(
maxLength: 10,
),

View File

@@ -15,7 +15,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@@ -35,13 +35,13 @@ void main() {
testWidgets('shows loader when reloading', (tester) async {
Future<void> onReload() async {
await Future.delayed(Duration(milliseconds: 100));
await Future.delayed(const Duration(milliseconds: 100));
}
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,

View File

@@ -10,7 +10,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: FeedIconButton(
icon: Icons.favorite,
),
@@ -41,7 +41,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: FeedIconButton(
text: 'Like',
),
@@ -79,7 +79,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: FeedIconButton(
icon: Icons.favorite,
text: 'Like',
@@ -97,7 +97,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: FeedIconButton(
icon: Icons.favorite,
),

View File

@@ -11,7 +11,7 @@ void main() {
Widget createTestWidget(Widget child) {
return MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@@ -27,7 +27,7 @@ void main() {
testWidgets('displays info row widget', (tester) async {
await tester.pumpWidget(
createTestWidget(
InfoRow(
const InfoRow(
type: ProductType.diet,
),
),
@@ -39,7 +39,7 @@ void main() {
testWidgets('displays info row for plan type', (tester) async {
await tester.pumpWidget(
createTestWidget(
InfoRow(
const InfoRow(
type: ProductType.plan,
),
),
@@ -51,7 +51,7 @@ void main() {
testWidgets('displays info row for recipe type', (tester) async {
await tester.pumpWidget(
createTestWidget(
InfoRow(
const InfoRow(
type: ProductType.recipe,
),
),

View File

@@ -9,7 +9,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: ItemWidget(text: 'Test item'),
),
),
@@ -23,7 +23,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: ItemWidget(text: 'Test item', reversed: true),
),
),
@@ -37,7 +37,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: ItemWidget(text: 'Test item', iconSize: 30),
),
),

View File

@@ -6,7 +6,7 @@ void main() {
group('Loader', () {
testWidgets('displays loader widget', (tester) async {
await tester.pumpWidget(
MaterialApp(
const MaterialApp(
home: Scaffold(
body: Loader(),
),
@@ -19,7 +19,7 @@ void main() {
testWidgets('has correct dimensions', (tester) async {
await tester.pumpWidget(
MaterialApp(
const MaterialApp(
home: Scaffold(
body: Loader(),
),

View File

@@ -9,7 +9,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: MainBackgroundBouble(
child: Text('Test'),
),
@@ -25,7 +25,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: MainBackgroundBouble(
width: 200,
child: Text('Test'),
@@ -41,7 +41,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: MainBackgroundBouble(
enableShadow: true,
child: Text('Test'),
@@ -57,7 +57,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: MainBackgroundBouble(
hasError: true,
child: Text('Test'),
@@ -73,7 +73,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: MainBackgroundBouble(
padding: EdgeInsets.all(16),
child: Text('Test'),

View File

@@ -10,7 +10,7 @@ void main() {
Widget createTestWidget(Widget child) {
return MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@@ -26,7 +26,7 @@ void main() {
testWidgets('displays marketing bottom sheet', (tester) async {
await tester.pumpWidget(
createTestWidget(
MarketingBottomSheet(),
const MarketingBottomSheet(),
),
);
@@ -37,7 +37,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@@ -51,7 +51,7 @@ void main() {
onPressed: () {
showMarketingBottomSheet(context);
},
child: Text('Show'),
child: const Text('Show'),
),
);
},

View File

@@ -11,50 +11,28 @@ void main() {
Widget createTestWidget(Widget child) {
return MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
home: Scaffold(
body: child,
),
home: Scaffold(body: child),
);
}
testWidgets('returns SizedBox.shrink when option is null', (tester) async {
await tester.pumpWidget(
createTestWidget(
OptionWidget(
option: null,
duration: 7,
),
),
);
await tester.pumpWidget(createTestWidget(const OptionWidget(option: null, duration: 7)));
expect(find.byType(OptionWidget), findsOneWidget);
expect(find.byType(SizedBox), findsWidgets);
});
testWidgets('displays option widget with option', (tester) async {
final option = PacketOptions(
items: ['Item 1', 'Item 2'],
price: 1000.0,
short: 'Short',
description: 'Description',
hasPersonalDiet: false,
);
const option = PacketOptions(items: ['Item 1', 'Item 2'], price: 1000.0, short: 'Short', description: 'Description', hasPersonalDiet: false);
await tester.pumpWidget(
createTestWidget(
OptionWidget(
option: option,
duration: 7,
),
),
);
await tester.pumpWidget(createTestWidget(const OptionWidget(option: option, duration: 7)));
expect(find.byType(OptionWidget), findsOneWidget);
expect(find.text('Short'), findsOneWidget);
@@ -62,47 +40,19 @@ void main() {
});
testWidgets('displays option widget with personal diet', (tester) async {
final option = PacketOptions(
items: ['Item 1'],
price: 1000.0,
short: 'Short',
description: 'Description',
hasPersonalDiet: true,
);
const option = PacketOptions(items: ['Item 1'], price: 1000.0, short: 'Short', description: 'Description', hasPersonalDiet: true);
await tester.pumpWidget(
createTestWidget(
OptionWidget(
option: option,
duration: 7,
),
),
);
await tester.pumpWidget(createTestWidget(const OptionWidget(option: option, duration: 7)));
expect(find.byType(OptionWidget), findsOneWidget);
});
testWidgets('hides duration when disableDuration is true', (tester) async {
final option = PacketOptions(
items: ['Item 1'],
price: 1000.0,
short: 'Short',
description: 'Description',
hasPersonalDiet: false,
);
const option = PacketOptions(items: ['Item 1'], price: 1000.0, short: 'Short', description: 'Description', hasPersonalDiet: false);
await tester.pumpWidget(
createTestWidget(
OptionWidget(
option: option,
duration: 7,
disableDuration: true,
),
),
);
await tester.pumpWidget(createTestWidget(const OptionWidget(option: option, duration: 7, disableDuration: true)));
expect(find.byType(OptionWidget), findsOneWidget);
});
});
}

View File

@@ -9,7 +9,7 @@ void main() {
testWidgets('displays error dialog with default title and description', (tester) async {
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@@ -23,7 +23,7 @@ void main() {
onPressed: () {
showErrorDialog(context);
},
child: Text('Show Error'),
child: const Text('Show Error'),
),
);
},
@@ -42,7 +42,7 @@ void main() {
testWidgets('displays error dialog with custom title and description', (tester) async {
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@@ -60,7 +60,7 @@ void main() {
description: 'Custom Description',
);
},
child: Text('Show Error'),
child: const Text('Show Error'),
),
);
},
@@ -78,7 +78,7 @@ void main() {
testWidgets('displays error dialog with custom button title', (tester) async {
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@@ -95,7 +95,7 @@ void main() {
buttonTitle: 'Close',
);
},
child: Text('Show Error'),
child: const Text('Show Error'),
),
);
},
@@ -112,7 +112,7 @@ void main() {
testWidgets('closes dialog when button is tapped', (tester) async {
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@@ -126,7 +126,7 @@ void main() {
onPressed: () {
showErrorDialog(context);
},
child: Text('Show Error'),
child: const Text('Show Error'),
),
);
},

View File

@@ -10,7 +10,7 @@ void main() {
Widget createTestWidget(Widget child) {
return MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@@ -26,7 +26,7 @@ void main() {
testWidgets('displays success published diet bottom sheet', (tester) async {
await tester.pumpWidget(
createTestWidget(
SuccessPublishedDietOrPlanBottomSheet(
const SuccessPublishedDietOrPlanBottomSheet(
title: 'Test Diet',
),
),
@@ -39,7 +39,7 @@ void main() {
testWidgets('displays diet published text when isPlan is false', (tester) async {
await tester.pumpWidget(
createTestWidget(
SuccessPublishedDietOrPlanBottomSheet(
const SuccessPublishedDietOrPlanBottomSheet(
title: 'Test Diet',
isPlan: false,
),
@@ -52,7 +52,7 @@ void main() {
testWidgets('displays plan published text when isPlan is true', (tester) async {
await tester.pumpWidget(
createTestWidget(
SuccessPublishedDietOrPlanBottomSheet(
const SuccessPublishedDietOrPlanBottomSheet(
title: 'Test Plan',
isPlan: true,
),
@@ -65,7 +65,7 @@ void main() {
testWidgets('displays plan title', (tester) async {
await tester.pumpWidget(
createTestWidget(
SuccessPublishedDietOrPlanBottomSheet(
const SuccessPublishedDietOrPlanBottomSheet(
title: 'My Plan',
isPlan: true,
),

View File

@@ -10,7 +10,7 @@ void main() {
Widget createTestWidget(Widget child) {
return MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@@ -26,7 +26,7 @@ void main() {
testWidgets('displays success published recipe bottom sheet', (tester) async {
await tester.pumpWidget(
createTestWidget(
SuccessPublishedRecipeBottomSheet(
const SuccessPublishedRecipeBottomSheet(
title: 'Test Recipe',
),
),
@@ -41,7 +41,7 @@ void main() {
testWidgets('displays recipe title', (tester) async {
await tester.pumpWidget(
createTestWidget(
SuccessPublishedRecipeBottomSheet(
const SuccessPublishedRecipeBottomSheet(
title: 'My Recipe',
),
),
@@ -55,7 +55,7 @@ void main() {
testWidgets('has ok button', (tester) async {
await tester.pumpWidget(
createTestWidget(
SuccessPublishedRecipeBottomSheet(
const SuccessPublishedRecipeBottomSheet(
title: 'Test Recipe',
),
),