2024-12-19 15:19:10 +08:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:appflowy/shared/icon_emoji_picker/flowy_icon_emoji_picker.dart';
|
|
|
|
import 'package:appflowy/shared/icon_emoji_picker/icon_color_picker.dart';
|
|
|
|
import 'package:appflowy/shared/icon_emoji_picker/icon_picker.dart';
|
2025-01-21 11:58:45 +08:00
|
|
|
import 'package:appflowy/shared/icon_emoji_picker/icon_uploader.dart';
|
2024-12-19 15:19:10 +08:00
|
|
|
import 'package:appflowy/shared/icon_emoji_picker/tab.dart';
|
|
|
|
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/space_icon_popup.dart';
|
2025-01-21 11:58:45 +08:00
|
|
|
import 'package:desktop_drop/desktop_drop.dart';
|
|
|
|
import 'package:flowy_infra_ui/style_widget/primary_rounded_button.dart';
|
2024-12-19 15:19:10 +08:00
|
|
|
import 'package:flowy_svg/flowy_svg.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2023-11-14 22:33:07 +08:00
|
|
|
import 'package:flutter_emoji_mart/flutter_emoji_mart.dart';
|
2023-06-27 15:17:51 +08:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
|
|
|
|
import 'base.dart';
|
|
|
|
|
|
|
|
extension EmojiTestExtension on WidgetTester {
|
|
|
|
Future<void> tapEmoji(String emoji) async {
|
2023-11-09 13:11:13 +08:00
|
|
|
final emojiWidget = find.descendant(
|
|
|
|
of: find.byType(EmojiPicker),
|
|
|
|
matching: find.text(emoji),
|
|
|
|
);
|
2023-06-27 15:17:51 +08:00
|
|
|
await tapButton(emojiWidget);
|
|
|
|
}
|
2024-12-19 15:19:10 +08:00
|
|
|
|
2025-01-20 17:55:01 +08:00
|
|
|
Future<void> tapIcon(EmojiIconData icon, {bool enableColor = true}) async {
|
2024-12-19 15:19:10 +08:00
|
|
|
final iconsData = IconsData.fromJson(jsonDecode(icon.emoji));
|
|
|
|
final pickTab = find.byType(PickerTab);
|
|
|
|
expect(pickTab, findsOneWidget);
|
|
|
|
await pumpAndSettle();
|
|
|
|
final iconTab = find.descendant(
|
|
|
|
of: pickTab,
|
|
|
|
matching: find.text(PickerTabType.icon.tr),
|
|
|
|
);
|
|
|
|
expect(iconTab, findsOneWidget);
|
2025-01-05 19:54:59 +08:00
|
|
|
await tapButton(iconTab);
|
2024-12-19 15:19:10 +08:00
|
|
|
final selectedSvg = find.descendant(
|
|
|
|
of: find.byType(FlowyIconPicker),
|
|
|
|
matching: find.byWidgetPredicate(
|
2025-01-14 09:31:43 +08:00
|
|
|
(w) => w is FlowySvg && w.svgString == iconsData.svgString,
|
2024-12-19 15:19:10 +08:00
|
|
|
),
|
|
|
|
);
|
2025-01-03 10:04:14 +08:00
|
|
|
|
2025-01-13 14:35:29 +08:00
|
|
|
await tapButton(selectedSvg.first);
|
2025-01-20 17:55:01 +08:00
|
|
|
if (enableColor) {
|
|
|
|
final colorPicker = find.byType(IconColorPicker);
|
|
|
|
expect(colorPicker, findsOneWidget);
|
|
|
|
final selectedColor = find.descendant(
|
|
|
|
of: colorPicker,
|
|
|
|
matching: find.byWidgetPredicate((w) {
|
|
|
|
if (w is Container) {
|
|
|
|
final d = w.decoration;
|
|
|
|
if (d is ShapeDecoration) {
|
|
|
|
if (d.color ==
|
|
|
|
Color(
|
|
|
|
int.parse(iconsData.color ?? builtInSpaceColors.first),
|
|
|
|
)) {
|
|
|
|
return true;
|
|
|
|
}
|
2024-12-19 15:19:10 +08:00
|
|
|
}
|
|
|
|
}
|
2025-01-20 17:55:01 +08:00
|
|
|
return false;
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
await tapButton(selectedColor);
|
|
|
|
}
|
2024-12-19 15:19:10 +08:00
|
|
|
}
|
2025-01-21 11:58:45 +08:00
|
|
|
|
|
|
|
Future<void> pickImage(EmojiIconData icon) async {
|
|
|
|
final pickTab = find.byType(PickerTab);
|
|
|
|
expect(pickTab, findsOneWidget);
|
|
|
|
await pumpAndSettle();
|
|
|
|
|
|
|
|
/// switch to custom tab
|
|
|
|
final iconTab = find.descendant(
|
|
|
|
of: pickTab,
|
|
|
|
matching: find.text(PickerTabType.custom.tr),
|
|
|
|
);
|
|
|
|
expect(iconTab, findsOneWidget);
|
|
|
|
await tapButton(iconTab);
|
|
|
|
|
|
|
|
/// mock for dragging image
|
|
|
|
final dropTarget = find.descendant(
|
|
|
|
of: find.byType(IconUploader),
|
|
|
|
matching: find.byType(DropTarget),
|
|
|
|
);
|
|
|
|
expect(dropTarget, findsOneWidget);
|
|
|
|
final dropTargetWidget = dropTarget.evaluate().first.widget as DropTarget;
|
|
|
|
dropTargetWidget.onDragDone?.call(
|
|
|
|
DropDoneDetails(
|
2025-02-07 18:17:46 +08:00
|
|
|
files: [DropItemFile(icon.emoji)],
|
2025-01-21 11:58:45 +08:00
|
|
|
localPosition: Offset.zero,
|
|
|
|
globalPosition: Offset.zero,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
await pumpAndSettle(const Duration(seconds: 3));
|
|
|
|
|
|
|
|
/// confirm to upload
|
|
|
|
final confirmButton = find.descendant(
|
|
|
|
of: find.byType(IconUploader),
|
|
|
|
matching: find.byType(PrimaryRoundedButton),
|
|
|
|
);
|
|
|
|
await tapButton(confirmButton);
|
|
|
|
}
|
2023-06-27 15:17:51 +08:00
|
|
|
}
|