import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:ikar/backend/modules/messages.dart'; import 'package:ikar/core/utils/download_progress.dart'; import 'package:ikar/core/utils/file_download.dart'; import 'package:ikar/frontend/widgets/attachment/bubbles/bubble_context.dart'; import 'package:ikar/frontend/widgets/attachment/bubbles/file_bubble.dart'; import 'package:ikar/l10n/app_localizations.dart'; import 'package:ikar/models/attachment.dart'; void main() { testWidgets( 'whole file card cannot open twice while external opening is pending', (tester) async { var opens = 0; var ready = Completer(); await tester.pumpWidget( MaterialApp( locale: const Locale('ru'), localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, home: Scaffold( body: Builder( builder: (context) { const file = FileAttachment( fileId: 765, name: 'report.pdf', size: 1024, ); return FileBubble( file: file, ctx: BubbleContext( context: context, cs: Theme.of(context).colorScheme, text: Colors.black, shape: BubbleShape.singleMiddle, contentType: MessageType.attachment, hasPhotoWithCaption: false, hasMultiplePhotosNoCaption: false, message: CachedMessage( id: '1', accountId: 1, chatId: 2, senderId: 3, time: 1000, status: 'sent', ), isMe: false, myId: 1, chatType: 'DIALOG', ), openFile: ( name, url, { onProgress, onReady, download, downloadOnlyIfMissing = false, }) { opens++; onReady?.call(); return ready.future; }, ); }, ), ), ), ); await tester.tap(find.text('report.pdf')); await tester.pump(); await tester.tap(find.text('report.pdf')); await tester.pump(); expect(opens, 1); expect(find.textContaining('Открытие'), findsOneWidget); ready.complete(const FileDownloadResult(ok: true)); await tester.pumpAndSettle(); ready = Completer(); await tester.tap(find.text('report.pdf')); expect(opens, 2); ready.complete(const FileDownloadResult(ok: true)); await tester.pumpAndSettle(); MediaDownloadProgress.set('765_report.pdf', null); }, ); }