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

@@ -57,7 +57,7 @@ void main() {
routes: [
GoRoute(
path: '/home',
builder: (context, state) => Scaffold(
builder: (context, state) => const Scaffold(
body: Center(child: Text('Home')),
),
),
@@ -81,7 +81,7 @@ void main() {
return MaterialApp.router(
routerConfig: router,
theme: ThemeHelper().themeData(),
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,

View File

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

View File

@@ -16,7 +16,7 @@ void main() {
Widget createTestWidget(ChatRoom chatRoom) {
return MaterialApp.router(
theme: ThemeHelper().themeData(),
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@@ -47,7 +47,7 @@ void main() {
}
testWidgets('displays chat room with user name', (tester) async {
final chatRoom = ChatRoom(
const chatRoom = ChatRoom(
id: 'test-id',
users: Users(
fromChatUser: ChatUser(
@@ -79,7 +79,7 @@ void main() {
testWidgets('displays chat room with last message', (tester) async {
final chatRoom = ChatRoom(
id: 'test-id',
users: Users(
users: const Users(
fromChatUser: ChatUser(
id: 1,
name: 'From User',
@@ -116,7 +116,7 @@ void main() {
});
testWidgets('displays chat room with unread messages count', (tester) async {
final chatRoom = ChatRoom(
const chatRoom = ChatRoom(
id: 'test-id',
users: Users(
fromChatUser: ChatUser(
@@ -148,7 +148,7 @@ void main() {
testWidgets('displays message from current user', (tester) async {
final chatRoom = ChatRoom(
id: 'test-id',
users: Users(
users: const Users(
fromChatUser: ChatUser(
id: 1,
name: 'From User',
@@ -187,7 +187,7 @@ void main() {
testWidgets('displays media attachment message', (tester) async {
final chatRoom = ChatRoom(
id: 'test-id',
users: Users(
users: const Users(
fromChatUser: ChatUser(
id: 1,
name: 'From User',
@@ -228,7 +228,7 @@ void main() {
final chatRoom = ChatRoom(
id: 'test-id',
users: Users(
fromChatUser: ChatUser(
fromChatUser: const ChatUser(
id: 1,
name: 'From User',
profilePhotoPath: null,

View File

@@ -9,7 +9,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: ValidationErrorWidget(error: 'Test error message'),
),
),
@@ -23,7 +23,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: ValidationErrorWidget(error: 'Test error'),
),
),
@@ -51,7 +51,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: ValidationErrorWidget(error: ''),
),
),

View File

@@ -24,7 +24,7 @@ void main() {
theme: ThemeHelper().themeData(),
home: BlocProvider<CreatePlanCubit>.value(
value: mockCubit,
child: Scaffold(
child: const Scaffold(
body: SelectExactOptionWidget(),
),
),

View File

@@ -25,7 +25,7 @@ void main() {
theme: ThemeHelper().themeData(),
home: BlocProvider<CreateRecipeCubit>.value(
value: mockCubit,
child: Scaffold(
child: const Scaffold(
body: TagsWidget(),
),
),
@@ -33,7 +33,7 @@ void main() {
}
testWidgets('displays tags widget', (tester) async {
final initialState = CreateRecipeState(
const initialState = CreateRecipeState(
entity: RecipeCreateEntity(
ingredients: [],
steps: [],
@@ -55,7 +55,7 @@ void main() {
});
testWidgets('displays existing tags', (tester) async {
final stateWithTags = CreateRecipeState(
const stateWithTags = CreateRecipeState(
entity: RecipeCreateEntity(
ingredients: [],
steps: [],
@@ -78,7 +78,7 @@ void main() {
});
testWidgets('calls addTag when add button is tapped', (tester) async {
final initialState = CreateRecipeState(
const initialState = CreateRecipeState(
entity: RecipeCreateEntity(
ingredients: [],
steps: [],

View File

@@ -24,7 +24,7 @@ void main() {
theme: ThemeHelper().themeData(),
home: BlocProvider<DiaryCubit>.value(
value: mockCubit,
child: Scaffold(
child: const Scaffold(
body: AddProductButtonWidget(),
),
),
@@ -32,7 +32,7 @@ void main() {
}
testWidgets('displays add product button widget', (tester) async {
final loadingState = DiaryState.loading();
const loadingState = DiaryState.loading();
when(mockCubit.state).thenReturn(loadingState);
when(mockCubit.stream).thenAnswer((_) => Stream.value(loadingState));

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 chosen diet widget content', (tester) async {
await tester.pumpWidget(
createTestWidget(
ChosenDietWidgetContent(
const ChosenDietWidgetContent(
currentDietDay: 5,
dietName: 'Test Diet',
dietDuration: 14,
@@ -42,7 +42,7 @@ void main() {
testWidgets('displays current day and duration', (tester) async {
await tester.pumpWidget(
createTestWidget(
ChosenDietWidgetContent(
const ChosenDietWidgetContent(
currentDietDay: 7,
dietName: 'Test Diet',
dietDuration: 21,
@@ -57,7 +57,7 @@ void main() {
testWidgets('displays diet name with underline', (tester) async {
await tester.pumpWidget(
createTestWidget(
ChosenDietWidgetContent(
const ChosenDietWidgetContent(
currentDietDay: 1,
dietName: 'My Diet',
dietDuration: 7,

View File

@@ -9,7 +9,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: CommentContainer(comment: 'Test comment'),
),
),
@@ -23,7 +23,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: CommentContainer(comment: ''),
),
),
@@ -37,7 +37,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: CommentContainer(comment: longComment),
),
),

View File

@@ -7,7 +7,7 @@ void main() {
group('ProductLoaderWidget', () {
testWidgets('displays product loader widget', (tester) async {
await tester.pumpWidget(
MaterialApp(
const MaterialApp(
home: Scaffold(
body: ProductLoaderWidget(),
),
@@ -20,7 +20,7 @@ void main() {
testWidgets('displays ListTile with activity indicator', (tester) async {
await tester.pumpWidget(
MaterialApp(
const MaterialApp(
home: Scaffold(
body: ProductLoaderWidget(),
),

View File

@@ -9,7 +9,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: InfoBouble(
children: [
Text('Test'),
@@ -29,7 +29,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: InfoBouble(
backgroundColor: Colors.blue,
children: [
@@ -47,7 +47,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: InfoBouble(
radius: 20,
children: [
@@ -65,7 +65,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: InfoBouble(
padding: EdgeInsets.all(16),
children: [
@@ -83,7 +83,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: InfoBouble(
mainAxisAlignment: MainAxisAlignment.center,
children: [

View File

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

View File

@@ -12,7 +12,7 @@ void main() {
home: Scaffold(
body: ChipGroup(
selectedChipIndex: 0,
chipsLabelList: ['All', 'Recipes', 'Diets'],
chipsLabelList: const ['All', 'Recipes', 'Diets'],
setSelectedChipIndex: (index) {},
),
),
@@ -29,7 +29,7 @@ void main() {
home: Scaffold(
body: ChipGroup(
selectedChipIndex: 0,
chipsLabelList: ['All', 'Recipes', 'Diets', 'Plans'],
chipsLabelList: const ['All', 'Recipes', 'Diets', 'Plans'],
setSelectedChipIndex: (index) {},
),
),
@@ -51,7 +51,7 @@ void main() {
home: Scaffold(
body: ChipGroup(
selectedChipIndex: 0,
chipsLabelList: ['All', 'Recipes', 'Diets'],
chipsLabelList: const ['All', 'Recipes', 'Diets'],
setSelectedChipIndex: (index) {
selectedIndex = index;
},
@@ -73,7 +73,7 @@ void main() {
home: Scaffold(
body: ChipGroup(
selectedChipIndex: 0,
chipsLabelList: [],
chipsLabelList: const [],
setSelectedChipIndex: (index) {},
),
),

View File

@@ -11,7 +11,7 @@ void main() {
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: ['Option 1', 'Option 2'],
chipsLabelList: const ['Option 1', 'Option 2'],
index: 0,
selectedChipIndex: 0,
onSelected: (selected) {},
@@ -30,7 +30,7 @@ void main() {
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: ['Option 1', 'Option 2'],
chipsLabelList: const ['Option 1', 'Option 2'],
index: 0,
selectedChipIndex: 0,
onSelected: (selected) {},
@@ -50,7 +50,7 @@ void main() {
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: ['Option 1', 'Option 2'],
chipsLabelList: const ['Option 1', 'Option 2'],
index: 1,
selectedChipIndex: 0,
onSelected: (selected) {},
@@ -70,10 +70,10 @@ void main() {
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: ['Option 1'],
chipsLabelList: const ['Option 1'],
index: 0,
selectedChipIndex: 0,
padding: EdgeInsets.all(16),
padding: const EdgeInsets.all(16),
onSelected: (selected) {},
),
),
@@ -89,7 +89,7 @@ void main() {
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: ['Option 1'],
chipsLabelList: const ['Option 1'],
index: 0,
selectedChipIndex: 0,
activeColor: Colors.blue,
@@ -110,7 +110,7 @@ void main() {
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChoiceChipWidget(
chipsLabelList: ['Option 1'],
chipsLabelList: const ['Option 1'],
index: 0,
selectedChipIndex: 0,
onSelected: (selected) {

View File

@@ -34,7 +34,7 @@ void main() {
Widget createTestWidget(FeedConsultantModel consultant) {
return MaterialApp.router(
theme: ThemeHelper().themeData(),
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@@ -66,7 +66,7 @@ void main() {
testWidgets('displays consultant information', (tester) async {
await mockNetworkImagesFor(() async {
final consultant = FeedConsultantModel(
const consultant = FeedConsultantModel(
slug: 'test-consultant',
name: 'Test Consultant',
photo: 'https://example.com/photo.jpg',
@@ -87,7 +87,7 @@ void main() {
testWidgets('displays consultant with badges', (tester) async {
await mockNetworkImagesFor(() async {
final consultant = FeedConsultantModel(
const consultant = FeedConsultantModel(
slug: 'test-consultant',
name: 'Test Consultant',
photo: 'https://example.com/photo.jpg',
@@ -110,7 +110,7 @@ void main() {
testWidgets('displays rating place', (tester) async {
await mockNetworkImagesFor(() async {
final consultant = FeedConsultantModel(
const consultant = FeedConsultantModel(
slug: 'test-consultant',
name: 'Test Consultant',
photo: 'https://example.com/photo.jpg',
@@ -129,7 +129,7 @@ void main() {
testWidgets('handles photo with https URL', (tester) async {
await mockNetworkImagesFor(() async {
final consultant = FeedConsultantModel(
const consultant = FeedConsultantModel(
slug: 'test-consultant',
name: 'Test Consultant',
photo: 'https://example.com/photo.jpg',
@@ -148,7 +148,7 @@ void main() {
testWidgets('handles photo without https URL', (tester) async {
await mockNetworkImagesFor(() async {
final consultant = FeedConsultantModel(
const consultant = FeedConsultantModel(
slug: 'test-consultant',
name: 'Test Consultant',
photo: '/storage/photo.jpg',

View File

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

View File

@@ -9,11 +9,9 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: FilterBadge(
filterBottomSheet: Container(
child: Text('Filter Bottom Sheet'),
),
filterBottomSheet: Text('Filter Bottom Sheet'),
),
),
),
@@ -27,11 +25,9 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: FilterBadge(
filterBottomSheet: Container(
child: Text('Filter Bottom Sheet'),
),
filterBottomSheet: Text('Filter Bottom Sheet'),
),
),
),

View File

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

View File

@@ -41,7 +41,7 @@ void main() {
Widget createTestWidget(Widget child) {
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: StatusWidget(status: Status.canceled),
),
),
@@ -23,7 +23,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: StatusWidget(status: Status.success),
),
),
@@ -37,7 +37,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
home: const Scaffold(
body: StatusWidget(status: Status.inProgress),
),
),

View File

@@ -36,7 +36,7 @@ void main() {
Widget createTestWidget(UserRegistrationSheet sheet) {
return MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@@ -54,7 +54,7 @@ void main() {
}
testWidgets('displays blood pressure screen', (tester) async {
final sheet = UserRegistrationSheet(
const sheet = UserRegistrationSheet(
firstName: 'Test',
lastName: 'User',
email: 'test@example.com',
@@ -90,7 +90,7 @@ void main() {
});
testWidgets('displays existing blood pressure values', (tester) async {
final sheet = UserRegistrationSheet(
const sheet = UserRegistrationSheet(
firstName: 'Test',
lastName: 'User',
email: 'test@example.com',
@@ -126,7 +126,7 @@ void main() {
});
testWidgets('displays dropdowns for hypo and hyper', (tester) async {
final sheet = UserRegistrationSheet(
const sheet = UserRegistrationSheet(
firstName: 'Test',
lastName: 'User',
email: 'test@example.com',

View File

@@ -36,7 +36,7 @@ void main() {
Widget createTestWidget(UserRegistrationSheet sheet) {
return MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@@ -54,7 +54,7 @@ void main() {
}
testWidgets('displays email field', (tester) async {
final sheet = UserRegistrationSheet(
const sheet = UserRegistrationSheet(
firstName: 'Test',
lastName: 'User',
email: '',
@@ -90,7 +90,7 @@ void main() {
});
testWidgets('displays password fields', (tester) async {
final sheet = UserRegistrationSheet(
const sheet = UserRegistrationSheet(
firstName: 'Test',
lastName: 'User',
email: 'test@example.com',
@@ -126,7 +126,7 @@ void main() {
});
testWidgets('initializes with existing values', (tester) async {
final sheet = UserRegistrationSheet(
const sheet = UserRegistrationSheet(
firstName: 'Test',
lastName: 'User',
email: 'test@example.com',

View File

@@ -36,7 +36,7 @@ void main() {
Widget createTestWidget(UserRegistrationSheet sheet) {
return MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: [
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@@ -54,7 +54,7 @@ void main() {
}
testWidgets('displays date of birth screen', (tester) async {
final sheet = UserRegistrationSheet(
const sheet = UserRegistrationSheet(
firstName: 'Test',
lastName: 'User',
email: 'test@example.com',
@@ -90,7 +90,7 @@ void main() {
});
testWidgets('displays existing birthdate when provided', (tester) async {
final sheet = UserRegistrationSheet(
const sheet = UserRegistrationSheet(
firstName: 'Test',
lastName: 'User',
email: 'test@example.com',
@@ -126,7 +126,7 @@ void main() {
});
testWidgets('displays calendar icon', (tester) async {
final sheet = UserRegistrationSheet(
const sheet = UserRegistrationSheet(
firstName: 'Test',
lastName: 'User',
email: 'test@example.com',

View File

@@ -33,7 +33,7 @@ void main() {
supportedLocales: const [Locale('ru')],
home: BlocProvider<RegistrationCubitV2>.value(
value: mockCubit,
child: Scaffold(
child: const Scaffold(
body: SexWidget(),
),
),

View File

@@ -34,7 +34,7 @@ void main() {
locale: const Locale('ru'),
home: BlocProvider<RegistrationCubitV2>.value(
value: mockCubit,
child: Scaffold(
child: const Scaffold(
body: StepWidget(),
),
),