cpd_2022_zi/test/widgets/widget_drop_down_test.dart

48 lines
1.4 KiB
Dart
Raw Normal View History

2023-03-06 12:09:01 +01:00
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:provider/provider.dart';
import 'package:smoke_cess_app/providers/input_provider.dart';
import 'package:smoke_cess_app/widgets/drop_down.dart';
void main() {
2023-03-06 19:12:31 +01:00
testWidgets('DropDown should display items and update input model',
(WidgetTester tester) async {
2023-03-06 12:09:01 +01:00
// Define the list of items
final items = ['Item 1', 'Item 2', 'Item 3'];
// Create an instance of the InputProvider and add it to the widget tree
final inputProvider = InputProvider();
await tester.pumpWidget(
MultiProvider(
providers: [
ChangeNotifierProvider.value(value: inputProvider),
],
child: MaterialApp(
home: Scaffold(
body: DropDown(items),
),
),
),
);
// Verify that the DropDown displays the first item
expect(find.text(items[0]), findsOneWidget);
// Tap the DropDown to open the menu
2023-03-06 19:12:31 +01:00
await tester.tap(find.byType(DropDown));
2023-03-06 12:09:01 +01:00
await tester.pump();
// Verify that the menu displays the correct items
for (final item in items) {
2023-03-06 19:12:31 +01:00
expect(find.text(item).first, findsOneWidget);
2023-03-06 12:09:01 +01:00
}
// Select the second item
2023-03-06 19:12:31 +01:00
await tester.tap(find.text(items[1]).last);
2023-03-06 12:09:01 +01:00
await tester.pump();
// Verify that the input model was updated with the selected item
expect(inputProvider.relapseCategory, equals(items[1]));
});
}