Add websocket support
This commit is contained in:
16 files changed
+1042
-168
No files matched your search
+53
-3
@@ -1,14 +1,64 @@
|
||||
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<BusylightUpdate>();
|
||||
|
||||
@override
|
||||
Future<BusylightStatus> getStatus() async => BusylightStatus.off;
|
||||
|
||||
@override
|
||||
Future<BusylightColor> getColor() async => BusylightColor.white;
|
||||
|
||||
@override
|
||||
Stream<BusylightUpdate> watchStatus() => updates.stream;
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('App smoke test — renders without crashing', (WidgetTester tester) async {
|
||||
testWidgets('App renders pushed status and brightness', (WidgetTester tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final service = _WidgetBusylightService();
|
||||
addTearDown(service.updates.close);
|
||||
await tester.pumpWidget(
|
||||
const ProviderScope(
|
||||
child: BusylightApp(),
|
||||
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<BrightnessSlider>(find.byType(BrightnessSlider)).value,
|
||||
0.7);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user