GardenPlanner/test/widgets/content_widgets/dashboard_test.dart

85 lines
2.9 KiB
Dart
Raw Normal View History

2023-06-25 10:13:39 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:garden_planner/repositories/beet.repositories.dart';
import 'package:garden_planner/widgets/content_widgets/dashboard.dart';
import 'package:garden_planner/widgets/content_widgets/dashboard_widgets/plant_row.dart';
import 'package:garden_planner/widgets/content_widgets/dashboard_widgets/space/plant_row_horizontal_space.dart';
import 'package:garden_planner/widgets/content_widgets/dashboard_widgets/space/plant_row_space.dart';
import '../../helpers/beet_repository_generator.dart';
import '../../helpers/plant_generator.dart';
void main() {
late BeetRepository beetRepository;
setUp(() {
beetRepository = BeetRepositoryGenerator.getBeetRepository();
beetRepository.addNewRowToBeet();
beetRepository.addNewRowToBeet();
beetRepository.addPlantToRowById(0, PlantGenerator.getPlant());
beetRepository.addPlantToRowById(2, PlantGenerator.getPlant());
beetRepository.addPlantToRowById(2, PlantGenerator.getPlant2());
});
testWidgets('Displays all rows', (WidgetTester tester) async {
final currentDate = DateTime.now();
//Arrange
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Dashboard(
onPlantDroppedToRow: (rowIndex, plant) {},
onPlantRemoveFromRow: (rowIndex, plantInRow) {},
beetRepository: beetRepository,
showSpaceRequirement: false,
showImages: true,
currentDate: currentDate,
),
),
),
);
//Assert
expect(find.byType(SingleChildScrollView), findsOneWidget);
expect(find.byType(PlantRow), findsNWidgets(3), reason: '3 Rows are setup');
expect(find.byType(PlantRowHorizontalSpace), findsNothing,
reason: 'Vertical Space should be displayed');
expect(find.byType(PlantRowSpace), findsNothing,
reason: 'Vertical Space should be displayed');
});
testWidgets('Displays all rows show space', (WidgetTester tester) async {
final currentDate = DateTime.now();
//Arrange
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Dashboard(
onPlantDroppedToRow: (rowIndex, plant) {},
onPlantRemoveFromRow: (rowIndex, plantInRow) {},
beetRepository: beetRepository,
showSpaceRequirement: true,
showImages: true,
currentDate: currentDate,
),
),
),
);
//Assert
expect(find.byType(SingleChildScrollView), findsOneWidget);
expect(find.byType(PlantRow), findsNWidgets(3), reason: '3 Rows are setup');
expect(find.byType(PlantRowHorizontalSpace), findsNWidgets(2),
reason: 'Vertical Space should be displayed');
expect(find.byType(PlantRowSpace), findsNWidgets(2),
reason: 'Vertical Space should be displayed');
});
}