widget refresh enhancements
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:marianum_mobile/background/widget_background_task.dart';
|
||||
|
||||
void main() {
|
||||
final now = DateTime(2026, 8, 6, 12, 0);
|
||||
|
||||
group('shouldSkipRefresh', () {
|
||||
test('skips when the snapshot is younger than the debounce window', () {
|
||||
expect(
|
||||
shouldSkipRefresh(
|
||||
fetchedAt: now.subtract(const Duration(minutes: 5)),
|
||||
now: now,
|
||||
force: false,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
test('refreshes when the snapshot is older than the debounce window', () {
|
||||
expect(
|
||||
shouldSkipRefresh(
|
||||
fetchedAt: now.subtract(const Duration(minutes: 15)),
|
||||
now: now,
|
||||
force: false,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('refreshes exactly at the debounce boundary', () {
|
||||
expect(
|
||||
shouldSkipRefresh(
|
||||
fetchedAt: now.subtract(WidgetBackgroundTask.refreshDebounce),
|
||||
now: now,
|
||||
force: false,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('force bypasses a fresh snapshot', () {
|
||||
expect(
|
||||
shouldSkipRefresh(
|
||||
fetchedAt: now.subtract(const Duration(minutes: 1)),
|
||||
now: now,
|
||||
force: true,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('refreshes when no snapshot exists yet', () {
|
||||
expect(shouldSkipRefresh(fetchedAt: null, now: now, force: false), isFalse);
|
||||
});
|
||||
|
||||
test('refreshes when fetchedAt lies in the future (clock change)', () {
|
||||
expect(
|
||||
shouldSkipRefresh(
|
||||
fetchedAt: now.add(const Duration(minutes: 5)),
|
||||
now: now,
|
||||
force: false,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user