-
Notifications
You must be signed in to change notification settings - Fork 383
fix(ui): Fix shadowed messages not hidden in the channel list
#2787
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
Open
VelikovPetar
wants to merge
4
commits into
master
Choose a base branch
from
bug/FLU-562_fix_shadowed_messages_appearing_in_channel_list
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+175
−20
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8b29103
fix(ui): Fix `shadowed` messages not hidden in the channel list
VelikovPetar 5a73c59
fix(ui): Fix `shadowed` messages not hidden in the channel list
VelikovPetar 8c8bab0
fix(ui): Remove wrong checks on Message.isShadowed.
VelikovPetar 74f5622
fix(ui): Refactor.
VelikovPetar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
..._chat_flutter/test/src/scroll_view/channel_scroll_view/stream_channel_list_item_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:mocktail/mocktail.dart'; | ||
| import 'package:stream_chat_flutter/stream_chat_flutter.dart'; | ||
|
|
||
| import '../../mocks.dart'; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| void main() { | ||
| const currentUserId = 'me'; | ||
|
|
||
| late MockClient client; | ||
| late MockClientState clientState; | ||
| late MockChannel channel; | ||
| late MockChannelState channelState; | ||
|
|
||
| setUp(() { | ||
| client = MockClient(); | ||
| clientState = MockClientState(); | ||
| channel = MockChannel(); | ||
| channelState = MockChannelState(); | ||
|
|
||
| final currentUser = OwnUser(id: currentUserId, name: 'Me'); | ||
|
|
||
| when(() => client.state).thenReturn(clientState); | ||
| when(() => clientState.currentUser).thenReturn(currentUser); | ||
| when(() => clientState.currentUserStream).thenAnswer((_) => Stream.value(currentUser)); | ||
| when(() => channel.state).thenReturn(channelState); | ||
| when(() => channel.client).thenReturn(client); | ||
| when(() => channelState.draft).thenReturn(null); | ||
| when(() => channelState.channelState).thenReturn(const ChannelState()); | ||
| }); | ||
|
|
||
| Future<void> pumpWithMessages( | ||
| WidgetTester tester, | ||
| List<Message> messages, | ||
| ) async { | ||
| when(() => channelState.messages).thenReturn(messages); | ||
| when(() => channelState.messagesStream).thenAnswer((_) => Stream.value(messages)); | ||
|
|
||
| await tester.pumpWidget( | ||
| MaterialApp( | ||
| home: StreamChat( | ||
| client: client, | ||
| child: Scaffold( | ||
| body: ChannelLastMessageText(channel: channel), | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
| } | ||
|
|
||
| testWidgets('shows the latest message text as preview', (tester) async { | ||
| final message = Message( | ||
| text: 'hello world', | ||
| user: User(id: 'other'), | ||
| createdAt: DateTime(2024, 1, 1), | ||
| ); | ||
|
|
||
| await pumpWithMessages(tester, [message]); | ||
|
|
||
| expect(find.text('hello world'), findsOneWidget); | ||
| }); | ||
|
|
||
| testWidgets('hides shadowed message from another user', (tester) async { | ||
| final visible = Message( | ||
| text: 'visible', | ||
| user: User(id: 'other'), | ||
| createdAt: DateTime(2024, 1, 1), | ||
| ); | ||
| final shadowed = Message( | ||
| text: 'shadowed', | ||
| shadowed: true, | ||
| user: User(id: 'other'), | ||
| createdAt: DateTime(2024, 1, 2), | ||
| ); | ||
|
|
||
| await pumpWithMessages(tester, [visible, shadowed]); | ||
|
|
||
| expect(find.text('visible'), findsOneWidget); | ||
| expect(find.text('shadowed'), findsNothing); | ||
| }); | ||
|
|
||
| testWidgets( | ||
| 'shows current user own shadowed message', | ||
| (tester) async { | ||
| final mine = Message( | ||
| text: 'my shadowed', | ||
| shadowed: true, | ||
| user: User(id: currentUserId), | ||
| createdAt: DateTime(2024, 1, 1), | ||
| ); | ||
|
|
||
| await pumpWithMessages(tester, [mine]); | ||
|
|
||
| expect(find.text('my shadowed'), findsOneWidget); | ||
| }, | ||
| ); | ||
|
|
||
| testWidgets('hides error and ephemeral messages', (tester) async { | ||
| final visible = Message( | ||
| text: 'visible', | ||
| user: User(id: 'other'), | ||
| createdAt: DateTime(2024, 1, 1), | ||
| ); | ||
| final errored = Message( | ||
| text: 'errored', | ||
| type: MessageType.error, | ||
| user: User(id: 'other'), | ||
| createdAt: DateTime(2024, 1, 2), | ||
| ); | ||
| final ephemeral = Message( | ||
| text: 'ephemeral', | ||
| type: MessageType.ephemeral, | ||
| user: User(id: 'other'), | ||
| createdAt: DateTime(2024, 1, 3), | ||
| ); | ||
|
|
||
| await pumpWithMessages(tester, [visible, errored, ephemeral]); | ||
|
|
||
| expect(find.text('visible'), findsOneWidget); | ||
| expect(find.text('errored'), findsNothing); | ||
| expect(find.text('ephemeral'), findsNothing); | ||
| }); | ||
|
|
||
| testWidgets( | ||
| 'custom lastMessagePredicate fully replaces the default', | ||
| (tester) async { | ||
| final shadowedByOther = Message( | ||
| text: 'shadowed by other', | ||
| shadowed: true, | ||
| user: User(id: 'other'), | ||
| createdAt: DateTime(2024, 1, 1), | ||
| ); | ||
|
|
||
| when(() => channelState.messages).thenReturn([shadowedByOther]); | ||
| when(() => channelState.messagesStream).thenAnswer((_) => Stream.value([shadowedByOther])); | ||
|
|
||
| await tester.pumpWidget( | ||
| MaterialApp( | ||
| home: StreamChat( | ||
| client: client, | ||
| child: Scaffold( | ||
| body: ChannelLastMessageText( | ||
| channel: channel, | ||
| lastMessagePredicate: (_) => true, | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(find.text('shadowed by other'), findsOneWidget); | ||
| }, | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a bit confusing, I think it's already clearer with a typedef. Something like this: