73 lines
2.1 KiB
Dart
73 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:garden_planner/entities/plant.dart';
|
|
import 'package:garden_planner/widgets/content_widgets/dashboard_widgets/plant_drop.dart';
|
|
|
|
import '../../../helpers/plant_generator.dart';
|
|
|
|
void main() {
|
|
testWidgets('PlantDrop shold accept Plants', (WidgetTester tester) async {
|
|
bool isDropped = false;
|
|
Plant plant = PlantGenerator.getPlant();
|
|
Plant? droppedPlant;
|
|
|
|
// Arrange
|
|
onPlantDropped(Plant plant) {
|
|
isDropped = true;
|
|
droppedPlant = plant;
|
|
}
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: Column(
|
|
children: [
|
|
Expanded(
|
|
child: Draggable<Plant>(
|
|
key: const Key("darg"),
|
|
data: plant,
|
|
feedback: Container(
|
|
padding: const EdgeInsets.all(8),
|
|
margin: const EdgeInsets.all(4),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Image.asset(
|
|
plant.image.toString(),
|
|
width: 100,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
child: Image.asset(
|
|
plant.image.toString(),
|
|
width: 100,
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: PlantDrop(
|
|
onPlantDropped: onPlantDropped,
|
|
showSpaceRequirement: true,
|
|
key: const Key("drop"),
|
|
)),
|
|
],
|
|
)),
|
|
),
|
|
);
|
|
|
|
//Act
|
|
final TestGesture drag = await tester
|
|
.startGesture(tester.getCenter(find.byKey(const Key("darg"))));
|
|
await tester.pump();
|
|
await drag.moveTo(tester.getTopLeft(find.byKey(const Key("drop"))));
|
|
await drag.up();
|
|
await tester.pumpAndSettle();
|
|
|
|
// Assert
|
|
expect(isDropped, equals(true), reason: 'Plant was not dropped');
|
|
expect(droppedPlant, equals(plant),
|
|
reason: 'droppedPlant is not the right plant');
|
|
});
|
|
}
|