diff --git a/lib/pages/new_private_chat/widget/contact_status_widget.dart b/lib/pages/new_private_chat/widget/contact_status_widget.dart index e2acf0cfa4..8b959143c1 100644 --- a/lib/pages/new_private_chat/widget/contact_status_widget.dart +++ b/lib/pages/new_private_chat/widget/contact_status_widget.dart @@ -13,36 +13,30 @@ class ContactStatusWidget extends StatelessWidget { required this.status, }); - final Color? activeColor = LinagoraRefColors.material().secondary[40]; final Color? inactiveColor = LinagoraRefColors.material().neutral[60]; @override Widget build(BuildContext context) { - return Padding( - padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - SvgPicture.asset( - ImagePaths.icStatus, - // ignore: deprecated_member_use - color: status == ContactStatus.active ? activeColor : inactiveColor, - ), - status == ContactStatus.active - ? Text( - " ${L10n.of(context)!.online}", - style: Theme.of(context).textTheme.bodySmall?.copyWith( - color: activeColor, - ), - ) - : Text( + return status == ContactStatus.inactive + ? Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SvgPicture.asset( + ImagePaths.icStatus, + colorFilter: + ColorFilter.mode(inactiveColor!, BlendMode.srcIn), + ), + Text( " ${L10n.of(context)!.inactive}", style: Theme.of(context).textTheme.bodySmall?.copyWith( color: inactiveColor, ), ), - ], - ), - ); + ], + ), + ) + : const SizedBox.shrink(); } } diff --git a/lib/pages/new_private_chat/widget/expansion_contact_list_tile.dart b/lib/pages/new_private_chat/widget/expansion_contact_list_tile.dart index 54efe2d7d0..e855238afb 100644 --- a/lib/pages/new_private_chat/widget/expansion_contact_list_tile.dart +++ b/lib/pages/new_private_chat/widget/expansion_contact_list_tile.dart @@ -85,7 +85,8 @@ class ExpansionContactListTile extends StatelessWidget { ), ], const SizedBox(width: 8.0), - if (contact.status != null) + if (contact.status != null && + contact.status == ContactStatus.inactive) ContactStatusWidget( status: contact.status!, ), diff --git a/test/pages/new_private_chat/widget/contact_status_widget_test.dart b/test/pages/new_private_chat/widget/contact_status_widget_test.dart new file mode 100644 index 0000000000..f7ea163077 --- /dev/null +++ b/test/pages/new_private_chat/widget/contact_status_widget_test.dart @@ -0,0 +1,64 @@ +import 'package:fluffychat/pages/new_private_chat/widget/contact_status_widget.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:flutter_svg/flutter_svg.dart'; +import 'package:fluffychat/domain/model/contact/contact_status.dart'; +import 'package:linagora_design_flutter/colors/linagora_ref_colors.dart'; + +void main() { + group('ContactStatusWidget', () { + testWidgets('renders correctly for inactive status', + (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + localizationsDelegates: L10n.localizationsDelegates, + supportedLocales: L10n.supportedLocales, + home: Scaffold( + body: ContactStatusWidget(status: ContactStatus.inactive), + ), + ), + ); + + expect(find.byType(SvgPicture), findsOneWidget); + + expect(find.byType(Text), findsOneWidget); + + final svgPicture = tester.widget(find.byType(SvgPicture)); + expect( + svgPicture.colorFilter, + ColorFilter.mode( + LinagoraRefColors.material().neutral[60]!, + BlendMode.srcIn, + ), + ); + + final text = tester.widget(find.byType(Text)); + expect(text.style?.color, LinagoraRefColors.material().neutral[60]); + expect( + text.style?.fontSize, + Theme.of(tester.element(find.byType(ContactStatusWidget))) + .textTheme + .bodySmall + ?.fontSize, + ); + }); + + testWidgets('renders correctly for active status', + (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + localizationsDelegates: L10n.localizationsDelegates, + supportedLocales: L10n.supportedLocales, + home: Scaffold( + body: ContactStatusWidget(status: ContactStatus.active), + ), + ), + ); + + expect(find.byType(SvgPicture), findsNothing); + expect(find.byType(Text), findsNothing); + expect(find.byType(SizedBox), findsOneWidget); + }); + }); +}