add extension_test.dart, serializer_test.dart and utils_test.dart
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import 'package:test/test.dart';
|
||||
import 'package:stream_chat/src/core/util/extension.dart';
|
||||
|
||||
void main() {
|
||||
test('`.withNullifyer` converts the type into non-nullable', () {
|
||||
final items = ['A', 'B', null, 'D'];
|
||||
expect(items, isA<Iterable<String?>>());
|
||||
expect(items.length, 4);
|
||||
|
||||
final nullifiedItems = items.withNullifyer;
|
||||
expect(nullifiedItems, isA<Iterable<String>>());
|
||||
expect(nullifiedItems.length, 3);
|
||||
});
|
||||
|
||||
test('`.nullProtected should remove all the null keys, value`', () {
|
||||
final map = {'name': 'sahil', 'age': null, null: 'India'};
|
||||
expect(map, isA<Map<String?, String?>>());
|
||||
expect(map.length, 3);
|
||||
|
||||
final nullProtectedMap = map.nullProtected;
|
||||
expect(nullProtectedMap, isA<Map<String, String>>());
|
||||
expect(nullProtectedMap.length, 1);
|
||||
});
|
||||
|
||||
group('mimeType', () {
|
||||
test('should return null if `String` is not a filename', () {
|
||||
const fileName = 'not-a-file-name';
|
||||
final mimeType = fileName.mimeType;
|
||||
expect(mimeType, isNull);
|
||||
});
|
||||
|
||||
test('should return mimeType if string is a filename', () {
|
||||
const fileName = 'dummyFileName.jpeg';
|
||||
final mimeType = fileName.mimeType;
|
||||
expect(mimeType, isNotNull);
|
||||
expect(mimeType!.type, 'image');
|
||||
expect(mimeType.subtype, 'jpeg');
|
||||
});
|
||||
|
||||
test('should return `image/heic` if ends with `heic`', () {
|
||||
const fileName = 'dummyFileName.heic';
|
||||
final mimeType = fileName.mimeType;
|
||||
expect(mimeType, isNotNull);
|
||||
expect(mimeType!.type, 'image');
|
||||
expect(mimeType.subtype, 'heic');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import 'package:stream_chat/src/core/util/serializer.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('Serializer', () {
|
||||
test('moveKeysToMapInPlace', () {
|
||||
final serializer = Serializer.moveToExtraDataFromRoot(
|
||||
{
|
||||
'test': 'test',
|
||||
'name': 'Sahil',
|
||||
'age': 22,
|
||||
'country': 'India',
|
||||
},
|
||||
['test'],
|
||||
);
|
||||
expect(serializer, {
|
||||
'test': 'test',
|
||||
'extra_data': {
|
||||
'name': 'Sahil',
|
||||
'age': 22,
|
||||
'country': 'India',
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('moveKeysToMapInPlace', () {
|
||||
final serializer = Serializer.moveFromExtraDataToRoot({
|
||||
'test': 'test',
|
||||
'extra_data': {
|
||||
'name': 'Sahil',
|
||||
'age': 22,
|
||||
'country': 'India',
|
||||
}
|
||||
});
|
||||
expect(serializer, {
|
||||
'test': 'test',
|
||||
'name': 'Sahil',
|
||||
'age': 22,
|
||||
'country': 'India',
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:stream_chat/src/core/util/utils.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('should generate a `randomId` of length 33', () {
|
||||
final id = randomId(size: 33);
|
||||
expect(id.length, 33);
|
||||
});
|
||||
|
||||
test('should `generateHash` for the passed objects', () {
|
||||
final objects = ['Sahil', 23, 'Flutter Engineer', 'India'];
|
||||
final hash = generateHash(objects);
|
||||
expect(hash, 'WyJTYWhpbCIsMjMsIkZsdXR0ZXIgRW5naW5lZXIiLCJJbmRpYSJd');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user