File size: 2,156 Bytes
b225a21 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:auto_gpt_flutter_client/views/task/task_list_tile.dart';
import 'package:auto_gpt_flutter_client/models/task.dart';
void main() {
final Task testTask = Task(id: 1, title: "Sample Task");
testWidgets('TaskListTile displays the task title',
(WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: TaskListTile(task: testTask, onTap: () {}, onDelete: () {})));
expect(find.text('Sample Task'), findsOneWidget);
});
testWidgets('TaskListTile toggles isSelected state on tap',
(WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: TaskListTile(task: testTask, onTap: () {}, onDelete: () {})));
// Initially, the delete icon should not be present
expect(find.byIcon(Icons.close), findsNothing);
// Tap the tile
await tester.tap(find.text('Sample Task'));
await tester.pump();
// The delete icon should appear
expect(find.byIcon(Icons.close), findsOneWidget);
});
testWidgets('TaskListTile triggers onDelete when delete icon is tapped',
(WidgetTester tester) async {
bool wasDeleteCalled = false;
await tester.pumpWidget(MaterialApp(
home: TaskListTile(
task: testTask,
onTap: () {},
onDelete: () {
wasDeleteCalled = true;
})));
// Tap the tile to make the delete icon appear
await tester.tap(find.text('Sample Task'));
await tester.pump();
// Tap the delete icon
await tester.tap(find.byIcon(Icons.close));
await tester.pump();
expect(wasDeleteCalled, true);
});
testWidgets('TaskListTile triggers onTap when tapped',
(WidgetTester tester) async {
bool wasTapped = false;
await tester.pumpWidget(MaterialApp(
home: TaskListTile(
task: testTask,
onTap: () {
wasTapped = true;
},
onDelete: () {})));
// Tap the tile
await tester.tap(find.text('Sample Task'));
await tester.pump();
expect(wasTapped, true);
});
}
|