@@ -3,11 +3,27 @@ import 'package:borneo_app/features/devices/view_models/grouped_devices_view_mod
33import 'package:borneo_app/core/models/scene_entity.dart' ;
44import 'package:borneo_app/core/models/events.dart' ;
55import 'package:flutter/material.dart' ;
6+ import 'package:flutter_gettext/flutter_gettext/gettext_localizations.dart' ;
67import '../../mocks/mocks.dart' ;
78import 'package:event_bus/event_bus.dart' ;
89import 'package:flutter_test/flutter_test.dart' hide EventDispatcher;
910import 'package:provider/provider.dart' ;
1011
12+ // A simple delegate that always returns [FakeGettext] so widgets
13+ // calling `GettextLocalizations.of(context)` don't crash.
14+ class _FakeGettextDelegate extends LocalizationsDelegate <GettextLocalizations > {
15+ const _FakeGettextDelegate ();
16+
17+ @override
18+ bool isSupported (Locale locale) => true ;
19+
20+ @override
21+ Future <GettextLocalizations > load (Locale locale) async => FakeGettext ();
22+
23+ @override
24+ bool shouldReload (covariant LocalizationsDelegate <GettextLocalizations > old) => false ;
25+ }
26+
1127void main () {
1228 testWidgets ('AppBar title updates when scene name changes' , (WidgetTester tester) async {
1329 final bus = EventBus ();
@@ -27,18 +43,22 @@ void main() {
2743
2844 await tester.pumpWidget (
2945 MaterialApp (
46+ localizationsDelegates: const [_FakeGettextDelegate ()],
47+ supportedLocales: const [Locale ('en' , 'US' )],
3048 home: ChangeNotifierProvider <GroupedDevicesViewModel >.value (value: vm, child: DevicesScreen ()),
3149 ),
3250 );
51+ // give the framework a chance to lay out slivers, etc.
52+ await tester.pumpAndSettle ();
3353
34- // initial title should reflect "Initial"
35- expect (find.textContaining ('Initial' ), findsOneWidget);
54+ // initial title should reflect the scene name via the translation string
55+ expect (find.textContaining ('Devices in Initial' ), findsOneWidget);
3656
3757 // modify scene name and fire event
3858 sceneMgr.currentScene = scene.copyWith (name: 'Updated' );
3959 bus.fire (SceneUpdatedEvent (sceneMgr.currentScene));
40- await tester.pump ();
60+ await tester.pumpAndSettle ();
4161
42- expect (find.textContaining ('Updated' ), findsOneWidget);
62+ expect (find.textContaining ('Devices in Updated' ), findsOneWidget);
4363 });
4464}
0 commit comments