fix(iap): address code review defects in freemium/IAP change
Fixes 9 of 10 review findings (10th requires a manual Play Console step, no code change): 1. app.dart/banner_anuncio_superior.dart: move the top SafeArea inside BannerAnuncioSuperior so it only reserves status-bar height when an ad actually renders, restoring edge-to-edge layout for premium and free-unloaded users. 2. servicio_anuncios.dart: bound every interstitial await (load, presentation, and the injected implementation itself) with injectable timeouts so a callback that never fires can no longer hang a caller. 3. estado_entitlement.dart/hoja_premium.dart: expose a typed resultadoUsuario signal for purchase/restore failures and restore-found-nothing, with dedicated localized messages (compraError, restauracionSinCompras) across all 13 locales -- never the raw developer/exception string. 4. main.dart/servicio_consentimiento.dart: add a GDPR/UMP consent flow (ConsentInformation/ConsentForm) that gates Mobile Ads SDK init on canRequestAds(); premium users never see a consent form; failures degrade to no ads instead of crashing or blocking startup. 6. servicio_anuncios.dart: track real ad presentation (onAdShowedFullScreenContent) so a failed-to-show interstitial no longer consumes a session cap slot. 7. banner_anuncio_superior.dart: add an explicit load-attempted guard so repeated didChangeDependencies (e.g. entitlement notifyListeners during a purchase) can only ever trigger one banner load attempt. 8. servicio_anuncios.dart: make esPremium a required constructor parameter, matching the hardened contract already applied to EstadoAlarmas/EstadoGrabacion/EstadoRadio. 9. hoja_premium.dart: add a dedicated premiumActivo localized string instead of reusing the equalizer's equalizerActive translation, across all 13 locales. All fixes implemented RED-first (failing test before production code). Full suite: 1261 passed, 2 pre-existing skips, 0 failures. flutter analyze: 5 pre-existing issues only, 0 new. [version set]
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pluriwave/app.dart';
|
||||
import 'package:pluriwave/estado/estado_entitlement.dart';
|
||||
import 'package:pluriwave/servicios/servicio_anuncios.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
/// S1 (Tier 1 visual fidelity): the prototype (`t4`) never draws a global
|
||||
/// `AppBar` — every root owns its own 56px title row instead (see
|
||||
@@ -69,4 +75,64 @@ void main() {
|
||||
reason: 'the tutorial carousel must run before the what-is-new dialog',
|
||||
);
|
||||
});
|
||||
|
||||
group(
|
||||
'construirCuerpoPrincipal — banner y la status bar (FIX 1, code review)',
|
||||
() {
|
||||
setUp(() {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
});
|
||||
|
||||
Future<void> bombear(WidgetTester tester, {required bool premium}) async {
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(padding: EdgeInsets.only(top: 44)),
|
||||
child: MaterialApp(
|
||||
home: MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<EstadoEntitlement>(
|
||||
create: (_) => EstadoEntitlement(prefs: null),
|
||||
),
|
||||
Provider<ServicioAnuncios>(
|
||||
create: (_) => ServicioAnuncios(esPremium: () => premium),
|
||||
),
|
||||
],
|
||||
child: Scaffold(
|
||||
body: construirCuerpoPrincipal(
|
||||
contenido: const Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: Text('contenido'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'usuario premium: el contenido arranca en y=0 -- edge-to-edge, sin '
|
||||
'franja en blanco reservada para la status bar',
|
||||
(tester) async {
|
||||
await bombear(tester, premium: true);
|
||||
|
||||
expect(tester.getTopLeft(find.text('contenido')).dy, 0);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'usuario free con el banner aún sin cargar: el contenido arranca '
|
||||
'igualmente en y=0 -- misma posición edge-to-edge que antes del '
|
||||
'cambio, no una franja reservada de 44px hasta que el ad cargue',
|
||||
(tester) async {
|
||||
await bombear(tester, premium: false);
|
||||
|
||||
expect(tester.getTopLeft(find.text('contenido')).dy, 0);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -181,6 +181,122 @@ void main() {
|
||||
expect(estado.esPremium, isFalse);
|
||||
},
|
||||
);
|
||||
|
||||
group('resultadoUsuario (FIX 3, code review)', () {
|
||||
test(
|
||||
'un error en el flujo de compra expone ResultadoEntitlementUsuario.error',
|
||||
() async {
|
||||
final compras = _PuertoComprasFalso();
|
||||
addTearDown(compras.dispose);
|
||||
final estado = EstadoEntitlement(
|
||||
prefs: await SharedPreferences.getInstance(),
|
||||
compras: compras,
|
||||
);
|
||||
addTearDown(estado.dispose);
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
|
||||
expect(estado.resultadoUsuario, isNull);
|
||||
|
||||
unawaited(estado.comprar());
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
compras.emitir(const EventoCompra(TipoEventoCompra.error));
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
|
||||
expect(estado.resultadoUsuario, ResultadoEntitlementUsuario.error);
|
||||
},
|
||||
);
|
||||
|
||||
test('restaurar() sin compra previa expone su propio resultado '
|
||||
'(restauracionSinCompras), distinto de un error', () async {
|
||||
final compras = _PuertoComprasFalso();
|
||||
addTearDown(compras.dispose);
|
||||
final estado = EstadoEntitlement(
|
||||
prefs: await SharedPreferences.getInstance(),
|
||||
compras: compras,
|
||||
);
|
||||
addTearDown(estado.dispose);
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
|
||||
unawaited(estado.restaurar());
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
compras.emitir(const EventoCompra(TipoEventoCompra.noEncontrada));
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
|
||||
expect(
|
||||
estado.resultadoUsuario,
|
||||
ResultadoEntitlementUsuario.restauracionSinCompras,
|
||||
);
|
||||
expect(
|
||||
estado.resultadoUsuario,
|
||||
isNot(ResultadoEntitlementUsuario.error),
|
||||
);
|
||||
});
|
||||
|
||||
test('consumirResultadoUsuario() limpia la señal y notifica a los '
|
||||
'listeners', () async {
|
||||
final compras = _PuertoComprasFalso();
|
||||
addTearDown(compras.dispose);
|
||||
final estado = EstadoEntitlement(
|
||||
prefs: await SharedPreferences.getInstance(),
|
||||
compras: compras,
|
||||
);
|
||||
addTearDown(estado.dispose);
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
|
||||
unawaited(estado.comprar());
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
compras.emitir(const EventoCompra(TipoEventoCompra.error));
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(estado.resultadoUsuario, isNotNull);
|
||||
|
||||
var notificaciones = 0;
|
||||
estado.addListener(() => notificaciones++);
|
||||
estado.consumirResultadoUsuario();
|
||||
|
||||
expect(estado.resultadoUsuario, isNull);
|
||||
expect(notificaciones, greaterThan(0));
|
||||
|
||||
// También se limpia (probado por separado) el resultado de una
|
||||
// restauración sin compras.
|
||||
unawaited(estado.restaurar());
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
compras.emitir(const EventoCompra(TipoEventoCompra.noEncontrada));
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(estado.resultadoUsuario, isNotNull);
|
||||
|
||||
estado.consumirResultadoUsuario();
|
||||
expect(estado.resultadoUsuario, isNull);
|
||||
});
|
||||
|
||||
test(
|
||||
'nunca expone el texto interno/de desarrollador de EventoCompra.mensaje',
|
||||
() async {
|
||||
final compras = _PuertoComprasFalso();
|
||||
addTearDown(compras.dispose);
|
||||
final estado = EstadoEntitlement(
|
||||
prefs: await SharedPreferences.getInstance(),
|
||||
compras: compras,
|
||||
);
|
||||
addTearDown(estado.dispose);
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
|
||||
unawaited(estado.comprar());
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
compras.emitir(
|
||||
const EventoCompra(
|
||||
TipoEventoCompra.error,
|
||||
mensaje: 'Producto no encontrado en Play Console',
|
||||
),
|
||||
);
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
|
||||
// resultadoUsuario es un enum tipado -- estructuralmente incapaz
|
||||
// de filtrar el string interno de EventoCompra.mensaje hacia la
|
||||
// UI.
|
||||
expect(estado.resultadoUsuario, ResultadoEntitlementUsuario.error);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('esPremiumPersistido (headless, sin BuildContext)', () {
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pluriwave/servicios/servicio_anuncios.dart';
|
||||
|
||||
@@ -10,10 +13,12 @@ void main() {
|
||||
required DateTime Function() ahora,
|
||||
required bool premium,
|
||||
Future<bool> Function()? mostrarInterstitialImpl,
|
||||
Duration? timeoutIntentoInterstitial,
|
||||
}) => ServicioAnuncios(
|
||||
ahora: ahora,
|
||||
esPremium: () => premium,
|
||||
mostrarInterstitialImpl: mostrarInterstitialImpl ?? (() async => true),
|
||||
timeoutIntentoInterstitial: timeoutIntentoInterstitial,
|
||||
);
|
||||
|
||||
group('intentarInterstitial — cap de frecuencia', () {
|
||||
@@ -87,6 +92,75 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
group('intentarInterstitial — fallo al mostrar no consume el cupo', () {
|
||||
test('la implementación real de AdMob distingue presentación real de '
|
||||
'fallo de renderizado (FIX 6, code review): '
|
||||
'onAdShowedFullScreenContent debe estar instrumentado y el resultado '
|
||||
'de show() no puede ser un true incondicional', () {
|
||||
final source =
|
||||
File('lib/servicios/servicio_anuncios.dart').readAsStringSync();
|
||||
expect(
|
||||
source.contains('onAdShowedFullScreenContent'),
|
||||
isTrue,
|
||||
reason:
|
||||
'debe registrar si el anuncio realmente llegó a presentarse '
|
||||
'(onAdShowedFullScreenContent) para no devolver true tras un '
|
||||
'onAdFailedToShowFullScreenContent',
|
||||
);
|
||||
expect(
|
||||
source.contains('await cierreCompleter.future;\n return true;'),
|
||||
isFalse,
|
||||
reason:
|
||||
'el resultado de _mostrarInterstitialAdMob ya no puede ser un '
|
||||
'true incondicional tras el cierre -- debe reflejar si el '
|
||||
'anuncio realmente se presentó',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('intentarInterstitial — timeout acotado (FIX 2, code review)', () {
|
||||
test('una implementación que nunca completa resuelve false dentro del '
|
||||
'timeout inyectado y no consume el cupo', () async {
|
||||
final ahora = DateTime(2026, 1, 1, 10, 0);
|
||||
final nuncaCompleta = Completer<bool>();
|
||||
addTearDown(() {
|
||||
if (!nuncaCompleta.isCompleted) nuncaCompleta.complete(false);
|
||||
});
|
||||
final servicio = construir(
|
||||
ahora: () => ahora,
|
||||
premium: false,
|
||||
mostrarInterstitialImpl: () => nuncaCompleta.future,
|
||||
timeoutIntentoInterstitial: const Duration(milliseconds: 20),
|
||||
);
|
||||
|
||||
final resultado = await servicio.intentarInterstitial().timeout(
|
||||
const Duration(seconds: 2),
|
||||
);
|
||||
|
||||
expect(resultado, isFalse);
|
||||
// El cupo no se consumió: un intento posterior con una
|
||||
// implementación que SÍ resuelve sigue mostrando el anuncio.
|
||||
final servicioReal = construir(ahora: () => ahora, premium: false);
|
||||
expect(await servicioReal.intentarInterstitial(), isTrue);
|
||||
});
|
||||
|
||||
test('una implementación lenta pero que SÍ completa dentro del timeout '
|
||||
'sigue resolviendo con su resultado real', () async {
|
||||
final ahora = DateTime(2026, 1, 1, 10, 0);
|
||||
final servicio = construir(
|
||||
ahora: () => ahora,
|
||||
premium: false,
|
||||
mostrarInterstitialImpl: () async {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 5));
|
||||
return true;
|
||||
},
|
||||
timeoutIntentoInterstitial: const Duration(milliseconds: 200),
|
||||
);
|
||||
|
||||
expect(await servicio.intentarInterstitial(), isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('debeMostrarBanner', () {
|
||||
test('free: true', () {
|
||||
final servicio = construir(
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pluriwave/servicios/servicio_consentimiento.dart';
|
||||
|
||||
/// Fake [PuertoConsentimiento]: never touches the UMP plugin, lets each
|
||||
/// test drive the outcome of the consent flow directly.
|
||||
class _PuertoConsentimientoFalso implements PuertoConsentimiento {
|
||||
_PuertoConsentimientoFalso({this.resultado = true, this.lanzarError = false});
|
||||
|
||||
final bool resultado;
|
||||
final bool lanzarError;
|
||||
int llamadas = 0;
|
||||
|
||||
@override
|
||||
Future<bool> resolver() async {
|
||||
llamadas++;
|
||||
if (lanzarError) throw Exception('fallo simulado de UMP');
|
||||
return resultado;
|
||||
}
|
||||
}
|
||||
|
||||
/// FIX 4 (code review): no GDPR/UMP consent flow existed at all before
|
||||
/// this. [resolverConsentimientoAnuncios] is the pure/injectable
|
||||
/// orchestration seam -- testable with zero AdMob/UMP platform channels,
|
||||
/// mirroring `ServicioAnuncios`'s own testing strategy.
|
||||
void main() {
|
||||
group('resolverConsentimientoAnuncios', () {
|
||||
test('usuario premium: nunca toca el puerto de consentimiento (cero '
|
||||
'formularios para premium) y resuelve false', () async {
|
||||
final puerto = _PuertoConsentimientoFalso(resultado: true);
|
||||
|
||||
final permiso = await resolverConsentimientoAnuncios(
|
||||
esPremium: true,
|
||||
consentimiento: puerto,
|
||||
);
|
||||
|
||||
expect(permiso, isFalse);
|
||||
expect(puerto.llamadas, 0);
|
||||
});
|
||||
|
||||
test('usuario free: delega al puerto de consentimiento y devuelve su '
|
||||
'resultado (canRequestAds)', () async {
|
||||
final puerto = _PuertoConsentimientoFalso(resultado: true);
|
||||
|
||||
final permiso = await resolverConsentimientoAnuncios(
|
||||
esPremium: false,
|
||||
consentimiento: puerto,
|
||||
);
|
||||
|
||||
expect(permiso, isTrue);
|
||||
expect(puerto.llamadas, 1);
|
||||
});
|
||||
|
||||
test('usuario free, consentimiento no otorgado: nunca se piden anuncios '
|
||||
'(false)', () async {
|
||||
final puerto = _PuertoConsentimientoFalso(resultado: false);
|
||||
|
||||
final permiso = await resolverConsentimientoAnuncios(
|
||||
esPremium: false,
|
||||
consentimiento: puerto,
|
||||
);
|
||||
|
||||
expect(permiso, isFalse);
|
||||
});
|
||||
|
||||
test('un fallo del puerto de consentimiento degrada silenciosamente a '
|
||||
'false -- nunca se propaga ni bloquea al llamador', () async {
|
||||
final puerto = _PuertoConsentimientoFalso(lanzarError: true);
|
||||
|
||||
final permiso = await resolverConsentimientoAnuncios(
|
||||
esPremium: false,
|
||||
consentimiento: puerto,
|
||||
);
|
||||
|
||||
expect(permiso, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,11 +1,34 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pluriwave/estado/estado_entitlement.dart';
|
||||
import 'package:pluriwave/servicios/servicio_anuncios.dart';
|
||||
import 'package:pluriwave/servicios/servicio_compras.dart';
|
||||
import 'package:pluriwave/widgets/banner_anuncio_superior.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
/// Fake [PuertoCompras] (mirrors `app_test.dart`'s own fake): lets a test
|
||||
/// drive [EstadoEntitlement]'s purchase-stream `notifyListeners()` calls
|
||||
/// without touching `in_app_purchase`.
|
||||
class _PuertoComprasFalso implements PuertoCompras {
|
||||
final _eventos = StreamController<EventoCompra>.broadcast();
|
||||
|
||||
@override
|
||||
Stream<EventoCompra> get eventos => _eventos.stream;
|
||||
|
||||
@override
|
||||
Future<void> comprar() async {}
|
||||
|
||||
@override
|
||||
Future<void> restaurar() async {}
|
||||
|
||||
void emitir(EventoCompra evento) => _eventos.add(evento);
|
||||
|
||||
Future<void> dispose() => _eventos.close();
|
||||
}
|
||||
|
||||
/// Ad-display spec "Persistent Top Banner, Never Overlapping Content": the
|
||||
/// banner is entitlement-aware and reserves layout via a `Column`
|
||||
/// (`SizedBox.shrink()` collapses it to zero footprint) — never a `Stack`
|
||||
@@ -72,4 +95,66 @@ void main() {
|
||||
expect(tester.getSize(banner).height, 0);
|
||||
expect(find.text('contenido'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('didChangeDependencies repetido (ej. notifyListeners de '
|
||||
'EstadoEntitlement durante una compra en curso) dispara como mucho UN '
|
||||
'intento de carga real (FIX 7, code review)', (tester) async {
|
||||
final compras = _PuertoComprasFalso();
|
||||
addTearDown(compras.dispose);
|
||||
var intentosDeCarga = 0;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<EstadoEntitlement>(
|
||||
create: (_) => EstadoEntitlement(prefs: null, compras: compras),
|
||||
),
|
||||
Provider<ServicioAnuncios>(
|
||||
create: (_) => ServicioAnuncios(esPremium: () => false),
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
BannerAnuncioSuperior(
|
||||
alIntentarCargar: () => intentosDeCarga++,
|
||||
),
|
||||
const Expanded(child: Center(child: Text('contenido'))),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
|
||||
expect(
|
||||
intentosDeCarga,
|
||||
1,
|
||||
reason: 'el primer didChangeDependencies debe intentar UNA carga',
|
||||
);
|
||||
|
||||
// Cada uno de estos eventos hace que EstadoEntitlement llame a
|
||||
// notifyListeners() -- y como BannerAnuncioSuperior.build() hace
|
||||
// context.watch<EstadoEntitlement>(), cada notificación vuelve a
|
||||
// ejecutar didChangeDependencies() en este widget.
|
||||
compras.emitir(const EventoCompra(TipoEventoCompra.pendiente));
|
||||
await tester.pump();
|
||||
compras.emitir(const EventoCompra(TipoEventoCompra.cancelada));
|
||||
await tester.pump();
|
||||
compras.emitir(const EventoCompra(TipoEventoCompra.pendiente));
|
||||
await tester.pump();
|
||||
compras.emitir(const EventoCompra(TipoEventoCompra.error));
|
||||
await tester.pump();
|
||||
|
||||
expect(
|
||||
intentosDeCarga,
|
||||
1,
|
||||
reason:
|
||||
'cuatro notificaciones adicionales de EstadoEntitlement NO '
|
||||
'deben disparar cuatro cargas más -- solo la primera cuenta',
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pluriwave/estado/estado_entitlement.dart';
|
||||
import 'package:pluriwave/l10n/gen/app_localizations.dart';
|
||||
import 'package:pluriwave/servicios/servicio_compras.dart';
|
||||
import 'package:pluriwave/widgets/hoja_premium.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
/// Fake [PuertoCompras] (mirrors `app_test.dart`'s own fake): lets a test
|
||||
/// drive [EstadoEntitlement]'s purchase-stream events without touching
|
||||
/// `in_app_purchase`.
|
||||
class _PuertoComprasFalso implements PuertoCompras {
|
||||
final _eventos = StreamController<EventoCompra>.broadcast();
|
||||
|
||||
@override
|
||||
Stream<EventoCompra> get eventos => _eventos.stream;
|
||||
|
||||
@override
|
||||
Future<void> comprar() async {}
|
||||
|
||||
@override
|
||||
Future<void> restaurar() async {}
|
||||
|
||||
void emitir(EventoCompra evento) => _eventos.add(evento);
|
||||
|
||||
Future<void> dispose() => _eventos.close();
|
||||
}
|
||||
|
||||
/// FIX 3 / FIX 9 (code review): the paywall must show localized feedback for
|
||||
/// a failed purchase/restore, a distinct non-error confirmation when a
|
||||
/// restore finds nothing, and its own dedicated "premium active" string
|
||||
/// instead of reusing the equalizer's `equalizerActive` translation.
|
||||
void main() {
|
||||
setUp(() {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
});
|
||||
|
||||
late AppLocalizations l10n;
|
||||
|
||||
Future<EstadoEntitlement> bombear(
|
||||
WidgetTester tester, {
|
||||
required _PuertoComprasFalso compras,
|
||||
}) async {
|
||||
late EstadoEntitlement estado;
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<EstadoEntitlement>(
|
||||
create: (_) {
|
||||
estado = EstadoEntitlement(prefs: null, compras: compras);
|
||||
return estado;
|
||||
},
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
locale: const Locale('es'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const Scaffold(body: HojaPremium()),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
l10n = AppLocalizations.of(tester.element(find.byType(HojaPremium)));
|
||||
return estado;
|
||||
}
|
||||
|
||||
group(
|
||||
'FIX 9 — la etiqueta de premium activo es propia, no la del ecualizador',
|
||||
() {
|
||||
testWidgets(
|
||||
'usuario premium: muestra l10n.premiumActivo, nunca l10n.equalizerActive',
|
||||
(tester) async {
|
||||
SharedPreferences.setMockInitialValues({'compra_premium_v1': true});
|
||||
final compras = _PuertoComprasFalso();
|
||||
addTearDown(compras.dispose);
|
||||
await bombear(tester, compras: compras);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text(l10n.premiumActivo), findsOneWidget);
|
||||
expect(find.text(l10n.equalizerActive), findsNothing);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
group('FIX 3 — feedback de error/restauración en el paywall', () {
|
||||
testWidgets('un error de compra muestra el mensaje localizado genérico '
|
||||
'(l10n.compraError), nunca el texto interno de EventoCompra.mensaje', (
|
||||
tester,
|
||||
) async {
|
||||
final compras = _PuertoComprasFalso();
|
||||
addTearDown(compras.dispose);
|
||||
await bombear(tester, compras: compras);
|
||||
|
||||
compras.emitir(
|
||||
const EventoCompra(
|
||||
TipoEventoCompra.error,
|
||||
mensaje: 'Producto no encontrado en Play Console',
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text(l10n.compraError), findsOneWidget);
|
||||
expect(find.text('Producto no encontrado en Play Console'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('una restauración sin compras muestra su propia confirmación '
|
||||
'(l10n.restauracionSinCompras), distinta del mensaje de error', (
|
||||
tester,
|
||||
) async {
|
||||
final compras = _PuertoComprasFalso();
|
||||
addTearDown(compras.dispose);
|
||||
await bombear(tester, compras: compras);
|
||||
|
||||
compras.emitir(const EventoCompra(TipoEventoCompra.noEncontrada));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text(l10n.restauracionSinCompras), findsOneWidget);
|
||||
expect(find.text(l10n.compraError), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'descartar el mensaje de error llama a consumirResultadoUsuario() y '
|
||||
'lo oculta de la UI',
|
||||
(tester) async {
|
||||
final compras = _PuertoComprasFalso();
|
||||
addTearDown(compras.dispose);
|
||||
final estado = await bombear(tester, compras: compras);
|
||||
|
||||
compras.emitir(const EventoCompra(TipoEventoCompra.error));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.text(l10n.compraError), findsOneWidget);
|
||||
|
||||
await tester.tap(
|
||||
find.byKey(const ValueKey('hoja-premium-resultado-descartar')),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text(l10n.compraError), findsNothing);
|
||||
expect(estado.resultadoUsuario, isNull);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user