Adds a permanent, non-consumable premium unlock (EstadoEntitlement + PuertoCompras/ServicioComprasPlayBilling) that removes ads and unlocks alarm vacations, alarms past a 5-alarm free cap, recording start, and full Android Auto browsing. The phone equalizer stays free for everyone. - Entitlement is prefs-backed (compra_premium_v1), fail-open, and resolvable headlessly via esPremiumPersistido() for the Android Auto audio handler, which registers before runApp. - Android Auto reduced mode keeps the real root folder labels for free users; browsing into any of them (and playFromMediaId/playFromSearch/ skipToNext/skipToPrevious) is blocked at the getChildren/servicio_audio choke points, with a locked "Función Premium" item as the backstop. Current-station play/pause/stop stays untouched. A free -> premium transition actively invalidates the head unit's cached browse tree. - Ads (top banner + capped interstitial before adding a station or an alarm) are gated behind entitlement via ServicioAnuncios, using official Google test ad unit IDs pending AdMob provisioning. - Alarm cap UX shows an explanatory message with a secondary unlock action rather than a bare paywall jump; existing data is grandfathered. - 4 new localization keys translated across all 13 supported locales. Co-located tests use strict TDD (RED test before implementation) for every new pure-logic unit; full existing suite passes unchanged.
76 lines
2.7 KiB
Dart
76 lines
2.7 KiB
Dart
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/widgets/banner_anuncio_superior.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
/// 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`
|
|
/// overlay. AdMob's own `BannerAd.load()` cannot reach a real ad server in
|
|
/// `flutter test` (no plugin channel registered), so it always resolves to
|
|
/// "unloaded" here — exactly the same degrade-to-shrink path a genuine
|
|
/// failed load takes in production (never a crash, never a placeholder).
|
|
void main() {
|
|
setUp(() {
|
|
SharedPreferences.setMockInitialValues({});
|
|
});
|
|
|
|
Widget construir({required bool premium}) {
|
|
return MultiProvider(
|
|
providers: [
|
|
ChangeNotifierProvider<EstadoEntitlement>(
|
|
create: (_) {
|
|
final estado = EstadoEntitlement(prefs: null);
|
|
return estado;
|
|
},
|
|
),
|
|
Provider<ServicioAnuncios>(
|
|
create: (_) => ServicioAnuncios(esPremium: () => premium),
|
|
),
|
|
],
|
|
child: MaterialApp(
|
|
home: Scaffold(
|
|
body: Column(
|
|
children: [
|
|
const BannerAnuncioSuperior(),
|
|
const Expanded(child: Center(child: Text('contenido'))),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
testWidgets(
|
|
'usuario free sin anuncio cargado: colapsa a SizedBox.shrink (nunca overlay)',
|
|
(tester) async {
|
|
await tester.pumpWidget(construir(premium: false));
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 50));
|
|
|
|
final banner = find.byType(BannerAnuncioSuperior);
|
|
expect(banner, findsOneWidget);
|
|
// Collapsed to zero footprint (no ad ever loads in a widget test — no
|
|
// AdMob plugin channel registered) — a `SizedBox.shrink()`, not an
|
|
// overlay: the Column layout below it stays fully visible.
|
|
expect(tester.getSize(banner).height, 0);
|
|
expect(find.text('contenido'), findsOneWidget);
|
|
},
|
|
);
|
|
|
|
testWidgets('usuario premium: nunca intenta mostrar el banner', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(construir(premium: true));
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 50));
|
|
|
|
final banner = find.byType(BannerAnuncioSuperior);
|
|
expect(tester.getSize(banner).height, 0);
|
|
expect(find.text('contenido'), findsOneWidget);
|
|
});
|
|
}
|