test(ui): add tests for message_input_attachment_list.dart
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -204,6 +204,7 @@
|
||||
files = (
|
||||
);
|
||||
inputPaths = (
|
||||
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
|
||||
);
|
||||
name = "Thin Binary";
|
||||
outputPaths = (
|
||||
|
||||
@@ -356,7 +356,11 @@ class _ChannelPageState extends State<ChannelPage> {
|
||||
),
|
||||
);
|
||||
},
|
||||
child: defaultWidget.copyWith(onReplyTap: reply),
|
||||
child: defaultWidget.copyWith(
|
||||
onReplyTap: reply,
|
||||
// showReactionPicker: true,
|
||||
// showReactionPickerIndicator: false,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
+190
@@ -0,0 +1,190 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
|
||||
import '../mocks.dart';
|
||||
|
||||
Widget wrapWithStreamChat(
|
||||
Widget child, {
|
||||
StreamChatClient? client,
|
||||
}) {
|
||||
return MaterialApp(
|
||||
home: StreamChat(
|
||||
client: client ?? MockClient(),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('StreamMessageInputAttachmentList tests', () {
|
||||
testWidgets(
|
||||
'StreamMessageInputAttachmentList should render attachments',
|
||||
(WidgetTester tester) async {
|
||||
final attachments = [
|
||||
Attachment(type: 'file', id: 'file1'),
|
||||
Attachment(type: 'file', id: 'file2'),
|
||||
Attachment(type: 'media', id: 'media1'),
|
||||
];
|
||||
|
||||
await tester.pumpWidget(
|
||||
wrapWithStreamChat(
|
||||
StreamMessageInputAttachmentList(
|
||||
attachments: attachments,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Expect 2 file attachments and 1 media attachment
|
||||
expect(find.byType(MessageInputFileAttachments), findsOneWidget);
|
||||
expect(find.byType(MessageInputMediaAttachments), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'StreamMessageInputAttachmentList should call onRemovePressed callback',
|
||||
(WidgetTester tester) async {
|
||||
Attachment? removedAttachment;
|
||||
|
||||
final attachments = [
|
||||
Attachment(type: 'file', id: 'file1'),
|
||||
Attachment(type: 'file', id: 'file2'),
|
||||
];
|
||||
|
||||
await tester.pumpWidget(
|
||||
wrapWithStreamChat(
|
||||
StreamMessageInputAttachmentList(
|
||||
attachments: attachments,
|
||||
onRemovePressed: (attachment) {
|
||||
removedAttachment = attachment;
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final removeButtons = find.byType(RemoveAttachmentButton);
|
||||
|
||||
// Tap the first remove button
|
||||
await tester.tap(removeButtons.first);
|
||||
await tester.pump();
|
||||
|
||||
// Expect the onRemovePressed callback to be called with the second
|
||||
// attachment as they are reversed in the UI.
|
||||
expect(removedAttachment, attachments[1]);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'''StreamMessageInputAttachmentList should display empty box if no attachments''',
|
||||
(WidgetTester tester) async {
|
||||
final attachments = <Attachment>[];
|
||||
|
||||
await tester.pumpWidget(
|
||||
wrapWithStreamChat(
|
||||
StreamMessageInputAttachmentList(
|
||||
attachments: attachments,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Expect an empty box
|
||||
expect(find.byType(SizedBox), findsOneWidget);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('MessageInputFileAttachments tests', () {
|
||||
testWidgets(
|
||||
'MessageInputFileAttachments should render file attachments',
|
||||
(WidgetTester tester) async {
|
||||
final attachments = [
|
||||
Attachment(type: 'file', id: 'file1'),
|
||||
Attachment(type: 'file', id: 'file2'),
|
||||
];
|
||||
|
||||
await tester.pumpWidget(
|
||||
wrapWithStreamChat(
|
||||
MessageInputFileAttachments(
|
||||
attachments: attachments,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Expect 2 file attachments
|
||||
expect(find.byType(ClipRRect), findsNWidgets(2));
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'MessageInputFileAttachments should call onRemovePressed callback',
|
||||
(WidgetTester tester) async {
|
||||
Attachment? removedAttachment;
|
||||
|
||||
final attachments = [
|
||||
Attachment(type: 'file', id: 'file1'),
|
||||
];
|
||||
|
||||
await tester.pumpWidget(
|
||||
wrapWithStreamChat(
|
||||
MessageInputFileAttachments(
|
||||
attachments: attachments,
|
||||
onRemovePressed: (attachment) {
|
||||
removedAttachment = attachment;
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final removeButton = find.byType(RemoveAttachmentButton);
|
||||
|
||||
// Tap the remove button
|
||||
await tester.tap(removeButton);
|
||||
await tester.pump();
|
||||
|
||||
// Expect the onRemovePressed callback to be called with the attachment
|
||||
expect(removedAttachment, attachments.first);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('MessageInputMediaAttachments tests', () {
|
||||
testWidgets(
|
||||
'MessageInputMediaAttachments should render media attachments',
|
||||
(WidgetTester tester) async {
|
||||
final attachments = [
|
||||
Attachment(type: 'media', id: 'media1'),
|
||||
Attachment(type: 'media', id: 'media2'),
|
||||
];
|
||||
|
||||
await tester.pumpWidget(
|
||||
wrapWithStreamChat(
|
||||
MessageInputMediaAttachments(
|
||||
attachments: attachments,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Expect 2 media attachments
|
||||
expect(find.byType(Stack), findsNWidgets(2));
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'MessageInputMediaAttachments should display empty box if no attachments',
|
||||
(WidgetTester tester) async {
|
||||
final attachments = <Attachment>[];
|
||||
|
||||
await tester.pumpWidget(
|
||||
wrapWithStreamChat(
|
||||
MessageInputMediaAttachments(
|
||||
attachments: attachments,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Expect an empty box
|
||||
expect(find.byType(SizedBox), findsOneWidget);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user