Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): be lenient when calling nullable onThreadTap method #1854

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading