Temporary setup of alternative to advertisements

This commit is contained in:
Courtney Arnold 2026-09-19 20:45:59 -05:00
parent ad2d932842
commit 57a9793a40
14 changed files with 653 additions and 56 deletions

View file

@ -0,0 +1,85 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fuel_tax_tracker/widgets/ad_placeholder_screen.dart';
void main() {
/// Pushes the placeholder onto a real navigator so its self-dismissal
/// (which pops its own route) has something to pop.
///
/// Deliberately avoids [WidgetTester.pumpAndSettle] while the
/// auto-dismiss ticker is alive — that timer reschedules a frame every
/// second, so settling would spin until it timed out rather than
/// returning.
Future<void> pushPlaceholder(WidgetTester tester, {required bool mustConfirm}) async {
await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (context) => TextButton(
onPressed: () => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => AdPlaceholderScreen(mustConfirm: mustConfirm),
),
),
child: const Text('open'),
),
),
),
);
await tester.tap(find.text('open'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
}
group('auto-dismissing placeholder (report + fuel-save interstitials)', () {
testWidgets('shows the logo and the future-ad message, with no Continue button',
(tester) async {
await pushPlaceholder(tester, mustConfirm: false);
expect(find.text('ADVERTISEMENT'), findsOneWidget);
expect(find.byType(Image), findsOneWidget, reason: 'the app logo');
expect(find.text('An advertisement will appear here'), findsOneWidget);
expect(find.textContaining('Ads are not running yet'), findsOneWidget);
expect(find.text('Continue'), findsNothing,
reason: 'only the sync gate waits on the user');
// Let it close so the ticker is cancelled before the test ends.
await tester.pump(const Duration(seconds: 4));
await tester.pumpAndSettle();
});
testWidgets('counts down and closes itself after four seconds', (tester) async {
await pushPlaceholder(tester, mustConfirm: false);
expect(find.textContaining('Closing in'), findsOneWidget);
await tester.pump(const Duration(seconds: 3));
expect(find.text('ADVERTISEMENT'), findsOneWidget,
reason: 'still up three seconds in');
await tester.pump(const Duration(seconds: 1));
await tester.pumpAndSettle();
expect(find.text('ADVERTISEMENT'), findsNothing, reason: 'closed itself');
expect(find.text('open'), findsOneWidget, reason: 'back on the page underneath');
});
});
group('confirming placeholder (the cloud-sync gate)', () {
testWidgets('waits for Continue instead of closing on its own', (tester) async {
await pushPlaceholder(tester, mustConfirm: true);
expect(find.text('Continue'), findsOneWidget);
expect(find.textContaining('Closing in'), findsNothing,
reason: 'nothing counts down — the upload waits on the user');
await tester.pump(const Duration(seconds: 10));
expect(find.text('ADVERTISEMENT'), findsOneWidget,
reason: 'still up well past the auto-dismiss window');
await tester.tap(find.text('Continue'));
await tester.pumpAndSettle();
expect(find.text('ADVERTISEMENT'), findsNothing);
expect(find.text('open'), findsOneWidget);
});
});
}