44 lines
1.1 KiB
Dart
44 lines
1.1 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:ikar/core/contacts/contact_presence.dart';
|
|
|
|
void main() {
|
|
final now = DateTime.utc(2026, 9, 5, 12);
|
|
final seconds = now.millisecondsSinceEpoch ~/ 1000;
|
|
|
|
test('missing or hidden last seen is unknown', () {
|
|
for (final value in [
|
|
null,
|
|
<String, dynamic>{},
|
|
{'status': 0},
|
|
{'seen': 0},
|
|
]) {
|
|
expect(contactPresence(value, now), ContactPresence.unknown);
|
|
}
|
|
});
|
|
|
|
test('server online and approximate statuses take precedence', () {
|
|
expect(contactPresence({'status': 1}, now), ContactPresence.online);
|
|
for (final status in [2, 3]) {
|
|
expect(
|
|
contactPresence({'status': status, 'seen': 1}, now),
|
|
ContactPresence.recently,
|
|
);
|
|
}
|
|
});
|
|
|
|
test('last seen uses seconds and a three day recent boundary', () {
|
|
expect(
|
|
contactPresence({
|
|
'seen': seconds - const Duration(days: 3).inSeconds,
|
|
}, now),
|
|
ContactPresence.recently,
|
|
);
|
|
expect(
|
|
contactPresence({
|
|
'seen': seconds - const Duration(days: 3).inSeconds - 1,
|
|
}, now),
|
|
ContactPresence.longAgo,
|
|
);
|
|
});
|
|
}
|