Skip to content

Commit

Permalink
TW-1849: Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Nov 18, 2024
1 parent 8b1cf6a commit 64edf3c
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/presentation/mixins/chat_list_item_mixin.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
95 changes: 95 additions & 0 deletions test/mixin/chat/chat_list_item_mixin_test.dart
Original file line number Diff line number Diff line change
@@ -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<BuildContext>(),
MockSpec<Room>(),
])
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]);
});
});
}

0 comments on commit 64edf3c

Please sign in to comment.