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

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:fuel_tax_tracker/models/fuel_entry.dart';
@ -215,37 +216,59 @@ void main() {
testWidgets('date range selector filters totals and the list, and recolors the active label',
(tester) async {
// Aug 5 2026: within Current Month, Last 3 Months, and Year to Date.
// These dates are derived from "now" rather than written out, because
// the screen filters against DateTime.now() (see _DateRange.startDate).
// Fixed dates quietly change which bucket they land in as the calendar
// moves — an earlier version of this test hardcoded August dates and
// started failing the moment September arrived.
final now = DateTime.now();
final format = DateFormat.yMMMd();
// The 1st of this month: always inside all three ranges.
final recentDate = DateTime(now.year, now.month, 1);
// The 1st of last month: always inside Last 3 Months, never inside
// Current Month. Also inside Year to Date except in January, when
// "last month" lands in the previous year.
final midDate = DateTime(now.year, now.month - 1, 1);
final midInYearToDate = midDate.year == now.year;
// Jan 1 this year: always inside Year to Date. It only falls *outside*
// Last 3 Months from April onward — before that, Last 3 Months already
// reaches back to Jan 1 or earlier, so no date at all can be "Year to
// Date but not Last 3 Months" and that distinction isn't testable.
final oldDate = DateTime(now.year, 1, 1);
final oldOutsideLast3Months = oldDate.isBefore(DateTime(now.year, now.month - 2, 1));
// In January the 1st of this month *is* Jan 1, so these two would
// render the same date text and findsOneWidget would double-count.
final oldIsDistinctFromRecent = oldDate != recentDate;
final recentEntry = FuelEntry(
id: 'recent',
vehicleId: 'v1',
date: DateTime(2026, 8, 5),
date: recentDate,
gallons: 10,
pricePerGallon: 3,
totalCost: 30,
updatedAt: DateTime.utc(2026, 8, 5),
updatedAt: recentDate.toUtc(),
receiptDriveFileId: 'r1',
);
// Jul 1 2026: within Last 3 Months and Year to Date, not Current Month.
final midEntry = FuelEntry(
id: 'mid',
vehicleId: 'v1',
date: DateTime(2026, 7, 1),
date: midDate,
gallons: 20,
pricePerGallon: 3,
totalCost: 60,
updatedAt: DateTime.utc(2026, 7, 1),
updatedAt: midDate.toUtc(),
receiptDriveFileId: 'r2',
);
// Mar 1 2026: within Year to Date only.
final oldEntry = FuelEntry(
id: 'old',
vehicleId: 'v1',
date: DateTime(2026, 3, 1),
date: oldDate,
gallons: 40,
pricePerGallon: 3,
totalCost: 120,
updatedAt: DateTime.utc(2026, 3, 1),
updatedAt: oldDate.toUtc(),
receiptDriveFileId: 'r3',
);
final appState = AppState()
@ -264,27 +287,38 @@ void main() {
.widgetList<Text>(find.text(label))
.any((t) => t.style?.fontWeight == FontWeight.w800);
// Defaults to Year to Date: all three visible.
expect(find.text('Aug 5, 2026'), findsOneWidget);
expect(find.text('Jul 1, 2026'), findsOneWidget);
expect(find.text('Mar 1, 2026'), findsOneWidget);
// Defaults to Year to Date.
expect(find.text(format.format(recentDate)), findsOneWidget);
if (midInYearToDate) {
expect(find.text(format.format(midDate)), findsOneWidget);
}
if (oldIsDistinctFromRecent) {
expect(find.text(format.format(oldDate)), findsOneWidget);
}
expect(isBold('Year to Date'), isTrue, reason: 'selected by default');
await tester.tap(find.text('Last 3 Months'));
await tester.pumpAndSettle();
expect(find.text('Aug 5, 2026'), findsOneWidget);
expect(find.text('Jul 1, 2026'), findsOneWidget);
expect(find.text('Mar 1, 2026'), findsNothing, reason: 'older than 3 months back');
expect(find.text(format.format(recentDate)), findsOneWidget);
expect(find.text(format.format(midDate)), findsOneWidget,
reason: 'last month is always within the last three');
if (oldOutsideLast3Months) {
expect(find.text(format.format(oldDate)), findsNothing,
reason: 'older than three months back');
}
expect(isBold('Last 3 Months'), isTrue);
expect(isBold('Year to Date'), isFalse, reason: 'no longer selected');
await tester.tap(find.text('Current Month'));
await tester.pumpAndSettle();
expect(find.text('Aug 5, 2026'), findsOneWidget);
expect(find.text('Jul 1, 2026'), findsNothing, reason: 'not in the current month');
expect(find.text('Mar 1, 2026'), findsNothing);
expect(find.text(format.format(recentDate)), findsOneWidget);
expect(find.text(format.format(midDate)), findsNothing,
reason: 'not in the current month');
if (oldIsDistinctFromRecent) {
expect(find.text(format.format(oldDate)), findsNothing);
}
});
testWidgets(