121 lines
3.5 KiB
Dart
121 lines
3.5 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter_test/flutter_test.dart';
|
||
|
import 'package:garden_planner/widgets/content_widgets/control_bar.dart';
|
||
|
|
||
|
void main() {
|
||
|
testWidgets('Control widget checkboxes working', (WidgetTester tester) async {
|
||
|
bool isShowSpaceChanged = false;
|
||
|
bool isImagesChanged = false;
|
||
|
|
||
|
//Arrange
|
||
|
await tester.pumpWidget(
|
||
|
MaterialApp(
|
||
|
home: Scaffold(
|
||
|
body: Control(
|
||
|
showSpaceRequirements: false,
|
||
|
onShowSpaceChanged: (value) => isShowSpaceChanged = true,
|
||
|
showImages: false,
|
||
|
onImagesChanged: (value) => isImagesChanged = true,
|
||
|
actionIsNeeded: false,
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
|
||
|
expect(find.byType(Checkbox), findsNWidgets(2));
|
||
|
|
||
|
// Act
|
||
|
await tester.tap(find.byType(Checkbox).at(0));
|
||
|
await tester.pump();
|
||
|
|
||
|
await tester.tap(find.byType(Checkbox).at(1));
|
||
|
await tester.pump();
|
||
|
|
||
|
// Assert
|
||
|
expect(isShowSpaceChanged, true, reason: 'Space value not changed');
|
||
|
expect(isImagesChanged, true, reason: 'Space value not changed');
|
||
|
});
|
||
|
|
||
|
testWidgets('Control widget Action needed false',
|
||
|
(WidgetTester tester) async {
|
||
|
//Arrange
|
||
|
await tester.pumpWidget(
|
||
|
MaterialApp(
|
||
|
home: Scaffold(
|
||
|
body: Control(
|
||
|
showSpaceRequirements: false,
|
||
|
onShowSpaceChanged: (value) => {},
|
||
|
showImages: false,
|
||
|
onImagesChanged: (value) => {},
|
||
|
actionIsNeeded: false,
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
|
||
|
// Assert
|
||
|
expect(find.byIcon(Icons.warning), findsNothing,
|
||
|
reason: 'sholud not be shown "Icon"');
|
||
|
expect(find.text("Aktion nötig"), findsNothing,
|
||
|
reason: 'sholud not be shown "Aktion nötig"');
|
||
|
expect(find.text("Nichts zu tun"), findsOneWidget,
|
||
|
reason: '"Nichts zu tun" should be displayed');
|
||
|
});
|
||
|
|
||
|
testWidgets('Control widget Action needed true >300',
|
||
|
(WidgetTester tester) async {
|
||
|
//Arrange
|
||
|
await tester.pumpWidget(
|
||
|
MaterialApp(
|
||
|
home: Scaffold(
|
||
|
body: SizedBox(
|
||
|
width: 800,
|
||
|
child: Control(
|
||
|
showSpaceRequirements: false,
|
||
|
onShowSpaceChanged: (value) => {},
|
||
|
showImages: false,
|
||
|
onImagesChanged: (value) => {},
|
||
|
actionIsNeeded: true,
|
||
|
),
|
||
|
)),
|
||
|
),
|
||
|
);
|
||
|
|
||
|
// Assert
|
||
|
expect(find.byIcon(Icons.warning), findsOneWidget,
|
||
|
reason: '"Icons." should be displayed');
|
||
|
expect(find.text('Aktion nötig'), findsOneWidget,
|
||
|
reason: '"Aktion nötig" should be display');
|
||
|
expect(find.text('Nichts zu tun'), findsNothing,
|
||
|
reason: 'sholud not be shown "Nichts zu tun"');
|
||
|
});
|
||
|
|
||
|
testWidgets('Control widget Action needed true <300',
|
||
|
(WidgetTester tester) async {
|
||
|
//Arrange
|
||
|
await tester.pumpWidget(
|
||
|
MaterialApp(
|
||
|
home: Scaffold(
|
||
|
body: SizedBox(
|
||
|
width: 290,
|
||
|
child: Control(
|
||
|
showSpaceRequirements: false,
|
||
|
onShowSpaceChanged: (value) => {},
|
||
|
showImages: false,
|
||
|
onImagesChanged: (value) => {},
|
||
|
actionIsNeeded: true,
|
||
|
),
|
||
|
)),
|
||
|
),
|
||
|
);
|
||
|
|
||
|
// Assert
|
||
|
expect(find.byIcon(Icons.warning), findsOneWidget,
|
||
|
reason: 'sholud not be shown because size is under 300');
|
||
|
expect(find.text('' "Aktion nötig"), findsNothing,
|
||
|
reason: 'sholud not be shown because size is under 300');
|
||
|
expect(find.text('Nichts zu tun'), findsNothing,
|
||
|
reason: 'sholud not be shown "Nichts zu tun"');
|
||
|
});
|
||
|
}
|