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:
@@ -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