fix(bienvenida): wire the welcome screen into the first-launch flow

This commit is contained in:
2026-07-29 15:49:44 +02:00
parent f3d744aeed
commit 2959941485
6 changed files with 265 additions and 8 deletions
@@ -0,0 +1,85 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/l10n/gen/app_localizations.dart';
import 'package:pluriwave/pantallas/pantalla_bienvenida.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// WU17b: `PantallaBienvenida.mostrarSiProcede` wires the welcome screen
/// into the genuine first-launch flow. WU17 built and tested the screen
/// fully in isolation, but nothing in `lib/app.dart` or `lib/main.dart`
/// ever referenced it — it was unreachable. These tests pin the actual
/// gap: the screen must show on a genuine first launch and never again
/// once `ServicioBienvenida` has recorded it as seen.
Widget _appConDisparador(GlobalKey<NavigatorState> navigatorKey) {
return MaterialApp(
navigatorKey: navigatorKey,
locale: const Locale('es'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Builder(
builder:
(context) => Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () => PantallaBienvenida.mostrarSiProcede(context),
child: const Text('disparar'),
),
),
),
),
);
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
testWidgets(
'first launch (no seen flag persisted) shows the welcome screen',
(tester) async {
SharedPreferences.setMockInitialValues({});
final navigatorKey = GlobalKey<NavigatorState>();
await tester.pumpWidget(_appConDisparador(navigatorKey));
await tester.tap(find.text('disparar'));
await tester.pumpAndSettle();
expect(find.byType(PantallaBienvenida), findsOneWidget);
},
);
testWidgets(
'second launch (seen flag already persisted) does not show it again',
(tester) async {
SharedPreferences.setMockInitialValues({
'pluri_bienvenida_vista_v1': true,
});
final navigatorKey = GlobalKey<NavigatorState>();
await tester.pumpWidget(_appConDisparador(navigatorKey));
await tester.tap(find.text('disparar'));
await tester.pumpAndSettle();
expect(find.byType(PantallaBienvenida), findsNothing);
},
);
testWidgets('showing it once persists the flag so a later check in the same '
'session skips it', (tester) async {
SharedPreferences.setMockInitialValues({});
final navigatorKey = GlobalKey<NavigatorState>();
await tester.pumpWidget(_appConDisparador(navigatorKey));
await tester.tap(find.text('disparar'));
await tester.pumpAndSettle();
expect(find.byType(PantallaBienvenida), findsOneWidget);
// Dismiss it the same way the CTA does (a plain pop), simulating the
// welcome screen being resolved before the next check ever happens.
navigatorKey.currentState!.pop();
await tester.pumpAndSettle();
await tester.tap(find.text('disparar'));
await tester.pumpAndSettle();
expect(find.byType(PantallaBienvenida), findsNothing);
});
}
@@ -0,0 +1,44 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/servicios/servicio_bienvenida.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// WU17b: `ServicioBienvenida` decides whether the first-run welcome
/// screen (`PantallaBienvenida`) is still due — same injectable-prefs,
/// versioned-key convention as `ServicioContenidoApp` (S3-R4), but a plain
/// boolean flag since this welcome is a one-time, not per-version, surface.
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('ServicioBienvenida', () {
test(
'debeMostrarBienvenida is true before it has ever been marked seen',
() async {
SharedPreferences.setMockInitialValues({});
final servicio = ServicioBienvenida();
expect(await servicio.debeMostrarBienvenida(), isTrue);
},
);
test(
'debeMostrarBienvenida is false after marcarBienvenidaVista',
() async {
SharedPreferences.setMockInitialValues({});
final servicio = ServicioBienvenida();
await servicio.marcarBienvenidaVista();
expect(await servicio.debeMostrarBienvenida(), isFalse);
},
);
test('respects a seen flag already persisted by a prior launch', () async {
SharedPreferences.setMockInitialValues({
'pluri_bienvenida_vista_v1': true,
});
final servicio = ServicioBienvenida();
expect(await servicio.debeMostrarBienvenida(), isFalse);
});
});
}