forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_sync_storage_refresh_test.dart
More file actions
83 lines (65 loc) · 2.93 KB
/
Copy pathauto_sync_storage_refresh_test.dart
File metadata and controls
83 lines (65 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/// Every Manage Storage clear must re-read the device's storage snapshot.
///
/// The Sync page's storage card renders the ring-status snapshot loaded in
/// `initState`. Clearing recordings while the page stayed open deleted the files
/// but left that snapshot untouched, so the card kept reporting the device full
/// (472 MB of 472 MB used, 12 KB free) until the user navigated away and back —
/// which re-ran the page-open read and showed the true 0 B.
///
/// All three actions are asserted individually. The defect was three handlers
/// that each had to remember the re-read, so a test covering only one of them
/// would let the other two regress.
library;
import 'package:flutter_test/flutter_test.dart';
import 'package:omi/pages/conversations/auto_sync_page.dart';
void main() {
/// Build the three actions over one shared call log, so each test can assert
/// what its action did and — just as importantly — what the others did not.
({
List<String> calls,
({Future<void> Function() synced, Future<void> Function() pending, Future<void> Function() all}) actions
}) subject({Future<void> Function()? clearPending}) {
final calls = <String>[];
return (
calls: calls,
actions: buildStorageClearActions(
clearSynced: () async => calls.add('clear synced'),
clearPending: clearPending ?? () async => calls.add('clear pending'),
clearAll: () async => calls.add('clear all'),
refreshDeviceStorage: () async => calls.add('refresh'),
),
);
}
test('clearing synced recordings re-reads the storage snapshot afterwards', () async {
final s = subject();
await s.actions.synced();
// Order is the whole point: a read taken before the clear returns the
// pre-clear numbers, which is the stale reading users were left looking at.
expect(s.calls, ['clear synced', 'refresh']);
});
test('clearing pending recordings re-reads the storage snapshot afterwards', () async {
final s = subject();
await s.actions.pending();
expect(s.calls, ['clear pending', 'refresh']);
});
test('clearing every recording re-reads the storage snapshot afterwards', () async {
final s = subject();
await s.actions.all();
expect(s.calls, ['clear all', 'refresh']);
});
test('each action clears only its own category', () async {
final s = subject();
await s.actions.pending();
expect(s.calls, isNot(contains('clear synced')));
expect(s.calls, isNot(contains('clear all')));
});
test('the storage snapshot is re-read even when the clear fails part-way', () async {
final s = subject(
clearPending: () async => throw StateError('device dropped the connection mid-delete'),
);
await expectLater(s.actions.pending(), throwsStateError);
// A clear that failed part-way still deleted some files, so the snapshot on
// screen is wrong in exactly the same way. The failure still surfaces.
expect(s.calls, ['refresh']);
});
}