add initialized channel tests
Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:dio/dio.dart' show MultipartFile;
|
||||
import 'package:stream_chat/src/core/models/event.dart';
|
||||
import 'package:stream_chat/src/core/models/message.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
Matcher isSameMultipartFileAs(MultipartFile targetFile) =>
|
||||
@@ -17,3 +20,72 @@ class _IsSameMultipartFileAs extends Matcher {
|
||||
bool matches(covariant MultipartFile file, Map matchState) =>
|
||||
file.length == targetFile.length;
|
||||
}
|
||||
|
||||
Matcher isSameEventAs(Event targetEvent) =>
|
||||
_IsSameEventAs(targetEvent: targetEvent);
|
||||
|
||||
class _IsSameEventAs extends Matcher {
|
||||
const _IsSameEventAs({required this.targetEvent});
|
||||
|
||||
final Event targetEvent;
|
||||
|
||||
@override
|
||||
Description describe(Description description) =>
|
||||
description.add('is same event as $targetEvent');
|
||||
|
||||
@override
|
||||
bool matches(covariant Event event, Map matchState) =>
|
||||
event.type == targetEvent.type;
|
||||
}
|
||||
|
||||
Matcher isSameMessageAs(
|
||||
Message targetMessage, {
|
||||
bool matchReactions = false,
|
||||
bool matchSendingStatus = false,
|
||||
}) =>
|
||||
_IsSameMessageAs(
|
||||
targetMessage: targetMessage,
|
||||
matchReactions: matchReactions,
|
||||
matchSendingStatus: matchSendingStatus,
|
||||
);
|
||||
|
||||
class _IsSameMessageAs extends Matcher {
|
||||
const _IsSameMessageAs({
|
||||
required this.targetMessage,
|
||||
this.matchReactions = false,
|
||||
this.matchSendingStatus = false,
|
||||
});
|
||||
|
||||
final Message targetMessage;
|
||||
final bool matchReactions;
|
||||
final bool matchSendingStatus;
|
||||
|
||||
@override
|
||||
Description describe(Description description) =>
|
||||
description.add('is same message as $targetMessage');
|
||||
|
||||
@override
|
||||
bool matches(covariant Message message, Map matchState) {
|
||||
var matches = message.id == targetMessage.id;
|
||||
if (matchSendingStatus) {
|
||||
matches &= message.status == targetMessage.status;
|
||||
}
|
||||
if (matchReactions) {
|
||||
matches &= const ListEquality().equals(
|
||||
message.ownReactions
|
||||
?.map((it) => '${it.type}-${it.messageId}')
|
||||
.toList(),
|
||||
targetMessage.ownReactions
|
||||
?.map((it) => '${it.type}-${it.messageId}')
|
||||
.toList());
|
||||
matches &= const ListEquality().equals(
|
||||
message.latestReactions
|
||||
?.map((it) => '${it.type}-${it.messageId}')
|
||||
.toList(),
|
||||
targetMessage.latestReactions
|
||||
?.map((it) => '${it.type}-${it.messageId}')
|
||||
.toList());
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user