107 lines
3.3 KiB
Dart
107 lines
3.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:material_symbols_icons/symbols.dart';
|
|
import 'package:ikar/backend/modules/messages.dart';
|
|
import 'package:ikar/core/utils/download_progress.dart';
|
|
import 'package:ikar/frontend/widgets/message_bubble.dart';
|
|
import 'package:ikar/l10n/app_localizations.dart';
|
|
import 'package:ikar/models/attachment.dart';
|
|
|
|
Future<void> pumpFile(
|
|
WidgetTester tester,
|
|
String name, {
|
|
required VoidCallback menu,
|
|
int? fileId,
|
|
}) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
locale: const Locale('ru'),
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
home: Scaffold(
|
|
body: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: GestureDetector(
|
|
onTap: menu,
|
|
onLongPress: menu,
|
|
child: MessageBubble(
|
|
message: CachedMessage(
|
|
id: '1',
|
|
accountId: 1,
|
|
chatId: 2,
|
|
senderId: 7,
|
|
time: 0,
|
|
attachments: [
|
|
FileAttachment(fileId: fileId, name: name, size: 128),
|
|
],
|
|
),
|
|
isMe: false,
|
|
myId: 1,
|
|
chatType: 'DIALOG',
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
}
|
|
|
|
void main() {
|
|
for (final name in [
|
|
'report.pdf',
|
|
'archive.zip',
|
|
'notes.docx',
|
|
'unknown.bin',
|
|
'song.mp3',
|
|
'picture.png',
|
|
]) {
|
|
for (final target in ['name', 'icon']) {
|
|
testWidgets(
|
|
'$name $target tap starts file action instead of message menu',
|
|
(tester) async {
|
|
var menus = 0;
|
|
await pumpFile(tester, name, menu: () => menus++);
|
|
await tester.tap(
|
|
target == 'name'
|
|
? find.text(name)
|
|
: find.byIcon(
|
|
name.endsWith('.mp3')
|
|
? Symbols.audio_file
|
|
: Symbols.description,
|
|
),
|
|
);
|
|
await tester.pump();
|
|
expect(menus, 0);
|
|
// Missing metadata proves that the file action handled the tap.
|
|
expect(find.text('Не удалось определить файл'), findsOneWidget);
|
|
await tester.pump(const Duration(seconds: 3));
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
testWidgets('long press still reaches the message menu', (tester) async {
|
|
var menus = 0;
|
|
await pumpFile(tester, 'report.pdf', menu: () => menus++);
|
|
await tester.longPress(find.text('report.pdf'));
|
|
expect(menus, 1);
|
|
expect(find.text('Не удалось определить файл'), findsNothing);
|
|
});
|
|
|
|
testWidgets(
|
|
'tap during download neither opens menu nor starts another action',
|
|
(tester) async {
|
|
var menus = 0;
|
|
MediaDownloadProgress.set('42_report.pdf', 0.5);
|
|
addTearDown(() => MediaDownloadProgress.set('42_report.pdf', null));
|
|
await pumpFile(tester, 'report.pdf', menu: () => menus++, fileId: 42);
|
|
await tester.tap(find.text('report.pdf'));
|
|
await tester.pump();
|
|
expect(menus, 0);
|
|
expect(find.textContaining('50%'), findsOneWidget);
|
|
expect(find.byType(CircularProgressIndicator), findsOneWidget);
|
|
},
|
|
);
|
|
}
|