test fixes

This commit is contained in:
Deven Joshi
2022-01-14 16:36:30 +05:30
parent f2ab29d8c6
commit 6729ef1deb
5 changed files with 136 additions and 92 deletions
@@ -46,6 +46,7 @@ extension IterableX<T> on Iterable<T> {
/// Useful extension for [PlatformFile]
extension PlatformFileX on PlatformFile {
/// Converts the [PlatformFile] into [AttachmentFile]
//ignore: avoid_redundant_argument_values
AttachmentFile get toAttachmentFile => AttachmentFile(
path: kIsWeb ? null : path,
name: name,
@@ -28,7 +28,7 @@ class MessageActionsModal extends StatefulWidget {
this.showReplyMessage = true,
this.showResendMessage = true,
this.showThreadReplyMessage,
this.showFlagButton = true,
this.showFlagButton,
this.showPinButton,
this.editMessageInputBuilder,
this.reverse = false,
@@ -73,13 +73,13 @@ class MessageActionsModal extends StatefulWidget {
final bool showResendMessage;
/// Flag for showing reply action
final bool showReplyMessage;
final bool? showReplyMessage;
/// Flag for showing thread reply action
final bool? showThreadReplyMessage;
/// Flag for showing flag action
final bool showFlagButton;
final bool? showFlagButton;
/// Flag for showing pin action
final bool? showPinButton;
@@ -191,14 +191,15 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (_userPermissions
if (widget.showReplyMessage ??
(_userPermissions
.contains(PermissionType.quoteMessage) &&
widget.showReplyMessage &&
widget.message.status == MessageSendingStatus.sent)
widget.message.status ==
MessageSendingStatus.sent))
_buildReplyButton(context),
if ((widget.showThreadReplyMessage ??
if (widget.showThreadReplyMessage ??
_userPermissions
.contains(PermissionType.sendReply)) &&
.contains(PermissionType.sendReply) &&
(widget.message.status ==
MessageSendingStatus.sent) &&
widget.message.parentId == null)
@@ -209,16 +210,16 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
_isMyMessage && hasEditPermission)
_buildEditMessage(context),
if (widget.showCopyMessage) _buildCopyButton(context),
if (_userPermissions
.contains(PermissionType.flagMessage) &&
widget.showFlagButton)
if (widget.showFlagButton ??
_userPermissions
.contains(PermissionType.flagMessage))
_buildFlagButton(context),
if (widget.showPinButton ??
_userPermissions
.contains(PermissionType.pinMessage))
_buildPinButton(context),
if (widget.showDeleteMessage ??
_isMyMessage && hasDeletePermission)
(_isMyMessage && hasDeletePermission))
_buildDeleteButton(context),
...widget.customActions
.map((action) => _buildCustomAction(
@@ -686,8 +687,8 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
void didChangeDependencies() {
final newStreamChannel = StreamChannel.of(context);
_userPermissions = newStreamChannel.channel.ownCapabilities;
_isMyMessage = widget.message.user!.id ==
newStreamChannel.channel.client.state.currentUser!.id;
_isMyMessage =
widget.message.user?.id == StreamChat.of(context).currentUser?.id;
super.didChangeDependencies();
}
}
@@ -19,6 +19,7 @@ void main() {
(WidgetTester tester) async {
final client = MockClient();
final clientState = MockClientState();
final channel = MockChannel();
when(() => client.state).thenReturn(clientState);
when(() => clientState.currentUser).thenReturn(OwnUser(id: 'user-id'));
@@ -32,6 +33,8 @@ void main() {
streamChatThemeData: streamTheme,
client: client,
child: SizedBox(
child: StreamChannel(
channel: channel,
child: MessageActionsModal(
message: Message(
text: 'test',
@@ -45,6 +48,10 @@ void main() {
key: Key('MessageWidget'),
),
messageTheme: streamTheme.ownMessageTheme,
showThreadReplyMessage: true,
showEditMessage: true,
showDeleteMessage: true,
),
),
),
),
@@ -66,6 +73,7 @@ void main() {
(WidgetTester tester) async {
final client = MockClient();
final clientState = MockClientState();
final channel = MockChannel();
when(() => client.state).thenReturn(clientState);
when(() => clientState.currentUser).thenReturn(OwnUser(id: 'user-id'));
@@ -79,6 +87,8 @@ void main() {
streamChatThemeData: streamTheme,
client: client,
child: SizedBox(
child: StreamChannel(
channel: channel,
child: MessageActionsModal(
showCopyMessage: false,
showReplyMessage: false,
@@ -98,6 +108,7 @@ void main() {
),
),
),
),
);
await tester.pumpAndSettle();
@@ -115,6 +126,7 @@ void main() {
(WidgetTester tester) async {
final client = MockClient();
final clientState = MockClientState();
final channel = MockChannel();
when(() => client.state).thenReturn(clientState);
when(() => clientState.currentUser).thenReturn(OwnUser(id: 'user-id'));
@@ -130,6 +142,8 @@ void main() {
streamChatThemeData: streamTheme,
client: client,
child: SizedBox(
child: StreamChannel(
channel: channel,
child: MessageActionsModal(
messageWidget: const Text('test'),
message: Message(
@@ -152,6 +166,7 @@ void main() {
),
),
),
),
);
await tester.pumpAndSettle();
@@ -170,6 +185,7 @@ void main() {
(WidgetTester tester) async {
final client = MockClient();
final clientState = MockClientState();
final channel = MockChannel();
when(() => client.state).thenReturn(clientState);
when(() => clientState.currentUser).thenReturn(OwnUser(id: 'user-id'));
@@ -186,6 +202,8 @@ void main() {
streamChatThemeData: streamTheme,
client: client,
child: SizedBox(
child: StreamChannel(
channel: channel,
child: MessageActionsModal(
messageWidget: const Text('test'),
onReplyTap: (m) {
@@ -203,6 +221,7 @@ void main() {
),
),
),
),
);
await tester.pumpAndSettle();
@@ -217,6 +236,7 @@ void main() {
(WidgetTester tester) async {
final client = MockClient();
final clientState = MockClientState();
final channel = MockChannel();
when(() => client.state).thenReturn(clientState);
when(() => clientState.currentUser).thenReturn(OwnUser(id: 'user-id'));
@@ -233,6 +253,8 @@ void main() {
streamChatThemeData: streamTheme,
client: client,
child: SizedBox(
child: StreamChannel(
channel: channel,
child: MessageActionsModal(
messageWidget: const Text('test'),
onThreadReplyTap: (m) {
@@ -246,6 +268,8 @@ void main() {
status: MessageSendingStatus.sent,
),
messageTheme: streamTheme.ownMessageTheme,
showThreadReplyMessage: true,
),
),
),
),
@@ -295,6 +319,7 @@ void main() {
),
),
messageTheme: streamTheme.ownMessageTheme,
showEditMessage: true,
),
),
),
@@ -345,6 +370,7 @@ void main() {
),
),
messageTheme: streamTheme.ownMessageTheme,
showEditMessage: true,
),
),
),
@@ -545,6 +571,7 @@ void main() {
),
),
messageTheme: streamTheme.ownMessageTheme,
showFlagButton: true,
),
),
),
@@ -601,6 +628,7 @@ void main() {
),
),
messageTheme: streamTheme.ownMessageTheme,
showFlagButton: true,
),
),
),
@@ -657,6 +685,7 @@ void main() {
),
),
messageTheme: streamTheme.ownMessageTheme,
showFlagButton: true,
),
),
),
@@ -711,6 +740,7 @@ void main() {
),
),
messageTheme: streamTheme.ownMessageTheme,
showDeleteMessage: true,
),
),
),
@@ -767,6 +797,7 @@ void main() {
),
),
messageTheme: streamTheme.ownMessageTheme,
showDeleteMessage: true,
),
),
),
@@ -13,6 +13,7 @@ void main() {
(WidgetTester tester) async {
final client = MockClient();
final clientState = MockClientState();
final channel = MockChannel();
final themeData = ThemeData();
when(() => client.state).thenReturn(clientState);
@@ -33,6 +34,8 @@ void main() {
home: StreamChat(
client: client,
streamChatThemeData: streamTheme,
child: StreamChannel(
channel: channel,
child: MessageReactionsModal(
messageWidget: const Text(
'test',
@@ -43,6 +46,7 @@ void main() {
),
),
),
),
);
await tester.pump(const Duration(milliseconds: 1000));
@@ -58,6 +62,7 @@ void main() {
(WidgetTester tester) async {
final client = MockClient();
final clientState = MockClientState();
final channel = MockChannel();
final themeData = ThemeData();
when(() => client.state).thenReturn(clientState);
@@ -89,6 +94,8 @@ void main() {
home: StreamChat(
client: client,
streamChatThemeData: streamTheme,
child: StreamChannel(
channel: channel,
child: MessageReactionsModal(
messageWidget: const Text(
'test',
@@ -102,6 +109,7 @@ void main() {
),
),
),
),
);
await tester.pump(const Duration(milliseconds: 1000));
@@ -21,6 +21,9 @@ class MockChannel extends Mock implements Channel {
Future<void> keyStroke([String? parentId]) async {
return;
}
@override
List<String> get ownCapabilities => ['send-message'];
}
class MockChannelState extends Mock implements ChannelClientState {