2023-05-09 22:34:07 +00:00
|
|
|
import 'package:moxxyv2/service/database/helpers.dart';
|
2022-07-17 12:55:16 +00:00
|
|
|
import 'package:moxxyv2/shared/helpers.dart';
|
2021-12-24 22:26:45 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
void main() {
|
2022-07-17 12:55:16 +00:00
|
|
|
group('padInt', () {
|
2022-07-21 15:16:16 +00:00
|
|
|
test('0 should be padded to 00', () {
|
|
|
|
expect(padInt(0), '00');
|
|
|
|
});
|
|
|
|
test('5 should be padded to 05', () {
|
|
|
|
expect(padInt(5), '05');
|
|
|
|
});
|
|
|
|
test('23 should not be padded', () {
|
|
|
|
expect(padInt(25), '25');
|
|
|
|
});
|
|
|
|
test('99 should not be padded', () {
|
|
|
|
expect(padInt(99), '99');
|
|
|
|
});
|
2021-12-24 22:26:45 +00:00
|
|
|
});
|
2021-12-26 11:34:02 +00:00
|
|
|
|
2022-07-17 12:55:16 +00:00
|
|
|
group('formatConversationTimestamp', () {
|
2022-07-21 15:16:16 +00:00
|
|
|
test('Just now', () {
|
2023-03-06 04:49:10 +00:00
|
|
|
expect(
|
|
|
|
formatConversationTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 19, 40).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 26, 12, 20).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
'Just now',
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
formatConversationTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 18, 50).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 26, 12, 20).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
isNot('Just now'),
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
formatConversationTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 19).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 26, 12, 20).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
'Just now',
|
|
|
|
);
|
2022-07-21 15:16:16 +00:00
|
|
|
});
|
|
|
|
test('nh', () {
|
2023-03-06 04:49:10 +00:00
|
|
|
expect(
|
|
|
|
formatConversationTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 19, 40).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 26, 13, 20).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
'1h',
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
formatConversationTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 19, 40).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 26, 13, 19, 40).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
'1h',
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
formatConversationTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 19, 40).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 27, 11, 19, 40).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
'23h',
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
formatConversationTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 19, 40).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 27, 12, 19, 40).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
isNot('24h'),
|
|
|
|
);
|
2022-07-21 15:16:16 +00:00
|
|
|
});
|
|
|
|
test('yesterday', () {
|
2023-03-06 04:49:10 +00:00
|
|
|
expect(
|
|
|
|
formatConversationTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 20).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 27, 11, 20).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
isNot('Yesterday'),
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
formatConversationTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 19, 40).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 28, 11, 19, 40).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
isNot('Yesterday'),
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
formatConversationTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 19, 40).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 28, 12, 19, 40).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
isNot('Yesterday'),
|
|
|
|
);
|
2022-07-21 15:16:16 +00:00
|
|
|
});
|
|
|
|
test('date', () {
|
2023-03-06 04:49:10 +00:00
|
|
|
expect(
|
|
|
|
formatConversationTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 20).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 27, 12, 20).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
'26.12.',
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
formatConversationTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 20).millisecondsSinceEpoch,
|
|
|
|
DateTime(2022, 12, 27, 12, 20).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
'26.12.2021',
|
|
|
|
);
|
2022-07-21 15:16:16 +00:00
|
|
|
});
|
2021-12-26 12:30:34 +00:00
|
|
|
});
|
2021-12-26 12:41:36 +00:00
|
|
|
|
2022-07-17 12:55:16 +00:00
|
|
|
group('formatMessageTimestamp', () {
|
2022-07-21 15:16:16 +00:00
|
|
|
test('Just noww', () {
|
2023-03-06 04:49:10 +00:00
|
|
|
expect(
|
|
|
|
formatMessageTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 20).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 26, 12, 20).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
'Just now',
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
formatMessageTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 20).millisecondsSinceEpoch,
|
|
|
|
DateTime(2022, 12, 26, 12, 21).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
isNot('Just now'),
|
|
|
|
);
|
2022-07-21 15:16:16 +00:00
|
|
|
});
|
|
|
|
test('nmin ago', () {
|
2023-03-06 04:49:10 +00:00
|
|
|
expect(
|
|
|
|
formatMessageTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 20).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 26, 12, 21).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
'1min ago',
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
formatMessageTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 20).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 26, 12, 28).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
'8min ago',
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
formatMessageTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 20).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 26, 12, 35).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
isNot('15min ago'),
|
|
|
|
);
|
2022-07-21 15:16:16 +00:00
|
|
|
});
|
|
|
|
test('hh:mm', () {
|
2023-03-06 04:49:10 +00:00
|
|
|
expect(
|
|
|
|
formatMessageTimestamp(
|
|
|
|
DateTime(2021, 12, 26, 12, 20).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 26, 12, 35).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
'12:20',
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
formatMessageTimestamp(
|
|
|
|
DateTime(2021, 12, 20, 15, 27).millisecondsSinceEpoch,
|
|
|
|
DateTime(2021, 12, 26, 12, 35).millisecondsSinceEpoch,
|
|
|
|
),
|
|
|
|
'15:27',
|
|
|
|
);
|
2022-07-21 15:16:16 +00:00
|
|
|
});
|
2021-12-26 12:41:36 +00:00
|
|
|
});
|
2021-12-26 19:57:22 +00:00
|
|
|
|
2022-07-17 12:55:16 +00:00
|
|
|
group('validateJid', () {
|
2022-07-21 15:16:16 +00:00
|
|
|
test('Valid JIDs', () {
|
2023-03-21 15:32:34 +00:00
|
|
|
expect(
|
|
|
|
validateJid('polynomdivision@someserver.example'),
|
|
|
|
JidFormatError.none,
|
|
|
|
);
|
2022-07-21 15:16:16 +00:00
|
|
|
expect(validateJid('a@b.c'), JidFormatError.none);
|
|
|
|
expect(validateJid('a@192.168.178.1'), JidFormatError.none);
|
|
|
|
expect(validateJid('a@local'), JidFormatError.none);
|
|
|
|
});
|
|
|
|
test('Invalid JIDs', () {
|
|
|
|
expect(validateJid('polynomdivision'), JidFormatError.noSeparator);
|
|
|
|
expect(validateJid('a@'), JidFormatError.noDomain);
|
|
|
|
expect(validateJid(''), JidFormatError.empty);
|
|
|
|
expect(validateJid('a@local@host'), JidFormatError.tooManySeparators);
|
|
|
|
expect(validateJid('@local'), JidFormatError.noLocalpart);
|
|
|
|
});
|
2021-12-26 19:57:22 +00:00
|
|
|
});
|
2022-01-21 08:34:38 +00:00
|
|
|
|
2022-07-21 15:16:16 +00:00
|
|
|
group('filenameWithSuffix', () {
|
|
|
|
test('Test simple filenames', () {
|
|
|
|
expect(filenameWithSuffix('test.jpg', '(1)'), 'test(1).jpg');
|
|
|
|
expect(filenameWithSuffix('test.welt.jpg', '(1)'), 'test.welt(1).jpg');
|
2023-03-21 15:32:34 +00:00
|
|
|
expect(
|
|
|
|
filenameWithSuffix('file-without-extension', '(1)'),
|
|
|
|
'file-without-extension(1)',
|
|
|
|
);
|
2022-07-21 15:16:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Test edge cases', () {
|
|
|
|
expect(filenameWithSuffix('test.png', ''), 'test.png');
|
|
|
|
});
|
2022-02-27 21:12:05 +00:00
|
|
|
});
|
2022-07-31 09:20:12 +00:00
|
|
|
|
|
|
|
test('formatDateBubble', () {
|
|
|
|
expect(
|
|
|
|
formatDateBubble(
|
|
|
|
DateTime(2022, 7, 31, 7, 26),
|
|
|
|
DateTime(2022, 7, 31, 11, 15),
|
|
|
|
),
|
|
|
|
'Today',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
formatDateBubble(
|
|
|
|
DateTime(2022, 7, 30, 22, 39),
|
|
|
|
DateTime(2022, 7, 31, 11, 15),
|
|
|
|
),
|
|
|
|
'Yesterday',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
formatDateBubble(
|
|
|
|
DateTime(2022, 7, 29, 7, 25),
|
|
|
|
DateTime(2022, 7, 31, 11, 15),
|
|
|
|
),
|
2023-02-23 15:59:15 +00:00
|
|
|
'Fri., 29. July',
|
2022-07-31 09:20:12 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
formatDateBubble(
|
|
|
|
DateTime(2019, 7, 29, 7, 25),
|
|
|
|
DateTime(2022, 7, 31, 11, 15),
|
|
|
|
),
|
|
|
|
'29. July 2019',
|
|
|
|
);
|
|
|
|
});
|
2023-02-23 15:59:15 +00:00
|
|
|
|
|
|
|
test('clampedListPrepend', () {
|
|
|
|
expect(
|
|
|
|
clampedListPrepend([1, 2, 3], 4, 4),
|
|
|
|
[4, 1, 2, 3],
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
clampedListPrepend([1, 2, 3, 4], 5, 4),
|
|
|
|
[5, 1, 2, 3],
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
clampedListPrepend([1, 2, 3, 4, 5, 6], 7, 4),
|
|
|
|
[7, 1, 2, 3],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('clampedListPrependAll', () {
|
|
|
|
expect(
|
|
|
|
clampedListPrependAll([1, 2, 3], [4, 5], 5),
|
|
|
|
[4, 5, 1, 2, 3],
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
clampedListPrependAll([1, 2, 3], [4, 5], 4),
|
|
|
|
[4, 5, 1, 2],
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
clampedListPrependAll([1, 2, 3, 4, 5], [6, 7], 4),
|
|
|
|
[6, 7, 1, 2],
|
|
|
|
);
|
|
|
|
});
|
2023-05-09 22:34:07 +00:00
|
|
|
|
|
|
|
group('getPrefixedSubMap', () {
|
|
|
|
test('Unknown prefix', () {
|
|
|
|
final map = {
|
|
|
|
'hello': 1,
|
|
|
|
'world': 2,
|
|
|
|
};
|
|
|
|
final result = getPrefixedSubMap(map, 'data_');
|
|
|
|
expect(result.isEmpty, true);
|
|
|
|
});
|
|
|
|
test('Known prefix', () {
|
|
|
|
final map = {
|
|
|
|
'hello': 1,
|
|
|
|
'world': 2,
|
|
|
|
'data_suletta': 4,
|
|
|
|
'data_miorine': 3,
|
|
|
|
};
|
|
|
|
final result = getPrefixedSubMap(map, 'data_');
|
|
|
|
expect(result.isNotEmpty, true);
|
|
|
|
expect(result.length, 2);
|
|
|
|
expect(result['suletta'], 4);
|
|
|
|
expect(result['miorine'], 3);
|
|
|
|
});
|
|
|
|
});
|
2021-12-24 22:26:45 +00:00
|
|
|
}
|