import 'dart:async'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:busylight_buddy/main.dart'; import 'package:busylight_buddy/models/busylight_color.dart'; import 'package:busylight_buddy/models/busylight_status.dart'; import 'package:busylight_buddy/providers/busylight_provider.dart'; import 'package:busylight_buddy/services/busylight_service.dart'; import 'package:busylight_buddy/widgets/brightness_slider.dart'; import 'package:shared_preferences/shared_preferences.dart'; class _WidgetBusylightService extends BusylightService { _WidgetBusylightService() : super(baseUrl: 'http://localhost'); final updates = StreamController(); @override Future getStatus() async => BusylightStatus.off; @override Future getColor() async => BusylightColor.white; @override Stream watchStatus() => updates.stream; } void main() { testWidgets('App renders pushed status and brightness', (WidgetTester tester) async { SharedPreferences.setMockInitialValues({}); final service = _WidgetBusylightService(); addTearDown(service.updates.close); await tester.pumpWidget( ProviderScope( overrides: [ busylightServiceProvider.overrideWithValue(service), ], child: const BusylightApp(), ), ); expect(find.text('BusyLight'), findsOneWidget); service.updates.add(const BusylightUpdate( status: BusylightStatus.off, color: BusylightColor.white, )); await tester.pumpAndSettle(); expect(find.text('OFF'), findsOneWidget); service.updates.add(const BusylightUpdate( status: BusylightStatus.busy, color: BusylightColor(r: 255, g: 0, b: 0, brightness: 0.7), )); await tester.pumpAndSettle(); expect(find.text('BUSY'), findsOneWidget); await tester.scrollUntilVisible( find.byType(BrightnessSlider), 300, scrollable: find.byType(Scrollable).first, ); expect(tester.widget(find.byType(BrightnessSlider)).value, 0.7); }); }