Skip to content

Commit

Permalink
fixup! fixup! fixup! WIP-Adding unit test for message class
Browse files Browse the repository at this point in the history
  • Loading branch information
KhaledNjim committed Dec 15, 2024
1 parent 77e2938 commit 160b24a
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 56 deletions.
2 changes: 1 addition & 1 deletion lib/presentation/mixins/message_avatar_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mixin MessageAvatarMixin {
bool ownMessage,
BuildContext context,
) {
return sameSender && (!ownMessage || !responsive.isMobile(context));
return sameSender && !(ownMessage && responsive.isMobile(context));
}

Widget placeHolderWidget(
Expand Down
10 changes: 5 additions & 5 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ packages:
description:
path: "."
ref: master
resolved-ref: "730692596f54708fab806f54912e3cbecb027825"
resolved-ref: f5e0f2d0f9450dda58c72233f72fb48cf7d2769b
url: "[email protected]:linagora/linagora-design-flutter.git"
source: git
version: "0.0.1"
Expand Down Expand Up @@ -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: "[email protected]:linagora/matrix-dart-sdk.git"
source: git
version: "0.22.6"
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
matrix:
git:
url: [email protected]:linagora/matrix-dart-sdk.git
ref: twake-supported-0.22.6
ref: change_operator_in_User

receive_sharing_intent:
git:
Expand Down
236 changes: 187 additions & 49 deletions test/mixin/message_avatar_mixin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Future<void> 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();
Expand All @@ -57,13 +57,16 @@ Future<void> 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);
when(room.unsafeGetUserFromMemoryOrFallback(event.senderId))
.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(
Expand All @@ -83,8 +86,8 @@ Future<void> main() async {
primaryColor,
),
builder: (context, child) => MediaQuery(
data: const MediaQueryData(
size: Size(1920, 1080),
data: MediaQueryData(
size: screenSize,
),
child: child!,
),
Expand All @@ -108,53 +111,188 @@ Future<void> 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);
},
);
});
});
}

0 comments on commit 160b24a

Please sign in to comment.