diff --git a/lib/presentation/mixins/chat_list_item_mixin.dart b/lib/presentation/mixins/chat_list_item_mixin.dart index 9360dfe67d..177d03032b 100644 --- a/lib/presentation/mixins/chat_list_item_mixin.dart +++ b/lib/presentation/mixins/chat_list_item_mixin.dart @@ -1,4 +1,3 @@ -import 'package:fluffychat/domain/model/room/room_extension.dart'; import 'package:fluffychat/pages/chat/events/images_builder/image_placeholder.dart'; import 'package:fluffychat/presentation/decorators/chat_list/subtitle_image_preview_style.dart'; import 'package:fluffychat/presentation/decorators/chat_list/subtitle_text_style_decorator/subtitle_text_style_view.dart'; @@ -214,7 +213,8 @@ mixin ChatListItemMixin { required BuildContext context, required Room room, }) { - if (room.notificationCount > 0 && room.isMuted) { + if (room.notificationCount > 0 && + room.pushRuleState != PushRuleState.notify) { return LinagoraRefColors.material().tertiary[30]; } if (room.notificationCount > 0) { diff --git a/test/mixin/chat/chat_list_item_mixin_test.dart b/test/mixin/chat/chat_list_item_mixin_test.dart new file mode 100644 index 0000000000..fd70d83ff6 --- /dev/null +++ b/test/mixin/chat/chat_list_item_mixin_test.dart @@ -0,0 +1,95 @@ +import 'package:fluffychat/presentation/mixins/chat_list_item_mixin.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:linagora_design_flutter/linagora_design_flutter.dart'; +import 'package:matrix/matrix.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; + +import 'chat_list_item_mixin_test.mocks.dart'; + +class ChatListItemMixinTest with ChatListItemMixin {} + +@GenerateNiceMocks([ + MockSpec(), + MockSpec(), +]) +void main() { + group('notificationColor Test', () { + late Room room; + late BuildContext context; + late ChatListItemMixinTest chatListItemMixinTest; + + setUp(() { + room = MockRoom(); + context = MockBuildContext(); + chatListItemMixinTest = ChatListItemMixinTest(); + }); + + testWidgets( + 'WHEN notification count is zero\n' + 'AND room is unmuted\n' + 'THEN color should have transparent\n', ( + WidgetTester tester, + ) async { + when(room.notificationCount).thenReturn(0); + when(room.pushRuleState).thenReturn(PushRuleState.notify); + + final color = chatListItemMixinTest.notificationColor( + context: context, + room: room, + ); + + expect(color, Colors.transparent); + }); + + testWidgets( + 'WHEN group is invite\n' + 'THEN color should have color primary\n', ( + WidgetTester tester, + ) async { + when(room.membership).thenReturn(Membership.invite); + + final color = chatListItemMixinTest.notificationColor( + context: context, + room: room, + ); + + expect(color, Theme.of(context).colorScheme.primary); + }); + + testWidgets( + 'WHEN notification count is greater than zero\n' + 'AND room is unmuted\n' + 'THEN color should be primary\n', ( + WidgetTester tester, + ) async { + when(room.notificationCount).thenReturn(5); + when(room.pushRuleState).thenReturn(PushRuleState.notify); + + final color = chatListItemMixinTest.notificationColor( + context: context, + room: room, + ); + + expect(color, Theme.of(context).colorScheme.primary); + }); + + testWidgets( + 'WHEN notification count is greater than zero\n' + 'AND room is muted\n' + 'THEN color should be tertiary[30]\n', ( + WidgetTester tester, + ) async { + when(room.notificationCount).thenReturn(5); + when(room.pushRuleState).thenReturn(PushRuleState.dontNotify); + + final color = chatListItemMixinTest.notificationColor( + context: context, + room: room, + ); + + expect(color, LinagoraRefColors.material().tertiary[30]); + }); + }); +}