From 1b7e27d826e5631d7802d0d27bf0244ba2917531 Mon Sep 17 00:00:00 2001 From: Gaurav-Kushwaha-1225 Date: Tue, 7 Jan 2025 21:39:50 +0530 Subject: [PATCH] test: added tests for `pressedTint` feature Tests are added for the `pressedTint` feature in the `MessageWithPossibleSender` widget. The tests are for checking the color of the `MessageWithPossibleSender` initially (transparent), after long press (pressedTint) and lastly after closing the `showMessageActionSheet`. --- test/widgets/message_list_test.dart | 74 +++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/test/widgets/message_list_test.dart b/test/widgets/message_list_test.dart index b1f443c8b5..f09e0eb2c7 100644 --- a/test/widgets/message_list_test.dart +++ b/test/widgets/message_list_test.dart @@ -24,6 +24,7 @@ import 'package:zulip/widgets/message_list.dart'; import 'package:zulip/widgets/page.dart'; import 'package:zulip/widgets/store.dart'; import 'package:zulip/widgets/channel_colors.dart'; +import 'package:zulip/widgets/theme.dart'; import '../api/fake_api.dart'; import '../example_data.dart' as eg; @@ -1095,6 +1096,79 @@ void main() { debugNetworkImageHttpClientProvider = null; }); + + + group('action sheet visual feedback', () { + late Message message; + + setUp(() { + // Create a basic message for testing + message = eg.streamMessage(); + }); + + // Helper function to find DecoratedBox and get its color + Color? getBackgroundColor(WidgetTester tester) { + final decoratedBox = tester.widget( + find.descendant( + of: find.byType(MessageWithPossibleSender), + matching: find.byType(DecoratedBox), + ), + ); + return (decoratedBox.decoration as BoxDecoration).color; + } + + Future buildTestWidget(WidgetTester tester) async { + await setupMessageListPage( + tester, + messages: [message], + ); + } + + testWidgets('starts with transparent background', (tester) async { + await buildTestWidget(tester); + + expect( + getBackgroundColor(tester), + equals(Colors.transparent), + reason: 'Message should start with transparent background', + ); + }); + + testWidgets('shows tint color when long pressed', (tester) async { + await buildTestWidget(tester); + + // Trigger long press + await tester.longPress(find.byType(MessageWithPossibleSender)); + await tester.pump(); + + final expectedTint = DesignVariables.of(tester.element(find.byType(MessageWithPossibleSender))) + .pressedTint; + + expect( + getBackgroundColor(tester), + equals(expectedTint), + reason: 'Message should show tint color during long press', + ); + }); + + testWidgets('returns to transparent after action sheet dismissal', (tester) async { + await buildTestWidget(tester); + + // Open action sheet + await tester.longPress(find.byType(MessageWithPossibleSender)); + await tester.pump(); + + // Simulate action sheet dismissal by tapping outside + await tester.tapAt(const Offset(0, 0)); + await tester.pumpAndSettle(); + + expect( + getBackgroundColor(tester), + equals(Colors.transparent), + reason: 'Message should return to transparent after dismissal', + ); + }); + }); }); group('Starred messages', () {