|
1 | 1 | // ignore_for_file: avoid_redundant_argument_values
|
2 | 2 |
|
3 | 3 | import 'package:stream_chat/src/core/models/attachment.dart';
|
| 4 | +import 'package:stream_chat/src/core/models/attachment_file.dart'; |
4 | 5 | import 'package:stream_chat/src/core/models/draft_message.dart';
|
5 | 6 | import 'package:stream_chat/src/core/models/message.dart';
|
6 | 7 | import 'package:stream_chat/src/core/models/poll.dart';
|
@@ -303,8 +304,8 @@ void main() {
|
303 | 304 | group('Message and DraftMessage conversion', () {
|
304 | 305 | test('should convert Message to DraftMessage correctly', () {
|
305 | 306 | final attachments = [
|
306 |
| - Attachment(type: 'image'), |
307 |
| - Attachment(type: 'file'), |
| 307 | + Attachment(type: 'image', uploadState: const UploadState.success()), |
| 308 | + Attachment(type: 'file', uploadState: const UploadState.success()), |
308 | 309 | ];
|
309 | 310 | final mentionedUsers = [
|
310 | 311 | User(id: 'user1'),
|
@@ -355,10 +356,51 @@ void main() {
|
355 | 356 | expect(draftMessage.extraData, equals(message.extraData));
|
356 | 357 | });
|
357 | 358 |
|
| 359 | + test('should only include successfully uploaded attachments', () { |
| 360 | + final successfulAttachment = Attachment( |
| 361 | + id: 'success-attachment', |
| 362 | + type: 'image', |
| 363 | + uploadState: const UploadState.success(), |
| 364 | + ); |
| 365 | + final preparingAttachment = Attachment( |
| 366 | + id: 'preparing-attachment', |
| 367 | + type: 'file', |
| 368 | + uploadState: const UploadState.preparing(), |
| 369 | + ); |
| 370 | + final inProgressAttachment = Attachment( |
| 371 | + id: 'progress-attachment', |
| 372 | + type: 'image', |
| 373 | + uploadState: const UploadState.inProgress(uploaded: 50, total: 100), |
| 374 | + ); |
| 375 | + final failedAttachment = Attachment( |
| 376 | + id: 'failed-attachment', |
| 377 | + type: 'file', |
| 378 | + uploadState: const UploadState.failed(error: 'Upload failed'), |
| 379 | + ); |
| 380 | + |
| 381 | + final message = Message( |
| 382 | + id: 'test-message', |
| 383 | + text: 'Test message with mixed upload states', |
| 384 | + attachments: [ |
| 385 | + successfulAttachment, |
| 386 | + preparingAttachment, |
| 387 | + inProgressAttachment, |
| 388 | + failedAttachment, |
| 389 | + ], |
| 390 | + ); |
| 391 | + |
| 392 | + final draftMessage = message.toDraftMessage(); |
| 393 | + |
| 394 | + // Only the successfully uploaded attachment should be included |
| 395 | + expect(draftMessage.attachments.length, equals(1)); |
| 396 | + expect(draftMessage.attachments.first.id, equals('success-attachment')); |
| 397 | + expect(draftMessage.attachments.first.uploadState.isSuccess, isTrue); |
| 398 | + }); |
| 399 | + |
358 | 400 | test('should convert DraftMessage to Message correctly', () {
|
359 | 401 | final attachments = [
|
360 |
| - Attachment(type: 'image'), |
361 |
| - Attachment(type: 'file'), |
| 402 | + Attachment(type: 'image', uploadState: const UploadState.success()), |
| 403 | + Attachment(type: 'file', uploadState: const UploadState.success()), |
362 | 404 | ];
|
363 | 405 | final mentionedUsers = [
|
364 | 406 | User(id: 'user1'),
|
|
0 commit comments