48 lines
1.4 KiB
Dart
48 lines
1.4 KiB
Dart
|
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() {
|
||
|
testWidgets('DropDown should display items and update input model',
|
||
|
(WidgetTester tester) async {
|
||
|
// 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
|
||
|
await tester.tap(find.byType(DropDown));
|
||
|
await tester.pump();
|
||
|
|
||
|
// Verify that the menu displays the correct items
|
||
|
for (final item in items) {
|
||
|
expect(find.text(item).first, findsOneWidget);
|
||
|
}
|
||
|
|
||
|
// Select the second item
|
||
|
await tester.tap(find.text(items[1]).last);
|
||
|
await tester.pump();
|
||
|
|
||
|
// Verify that the input model was updated with the selected item
|
||
|
expect(inputProvider.relapseCategory, equals(items[1]));
|
||
|
});
|
||
|
}
|