Skip to content

Commit

Permalink
fix(ui): be lenient when calling nullable onThreadTap method (#1854)
Browse files Browse the repository at this point in the history
  • Loading branch information
esarbanis authored Feb 21, 2024
1 parent 35d338e commit 7073571
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/stream_chat_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

🐞 Fixed
- Removed double focus on `StreamMessageInput` when `focusNode` is provided for web and desktop.
- Optionally call `onThreadTap` in `BottomRow` to avoid `Null check operator used on a null value`


## 7.0.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class BottomRow extends StatelessWidget {
final channel = StreamChannel.of(context);
message = await channel.getMessage(message.parentId!);
}
return onThreadTap!(message);
return onThreadTap?.call(message);
} catch (e, stk) {
debugPrint('Error while fetching message: $e, $stk');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:stream_chat_flutter/src/message_widget/bottom_row.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';

import '../mocks.dart';

void main() {
late Channel channel;
late ChannelClientState channelClientState;

setUp(() {
channel = MockChannel();
when(() => channel.on(any(), any(), any(), any()))
.thenAnswer((_) => const Stream.empty());
channelClientState = MockChannelState();
when(() => channel.state).thenReturn(channelClientState);
when(() => channelClientState.messages).thenReturn([
Message(
id: 'parentId',
)
]);
});

setUpAll(() {
registerFallbackValue(Message());
});

testWidgets('BottomRow', (tester) async {
final theme = StreamChatThemeData.light();
final onThreadTap = MockVoidSingleParamCallback<Message>();

await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: StreamChannel(
channel: channel,
child: BottomRow(
message: Message(
parentId: 'parentId',
),
isDeleted: false,
showThreadReplyIndicator: false,
showUsername: false,
showInChannel: true,
showTimeStamp: false,
reverse: false,
showSendingIndicator: false,
hasUrlAttachments: false,
isGiphy: false,
isOnlyEmoji: false,
messageTheme: theme.otherMessageTheme,
streamChatTheme: theme,
hasNonUrlAttachments: false,
streamChat: StreamChatState(),
onThreadTap: onThreadTap,
),
),
),
),
),
);

await tester.tap(find.byType(GestureDetector));
await tester.pumpAndSettle();

verify(() => onThreadTap.call(any()));
});
}
4 changes: 4 additions & 0 deletions packages/stream_chat_flutter/test/src/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class MockVoidCallback extends Mock {
void call();
}

class MockVoidSingleParamCallback<T> extends Mock {
void call(T param);
}

class MockAttachmentHandler extends Mock implements StreamAttachmentHandler {}

class MockMember extends Mock implements Member {}
Expand Down

0 comments on commit 7073571

Please sign in to comment.