forked from eatvio/eatvio_app
test(tests): add whitespace to multiple test files for consistency and improved readability
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
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/loader.dart';
|
||||
import 'package:eatvio_app/features/consultant_rating/models/rating_model.dart';
|
||||
import 'package:eatvio_app/features/consultant_rating/presentation/widgets/rating_history_widget.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';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
|
||||
void main() {
|
||||
group('RatingHistoryWidget', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Portal(
|
||||
child: Scaffold(body: SingleChildScrollView(child: child)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display loader when isLoading is true', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const widget = RatingHistoryWidget(isLoading: true, ratingHistory: []);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Loader), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display rating history items when isLoading is false', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final ratingHistory = [
|
||||
RatingModel(
|
||||
type: RatingEnum.addedRecipe,
|
||||
amount: 10,
|
||||
date: DateTime(2024, 1, 1),
|
||||
),
|
||||
RatingModel(
|
||||
type: RatingEnum.addedBlogPost,
|
||||
amount: 5,
|
||||
date: DateTime(2024, 1, 2),
|
||||
),
|
||||
];
|
||||
final widget = RatingHistoryWidget(isLoading: false, ratingHistory: ratingHistory);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Loader), findsNothing);
|
||||
expect(find.byType(ListView), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display empty list when ratingHistory is empty', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const widget = RatingHistoryWidget(isLoading: false, ratingHistory: []);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Loader), findsNothing);
|
||||
expect(find.byType(ListView), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display all rating types correctly', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final ratingHistory = [
|
||||
RatingModel(type: RatingEnum.addedRecipe, amount: 1, date: DateTime.now()),
|
||||
RatingModel(type: RatingEnum.addedPublicDiet, amount: 2, date: DateTime.now()),
|
||||
RatingModel(type: RatingEnum.addedBlogPost, amount: 3, date: DateTime.now()),
|
||||
RatingModel(type: RatingEnum.invitedUser, amount: 4, date: DateTime.now()),
|
||||
RatingModel(type: RatingEnum.hasMedicalDegree, amount: 5, date: DateTime.now()),
|
||||
RatingModel(type: RatingEnum.consulted, amount: 6, date: DateTime.now()),
|
||||
RatingModel(type: RatingEnum.addedGlossary, amount: 7, date: DateTime.now()),
|
||||
];
|
||||
final widget = RatingHistoryWidget(isLoading: false, ratingHistory: ratingHistory);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(ListView), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
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/loader.dart';
|
||||
import 'package:eatvio_app/features/consultant_rating/models/statistics_model.dart';
|
||||
import 'package:eatvio_app/features/consultant_rating/presentation/widgets/statistic_widget.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';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
|
||||
void main() {
|
||||
group('StatisticWidget', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Portal(
|
||||
child: Scaffold(body: SingleChildScrollView(child: child)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display loader when isLoading is true', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const widget = StatisticWidget(isLoading: true, statistics: null);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Loader), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display statistics when isLoading is false and statistics provided', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final statistics = StatisticsModel(
|
||||
countReferal: 10,
|
||||
blogPostsCount: 5,
|
||||
recipesCount: 3,
|
||||
dietsCount: 2,
|
||||
consultationsCount: 8,
|
||||
qwe: 1,
|
||||
);
|
||||
final widget = StatisticWidget(isLoading: false, statistics: statistics);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Loader), findsNothing);
|
||||
expect(find.text('10'), findsOneWidget);
|
||||
expect(find.text('5'), findsOneWidget);
|
||||
expect(find.text('3'), findsOneWidget);
|
||||
expect(find.text('2'), findsOneWidget);
|
||||
expect(find.text('8'), findsOneWidget);
|
||||
expect(find.text('1'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display zeros when statistics is null', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const widget = StatisticWidget(isLoading: false, statistics: null);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Loader), findsNothing);
|
||||
expect(find.text('0'), findsNWidgets(6));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user