forked from eatvio/eatvio_app
fix(chat): initialize startDate to current date when personal diet is not enabled and streamline widget layout for improved readability
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
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/features/profile/models/weight_model.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/widgets/imt_chart_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
|
||||
void main() {
|
||||
group('ImtChartWidget', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
await initializeDateFormatting('ru', null);
|
||||
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(),
|
||||
home: Portal(
|
||||
child: Scaffold(body: SingleChildScrollView(child: child)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display chart with empty weight points', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
const widget = ImtChartWidget(weightPoints: []);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
|
||||
// Assert
|
||||
expect(find.byType(ImtChartWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display chart with single weight point', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final weightPoints = [
|
||||
WeightModel(
|
||||
id: 1,
|
||||
userId: 1,
|
||||
weight: 70,
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
bmi: 23.5,
|
||||
),
|
||||
];
|
||||
final widget = ImtChartWidget(weightPoints: weightPoints);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
|
||||
// Assert
|
||||
expect(find.byType(ImtChartWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display chart with multiple weight points and show increase arrow', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final now = DateTime.now();
|
||||
final weightPoints = [
|
||||
WeightModel(
|
||||
id: 1,
|
||||
userId: 1,
|
||||
weight: 70,
|
||||
createdAt: now.subtract(const Duration(days: 7)),
|
||||
updatedAt: now.subtract(const Duration(days: 7)),
|
||||
bmi: 23.0,
|
||||
),
|
||||
WeightModel(
|
||||
id: 2,
|
||||
userId: 1,
|
||||
weight: 72,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
bmi: 24.0,
|
||||
),
|
||||
];
|
||||
final widget = ImtChartWidget(weightPoints: weightPoints);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
|
||||
// Assert
|
||||
expect(find.byType(ImtChartWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display chart with multiple weight points and show decrease arrow', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final now = DateTime.now();
|
||||
final weightPoints = [
|
||||
WeightModel(
|
||||
id: 1,
|
||||
userId: 1,
|
||||
weight: 72,
|
||||
createdAt: now.subtract(const Duration(days: 7)),
|
||||
updatedAt: now.subtract(const Duration(days: 7)),
|
||||
bmi: 24.0,
|
||||
),
|
||||
WeightModel(
|
||||
id: 2,
|
||||
userId: 1,
|
||||
weight: 70,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
bmi: 23.0,
|
||||
),
|
||||
];
|
||||
final widget = ImtChartWidget(weightPoints: weightPoints);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
|
||||
// Assert
|
||||
expect(find.byType(ImtChartWidget), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user