GardenPlanner/test/widgets/content_widgets/dashboard_widgets/plant_row_test.dart

57 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:garden_planner/entities/beet_row.dart';
import 'package:garden_planner/entities/plant.dart';
import 'package:garden_planner/entities/plant_in_row.dart';
import 'package:garden_planner/widgets/content_widgets/dashboard_widgets/plant_element.dart';
import 'package:garden_planner/widgets/content_widgets/dashboard_widgets/plant_row.dart';
import '../../../helpers/beet_repository_generator.dart';
import '../../../helpers/plant_generator.dart';
void main() {
testWidgets('PlantRow displays PlantElement widgets',
(WidgetTester tester) async {
final List<PlantInRow> plants = [
PlantInRow(position: 0, plant: PlantGenerator.getPlant()),
PlantInRow(position: 1, plant: PlantGenerator.getPlant2())
];
final beetRow = BeetRow(0);
beetRow.plants = plants;
int removePlantCount = 0;
onPlantDropped(Plant plant) {}
onPlantRemove(PlantInRow plantInRow) {
removePlantCount++;
}
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: PlantRow(
row: beetRow,
verticalSpace: 10.0,
onPlantDropped: onPlantDropped,
showSpaceRequirement: true,
beetRepository: BeetRepositoryGenerator.getBeetRepository(),
onPlantRemove: onPlantRemove,
showImages: true,
date: DateTime.now(),
),
),
),
);
final plantElementFinder = find.byType(PlantElement);
expect(plantElementFinder, findsNWidgets(plants.length),
reason: 'Plants are not added');
final deleteButtonFinder = find.byIcon(Icons.delete).first;
await tester.tap(deleteButtonFinder);
await tester.pump();
expect(removePlantCount, 1, reason: 'Plant was not removed');
});
}