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 {