From 41ef28f20bd458a7670f2ba824d7e4660a77596d Mon Sep 17 00:00:00 2001 From: iven Date: Sun, 7 Jun 2026 10:44:15 +0800 Subject: [PATCH] =?UTF-8?q?test(app):=20CalendarBloc=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=2031=20=E4=B8=AA=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/bloc/calendar_bloc_test.dart | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/test/features/calendar/bloc/calendar_bloc_test.dart b/app/test/features/calendar/bloc/calendar_bloc_test.dart index 79537d3..78ad809 100644 --- a/app/test/features/calendar/bloc/calendar_bloc_test.dart +++ b/app/test/features/calendar/bloc/calendar_bloc_test.dart @@ -108,6 +108,37 @@ void main() { expect(loaded.focusedMonth, DateTime(2026, 7, 1)); }); + // ===== 初始加载选中日期的日记 ===== + + test('CalendarMonthChanged 加载后自动填充 selectedDayJournals', () async { + // 在 6 月 15 日创建日记(避免 InMemoryJournalRepository 的边界排除问题) + final june15 = DateTime(2026, 6, 15); + await repo.createJournal(_makeEntry(id: 'j-today', date: june15)); + + // 用 6 月 15 日触发月份切换,selectedDay = 6月15日 + final state = await dispatch(CalendarMonthChanged(june15)); + final loaded = state as CalendarLoaded; + + // selectedDayJournals 应自动填充,无需手动 CalendarDaySelected + expect(loaded.selectedDayJournals, isNotEmpty); + expect(loaded.selectedDayJournals.length, 1); + expect(loaded.selectedDayJournals.first.id, 'j-today'); + }); + + test('CalendarMonthChanged 加载后 selectedDay 无日记时 selectedDayJournals 为空', () async { + // 在 6 月 15 日创建日记,但 selectedDay 是 6 月 10 日 + final june15 = DateTime(2026, 6, 15); + await repo.createJournal(_makeEntry(id: 'j-1', date: june15)); + + final state = await dispatch(CalendarMonthChanged(DateTime(2026, 6, 10))); + final loaded = state as CalendarLoaded; + + // selectedDay 是 6 月 10 日,日记在 6 月 15 日,所以 selectedDayJournals 应为空 + expect(loaded.selectedDayJournals, isEmpty); + // 但 journalsByDate 应有数据 + expect(loaded.journalsByDate, isNotEmpty); + }); + // ===== 日期选择 ===== test('CalendarDaySelected 有日记 → selectedDayJournals 不为空', () async {