diff --git a/lib/presentation/mixins/message_avatar_mixin.dart b/lib/presentation/mixins/message_avatar_mixin.dart index 16513aef7f..f02b794fa4 100644 --- a/lib/presentation/mixins/message_avatar_mixin.dart +++ b/lib/presentation/mixins/message_avatar_mixin.dart @@ -13,7 +13,7 @@ mixin MessageAvatarMixin { bool ownMessage, BuildContext context, ) { - return sameSender && (!ownMessage || !responsive.isMobile(context)); + return sameSender && !(ownMessage && responsive.isMobile(context)); } Widget placeHolderWidget( diff --git a/pubspec.lock b/pubspec.lock index 4ef7431479..024bec8b88 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1779,7 +1779,7 @@ packages: description: path: "." ref: master - resolved-ref: "730692596f54708fab806f54912e3cbecb027825" + resolved-ref: f5e0f2d0f9450dda58c72233f72fb48cf7d2769b url: "git@github.com:linagora/linagora-design-flutter.git" source: git version: "0.0.1" @@ -1876,8 +1876,8 @@ packages: dependency: "direct main" description: path: "." - ref: "twake-supported-0.22.6" - resolved-ref: "04ec6f3b9ece8e64e031cbe5c6e8164dc2ec7f2d" + ref: change_operator_in_User + resolved-ref: "01c955b0fc494030cd7fee1ff0b2c2e687b90f7f" url: "git@github.com:linagora/matrix-dart-sdk.git" source: git version: "0.22.6" @@ -3007,10 +3007,10 @@ packages: dependency: "direct main" description: name: url_launcher - sha256: "6ce1e04375be4eed30548f10a315826fd933c1e493206eab82eed01f438c8d2e" + sha256: "9d06212b1362abc2f0f0d78e6f09f726608c74e3b9462e8368bb03314aa8d603" url: "https://pub.dev" source: hosted - version: "6.2.6" + version: "6.3.1" url_launcher_android: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 58185bb536..ee0a6518d6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: matrix: git: url: git@github.com:linagora/matrix-dart-sdk.git - ref: twake-supported-0.22.6 + ref: change_operator_in_User receive_sharing_intent: git: diff --git a/test/mixin/message_avatar_mixin_test.dart b/test/mixin/message_avatar_mixin_test.dart index 5bd7f49a9d..7e52e6f310 100644 --- a/test/mixin/message_avatar_mixin_test.dart +++ b/test/mixin/message_avatar_mixin_test.dart @@ -35,7 +35,7 @@ Future main() async { mockMessageAvatarUtils = MockMessageAvatarUtils(); }); - group('[MessageAvatarUtils] TEST\n', () { + group('Tests for when the avatar next to a message should be displayed ', () { setUp(() { room = MockRoom(); user = MockUser(); @@ -57,6 +57,8 @@ Future main() async { required bool selectMode, required bool sameSender, required bool ownMessage, + required Size screenSize, + required bool isDirectChat, }) async { when(room.requestUser(event.senderId, ignoreErrors: true)) .thenAnswer((_) async => user); @@ -64,6 +66,7 @@ Future main() async { .thenReturn(user); when(user.avatarUrl).thenReturn(Uri.tryParse("fakeImage")); when(user.calcDisplayname()).thenReturn('Test'); + when(event.room.isDirectChat).thenReturn(isDirectChat); Widget? widget; await tester.pumpWidget( ThemeBuilder( @@ -83,8 +86,8 @@ Future main() async { primaryColor, ), builder: (context, child) => MediaQuery( - data: const MediaQueryData( - size: Size(1920, 1080), + data: MediaQueryData( + size: screenSize, ), child: child!, ), @@ -108,53 +111,188 @@ Future main() async { ); await tester.pumpAndSettle(); - - if (selectMode || ownMessage) { - expect(find.byType(SizedBox), findsOneWidget); - } else { - expect(widget, isNotNull); - verify(room.requestUser(event.senderId, ignoreErrors: true)).called(1); - expect(find.byType(Avatar), findsOneWidget); - } } - testWidgets( - 'GIVEN selectMode is true THEN display SizedBox', - (WidgetTester tester) async { - await runTest( - tester, - event: event, - selectMode: true, - sameSender: true, - ownMessage: false, - ); - }, - ); - - testWidgets( - 'GIVEN ownMessage is true THEN display SizedBox', - (WidgetTester tester) async { - await runTest( - tester, - event: event, - selectMode: false, - sameSender: false, - ownMessage: true, - ); - }, - ); - - testWidgets( - 'GIVEN not ownMessage AND not selectMode THEN display Avatar', - (WidgetTester tester) async { - await runTest( - tester, - event: event, - selectMode: false, - sameSender: true, - ownMessage: false, - ); - }, - ); + group('Web-sized screens', () { + const webSize = Size(1200, 800); + + testWidgets( + 'Should display Avatar when Own message in group chat', + (WidgetTester tester) async { + await runTest( + tester, + event: event, + selectMode: false, + sameSender: true, + ownMessage: true, + screenSize: webSize, + isDirectChat: false, + ); + verify(room.requestUser(event.senderId, ignoreErrors: true)) + .called(1); + expect(find.byType(Avatar), findsOneWidget); + }, + ); + + testWidgets( + 'Should display Avatar when Own message in direct chat', + (WidgetTester tester) async { + await runTest( + tester, + event: event, + selectMode: false, + sameSender: true, + ownMessage: true, + screenSize: webSize, + isDirectChat: true, + ); + verify(room.requestUser(event.senderId, ignoreErrors: true)) + .called(1); + expect(find.byType(Avatar), findsOneWidget); + }, + ); + + testWidgets( + 'Should return Avatar when Not my message in direct chat', + (WidgetTester tester) async { + await runTest( + tester, + event: event, + selectMode: false, + sameSender: true, + ownMessage: false, + screenSize: webSize, + isDirectChat: true, + ); + verify(room.requestUser(event.senderId, ignoreErrors: true)) + .called(1); + expect(find.byType(Avatar), findsOneWidget); + }, + ); + + testWidgets( + 'Should return Avatar when not my message in group chat', + (WidgetTester tester) async { + await runTest( + tester, + event: event, + selectMode: false, + sameSender: true, + ownMessage: false, + screenSize: webSize, + isDirectChat: false, + ); + verify(room.requestUser(event.senderId, ignoreErrors: true)) + .called(1); + expect(find.byType(Avatar), findsOneWidget); + }, + ); + + testWidgets( + 'Should return SizedBox when Select mode is active', + (WidgetTester tester) async { + await runTest( + tester, + event: event, + selectMode: true, + sameSender: true, + ownMessage: false, + screenSize: webSize, + isDirectChat: true, + ); + verifyNever(room.requestUser(event.senderId, ignoreErrors: true)); + expect(find.byType(SizedBox), findsOneWidget); + }, + ); + }); + group('Mobile-sized screens', () { + const mobileSize = Size(400, 800); + + testWidgets( + 'Should return SizedBox when Own message in group chat', + (WidgetTester tester) async { + await runTest( + tester, + event: event, + selectMode: false, + sameSender: true, + ownMessage: true, + isDirectChat: false, + screenSize: mobileSize, + ); + verifyNever(room.requestUser(event.senderId, ignoreErrors: true)); + expect(find.byType(SizedBox), findsOneWidget); + }, + ); + + testWidgets( + 'Should return SizedBox when Own message in direct chat', + (WidgetTester tester) async { + await runTest( + tester, + event: event, + selectMode: false, + sameSender: true, + ownMessage: true, + screenSize: mobileSize, + isDirectChat: true, + ); + verifyNever(room.requestUser(event.senderId, ignoreErrors: true)); + expect(find.byType(SizedBox), findsOneWidget); + }, + ); + + testWidgets( + 'Should return SizedBox when Not my message in direct chat', + (WidgetTester tester) async { + await runTest( + tester, + event: event, + selectMode: false, + sameSender: true, + ownMessage: false, + screenSize: mobileSize, + isDirectChat: true, + ); + verifyNever(room.requestUser(event.senderId, ignoreErrors: true)); + expect(find.byType(SizedBox), findsOneWidget); + }, + ); + + testWidgets( + 'Should return Avatar when Not my message in group chat', + (WidgetTester tester) async { + await runTest( + tester, + event: event, + selectMode: false, + sameSender: true, + ownMessage: false, + screenSize: mobileSize, + isDirectChat: false, + ); + verify(room.requestUser(event.senderId, ignoreErrors: true)) + .called(1); + expect(find.byType(Avatar), findsOneWidget); + }, + ); + + testWidgets( + 'Should return SizedBox when Select mode is active', + (WidgetTester tester) async { + await runTest( + tester, + event: event, + selectMode: true, + sameSender: true, + ownMessage: false, + screenSize: mobileSize, + isDirectChat: true, + ); + verifyNever(room.requestUser(event.senderId, ignoreErrors: true)); + expect(find.byType(SizedBox), findsOneWidget); + }, + ); + }); }); }