Skip to content

Commit

Permalink
test: added tests for pressedTint feature
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Gaurav-Kushwaha-1225 authored and gnprice committed Jan 17, 2025
1 parent 03a4244 commit 22832d0
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<DecoratedBox>(
find.descendant(
of: find.byType(MessageWithPossibleSender),
matching: find.byType(DecoratedBox),
),
);
return (decoratedBox.decoration as BoxDecoration).color;
}

Future<void> 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', () {
Expand Down

0 comments on commit 22832d0

Please sign in to comment.