fix(offline-first): harden local schedule cache lookup and key normalization
This commit is contained in:
@@ -117,6 +117,67 @@ void main() {
|
||||
expect(staleKeys, isNot(contains('2026-03-01')));
|
||||
expect(staleKeys, isNot(contains('2026-04-30')));
|
||||
});
|
||||
|
||||
test('normalizes mixed date formats and de-duplicates same day rows', () {
|
||||
final status = ScheduleCacheStatus.fromSchedules(
|
||||
[
|
||||
DailyPrayerSchedule(
|
||||
date: '2026-4-6',
|
||||
imsak: '04:20',
|
||||
subuh: '04:30',
|
||||
terbit: '05:45',
|
||||
dhuha: '06:10',
|
||||
dzuhur: '11:55',
|
||||
ashar: '15:10',
|
||||
maghrib: '17:58',
|
||||
isya: '19:05',
|
||||
),
|
||||
DailyPrayerSchedule(
|
||||
date: '2026-04-06',
|
||||
imsak: '04:20',
|
||||
subuh: '04:30',
|
||||
terbit: '05:45',
|
||||
dhuha: '06:10',
|
||||
dzuhur: '11:55',
|
||||
ashar: '15:10',
|
||||
maghrib: '17:58',
|
||||
isya: '19:05',
|
||||
),
|
||||
DailyPrayerSchedule(
|
||||
date: '2026-04-07',
|
||||
imsak: '04:21',
|
||||
subuh: '04:31',
|
||||
terbit: '05:46',
|
||||
dhuha: '06:11',
|
||||
dzuhur: '11:56',
|
||||
ashar: '15:11',
|
||||
maghrib: '17:59',
|
||||
isya: '19:06',
|
||||
),
|
||||
],
|
||||
DateTime(2026, 4, 6),
|
||||
);
|
||||
|
||||
expect(status.startDate, DateTime(2026, 4, 6));
|
||||
expect(status.endDate, DateTime(2026, 4, 7));
|
||||
expect(status.cachedDays, 2);
|
||||
expect(status.daysUntilRefresh, 1);
|
||||
});
|
||||
|
||||
test('stale key helper accepts non-padded legacy keys', () {
|
||||
final staleKeys = SyncService.staleScheduleKeys(
|
||||
[
|
||||
'2026-4-6',
|
||||
'2026-5-1',
|
||||
'2026-6-1',
|
||||
],
|
||||
DateTime(2026, 4, 6),
|
||||
);
|
||||
|
||||
expect(staleKeys, contains('2026-6-1'));
|
||||
expect(staleKeys, isNot(contains('2026-4-6')));
|
||||
expect(staleKeys, isNot(contains('2026-5-1')));
|
||||
});
|
||||
});
|
||||
|
||||
group('AppUpdateInfo parsing', () {
|
||||
|
||||
Reference in New Issue
Block a user