feat(calendar): "what's due this month" — dedicated screen + inventory filter
Reuses the existing per-variety crop-calendar masks (sow/transplant/ flowering/fruiting/seed-harvest) — no schema change, no migration — to answer "qué toca este mes" across the whole inventory. Since the months are the grower's own record, there's no hemisphere assumption. - Repo: CalendarEntry + watchCalendar() (varieties with any recorded phase); VarietyListItem now carries sowMonths. - Dedicated CalendarScreen (/calendar): a month strip (defaults to the current month, intl month names) and varieties grouped by phase — actions (sow/transplant/harvest seed) above informational (flowering/ fruiting), each tinted, tap → variety detail; empty-month state. - Inventory filter: a 'this month' chip (shown only when some variety has a calendar) keeps what sows in the current month; folded into the attributes group + clear-filters. - Entry points: a live Home card + a drawer item. - i18n calendar block + menu.calendar (en/es/pt/ast). - Tests: calendar_test (watchCalendar, list carries sow-months, pure filter), calendar_screen_test (phase grouping, month switch, empty), plus the screen added to the small-screen overflow guard.
This commit is contained in:
parent
28e8318026
commit
171daabce3
19 changed files with 681 additions and 5 deletions
65
apps/app_seeds/test/data/calendar_test.dart
Normal file
65
apps/app_seeds/test/data/calendar_test.dart
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import 'package:drift/drift.dart' show Value;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/data/variety_repository.dart';
|
||||
import 'package:tane/db/database.dart';
|
||||
import 'package:tane/domain/crop_calendar.dart';
|
||||
import 'package:tane/state/inventory_cubit.dart';
|
||||
|
||||
import '../support/test_support.dart';
|
||||
|
||||
/// The aggregate crop calendar: `watchCalendar` surfaces every variety with a
|
||||
/// recorded phase, and the inventory carries sow-months for the "this month"
|
||||
/// filter.
|
||||
void main() {
|
||||
late AppDatabase db;
|
||||
setUp(() => db = newTestDatabase());
|
||||
tearDown(() => db.close());
|
||||
|
||||
test('watchCalendar emits varieties with a recorded phase, masks intact',
|
||||
() async {
|
||||
final repo = newTestRepository(db);
|
||||
final tomato = await repo.addQuickVariety(label: 'Tomate rosa');
|
||||
await repo.updateVariety(
|
||||
id: tomato,
|
||||
sowMonths: Value(monthsToMask([2, 3])), // Feb, Mar
|
||||
seedHarvestMonths: Value(monthsToMask([8])), // Aug
|
||||
);
|
||||
// A variety with no calendar at all is excluded.
|
||||
await repo.addQuickVariety(label: 'Sin calendario');
|
||||
|
||||
final entries = await repo.watchCalendar().first;
|
||||
expect(entries, hasLength(1));
|
||||
final e = entries.single;
|
||||
expect(e.label, 'Tomate rosa');
|
||||
expect(maskHasMonth(e.sowMonths, 3), isTrue);
|
||||
expect(maskHasMonth(e.sowMonths, 5), isFalse);
|
||||
expect(maskHasMonth(e.seedHarvestMonths, 8), isTrue);
|
||||
});
|
||||
|
||||
test('the inventory list carries sow-months', () async {
|
||||
final repo = newTestRepository(db);
|
||||
final id = await repo.addQuickVariety(label: 'Lechuga');
|
||||
await repo.updateVariety(id: id, sowMonths: Value(monthsToMask([9])));
|
||||
|
||||
final items = await repo.watchInventory().first;
|
||||
expect(items.single.sowMonths, monthsToMask([9]));
|
||||
});
|
||||
|
||||
test('the sow-this-month filter keeps only what sows in the pinned month', () {
|
||||
const march = 3;
|
||||
final sowsInMarch = _item('a', monthsToMask([3, 4]));
|
||||
final sowsInJune = _item('b', monthsToMask([6]));
|
||||
final noCalendar = _item('c', null);
|
||||
final state = InventoryState(
|
||||
items: [sowsInMarch, sowsInJune, noCalendar],
|
||||
sowThisMonthOnly: true,
|
||||
filterMonth: march,
|
||||
loading: false,
|
||||
);
|
||||
expect(state.visibleItems.map((i) => i.id), ['a']);
|
||||
expect(state.hasSowCalendar, isTrue);
|
||||
});
|
||||
}
|
||||
|
||||
VarietyListItem _item(String id, int? sowMonths) =>
|
||||
VarietyListItem(id: id, label: id, sowMonths: sowMonths);
|
||||
58
apps/app_seeds/test/ui/calendar_screen_test.dart
Normal file
58
apps/app_seeds/test/ui/calendar_screen_test.dart
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import 'package:drift/drift.dart' show Value;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/domain/crop_calendar.dart';
|
||||
import 'package:tane/i18n/strings.g.dart';
|
||||
import 'package:tane/ui/calendar_screen.dart';
|
||||
|
||||
import '../support/test_support.dart';
|
||||
|
||||
/// The "what's due this month" screen groups varieties by phase for the picked
|
||||
/// month, and switching months changes what's shown.
|
||||
void main() {
|
||||
testWidgets('shows a variety under Sow for its recorded month, hidden in others',
|
||||
(tester) async {
|
||||
final db = newTestDatabase();
|
||||
addTearDown(db.close);
|
||||
final repo = newTestRepository(db);
|
||||
final id = await repo.addQuickVariety(label: 'Rúcula');
|
||||
await repo.updateVariety(id: id, sowMonths: Value(monthsToMask([3])));
|
||||
|
||||
await tester.pumpWidget(wrapScreen(
|
||||
repository: repo,
|
||||
locale: AppLocale.es,
|
||||
child: const CalendarScreen(initialMonth: 3),
|
||||
));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(Key('calendar.entry.$id')), findsOneWidget);
|
||||
expect(find.text('Rúcula'), findsOneWidget);
|
||||
|
||||
// Jump to a month it doesn't sow in → empty state, entry gone.
|
||||
await tester.tap(find.byKey(const Key('calendar.month.6')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(Key('calendar.entry.$id')), findsNothing);
|
||||
|
||||
await disposeTree(tester);
|
||||
});
|
||||
|
||||
testWidgets('an empty month shows the "nothing" message', (tester) async {
|
||||
final db = newTestDatabase();
|
||||
addTearDown(db.close);
|
||||
final repo = newTestRepository(db);
|
||||
final id = await repo.addQuickVariety(label: 'Tomate');
|
||||
await repo.updateVariety(id: id, sowMonths: Value(monthsToMask([4])));
|
||||
|
||||
await tester.pumpWidget(wrapScreen(
|
||||
repository: repo,
|
||||
locale: AppLocale.es,
|
||||
child: const CalendarScreen(initialMonth: 1), // nothing in January
|
||||
));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(Key('calendar.entry.$id')), findsNothing);
|
||||
expect(find.byIcon(Icons.event_available), findsOneWidget);
|
||||
|
||||
await disposeTree(tester);
|
||||
});
|
||||
}
|
||||
|
|
@ -9,7 +9,10 @@ import 'package:tane/services/social_account_store.dart';
|
|||
import 'package:tane/services/social_connection.dart';
|
||||
import 'package:tane/services/social_service.dart';
|
||||
import 'package:tane/services/social_settings.dart';
|
||||
import 'package:drift/drift.dart' show Value;
|
||||
import 'package:tane/domain/crop_calendar.dart';
|
||||
import 'package:tane/ui/about_screen.dart';
|
||||
import 'package:tane/ui/calendar_screen.dart';
|
||||
import 'package:tane/ui/chat_screen.dart';
|
||||
import 'package:tane/ui/home_screen.dart';
|
||||
import 'package:tane/ui/intro_screen.dart';
|
||||
|
|
@ -294,6 +297,24 @@ void main() {
|
|||
await disposeTree(tester);
|
||||
});
|
||||
|
||||
testWidgets('the "this month" calendar fits a small screen', (tester) async {
|
||||
final db = newTestDatabase();
|
||||
addTearDown(db.close);
|
||||
final repo = newTestRepository(db);
|
||||
final id = await repo.addQuickVariety(
|
||||
label: 'Lechuga maravilla de verano', category: 'Asteráceas');
|
||||
await repo.updateVariety(id: id, sowMonths: Value(monthsToMask([3])));
|
||||
await pumpSmall(
|
||||
tester,
|
||||
wrapScreen(
|
||||
repository: repo,
|
||||
locale: AppLocale.es,
|
||||
child: const CalendarScreen(initialMonth: 3),
|
||||
),
|
||||
);
|
||||
await disposeTree(tester);
|
||||
});
|
||||
|
||||
// NOTE: the variety-detail screen is deliberately NOT overflow-checked here.
|
||||
// It reports a ~2px overflow on a RenderFlex that is already DISPOSED/DEFUNCT
|
||||
// — a transient stale frame while its cubit's Drift stream rebuilds during
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue