feat(workspace): refresh desktop editing experience and prepare 0.1.2
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s

This commit is contained in:
lingjhf committed 2026-10-09 01:56:01 +08:00
1 parent aa5255d1e4
commit 2e0033ce2d
260 files changed
+43963 -5591

No files matched your search

+290 -1
View File
@@ -1,3 +1,4 @@
import 'package:cutdex_ui/icons.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/gestures.dart';
@@ -7,6 +8,294 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
for (final dismissal in ['trigger', 'selection', 'outside']) {
testWidgets(
'pointer $dismissal dismissal releases menu trigger highlight',
(tester) async {
late FocusNode triggerFocus;
final states = WidgetStatesController();
addTearDown(states.dispose);
var closed = 0;
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: Align(
alignment: Alignment.topLeft,
child: AppDropdownMenu(
onClose: () => closed++,
items: [AppMenuItem(label: 'Action', onPressed: () {})],
builder: (_, toggle, focus) {
triggerFocus = focus;
return TextButton(
focusNode: focus,
statesController: states,
onPressed: toggle,
child: const Text('Open'),
);
},
),
),
),
),
);
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
await mouse.addPointer(location: const Offset(400, 400));
Future<void> click(Offset point) async {
await mouse.moveTo(point);
await mouse.down(point);
await mouse.up();
}
await click(tester.getCenter(find.text('Open')));
await tester.pumpAndSettle();
expect(find.text('Action'), findsOneWidget);
switch (dismissal) {
case 'trigger':
await click(tester.getCenter(find.text('Open')));
case 'selection':
await click(tester.getCenter(find.text('Action')));
case 'outside':
await click(const Offset(400, 400));
}
await mouse.moveTo(const Offset(450, 450));
await tester.pumpAndSettle();
expect(find.text('Action'), findsNothing);
expect(closed, 1);
expect(triggerFocus.hasFocus, isFalse);
expect(states.value, isNot(contains(WidgetState.focused)));
expect(states.value, isNot(contains(WidgetState.hovered)));
await mouse.removePointer();
expect(tester.takeException(), isNull);
},
);
}
for (final kind in [PointerDeviceKind.mouse, PointerDeviceKind.touch]) {
testWidgets('dropdown outside $kind click activates buttons and inputs', (
tester,
) async {
var outsideClicks = 0;
var menuActions = 0;
final inputFocus = FocusNode();
addTearDown(inputFocus.dispose);
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penLight,
home: Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppDropdownMenu(
items: [
AppMenuItem(
label: 'Menu action',
onPressed: () => menuActions++,
),
],
builder: (_, toggle, focus) => TextButton(
focusNode: focus,
onPressed: toggle,
child: const Text('Open menu'),
),
),
const SizedBox(height: 200),
TextButton(
onPressed: () => outsideClicks++,
child: const Text('Outside button'),
),
SizedBox(width: 240, child: TextField(focusNode: inputFocus)),
],
),
),
),
);
await tester.tap(find.text('Open menu'), kind: kind);
await tester.pumpAndSettle();
expect(find.text('Menu action'), findsOneWidget);
await tester.tap(find.text('Outside button'), kind: kind);
await tester.pumpAndSettle();
expect(find.text('Menu action'), findsNothing);
expect(outsideClicks, 1);
await tester.tap(find.text('Open menu'), kind: kind);
await tester.pumpAndSettle();
await tester.tap(find.byType(TextField), kind: kind);
await tester.pumpAndSettle();
expect(find.text('Menu action'), findsNothing);
expect(inputFocus.hasFocus, isTrue);
expect(menuActions, 0);
expect(tester.takeException(), isNull);
});
testWidgets('dropdowns and selects switch on the first $kind click', (
tester,
) async {
var selected = 0;
var actions = 0;
Widget dropdown(String name) => AppDropdownMenu(
items: [AppMenuItem(label: '$name action', onPressed: () => actions++)],
builder: (_, toggle, focus) =>
TextButton(focusNode: focus, onPressed: toggle, child: Text(name)),
);
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
dropdown('First'),
dropdown('Second'),
SizedBox(
width: 200,
child: AppSelect<int>(
value: selected,
options: const [
AppSelectOption(0, 'Automatic'),
AppSelectOption(1, 'Manual'),
],
onChanged: (next) => selected = next,
label: 'Mode',
emptyLabel: 'No options',
),
),
],
),
),
),
);
await tester.tap(find.text('First'), kind: kind);
await tester.pumpAndSettle();
expect(find.text('First action'), findsOneWidget);
await tester.tap(find.text('Second'), kind: kind);
await tester.pumpAndSettle();
expect(find.text('First action'), findsNothing);
expect(find.text('Second action'), findsOneWidget);
// Clicking the open menu's own trigger still closes it.
await tester.tap(find.text('Second'), kind: kind);
await tester.pumpAndSettle();
expect(find.text('Second action'), findsNothing);
await tester.tap(find.text('First'), kind: kind);
await tester.pumpAndSettle();
await tester.tap(
find.widgetWithText(TextButton, 'Automatic'),
kind: kind,
);
await tester.pumpAndSettle();
expect(find.text('First action'), findsNothing);
expect(find.widgetWithText(MenuItemButton, 'Manual'), findsOneWidget);
await tester.tap(find.text('First'), kind: kind);
await tester.pumpAndSettle();
expect(find.widgetWithText(MenuItemButton, 'Manual'), findsNothing);
expect(find.text('First action'), findsOneWidget);
expect(selected, 0);
await tester.tap(find.text('First action'), kind: kind);
await tester.pumpAndSettle();
expect(actions, 1);
expect(find.text('First action'), findsNothing);
expect(tester.takeException(), isNull);
});
}
testWidgets('Flutter context menu outside click also activates its target', (
tester,
) async {
debugDefaultTargetPlatformOverride = TargetPlatform.windows;
addTearDown(() => debugDefaultTargetPlatformOverride = null);
var outsideClicks = 0;
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppContextMenu(
itemsBuilder: (_) => [
AppMenuItem(label: 'Context action', onPressed: () {}),
],
child: const SizedBox(width: 100, height: 100),
),
const SizedBox(height: 200),
TextButton(
onPressed: () => outsideClicks++,
child: const Text('Outside button'),
),
],
),
),
),
);
await tester.tap(
find.byType(AppContextMenu),
kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton,
);
await tester.pumpAndSettle();
expect(find.text('Context action'), findsOneWidget);
await tester.tap(
find.text('Outside button'),
kind: PointerDeviceKind.mouse,
);
await tester.pumpAndSettle();
expect(find.text('Context action'), findsNothing);
expect(outsideClicks, 1);
expect(tester.takeException(), isNull);
debugDefaultTargetPlatformOverride = null;
});
testWidgets('dropdown offsets do not inherit or overwrite expansion state', (
tester,
) async {
final bucket = PageStorageBucket();
const ancestorKey = PageStorageKey('expanded-property');
int? selected;
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: PageStorage(
bucket: bucket,
child: Builder(
key: ancestorKey,
builder: (context) {
bucket.writeState(context, true);
return SizedBox(
width: 220,
child: AppSelect<int>(
label: 'Color space',
emptyLabel: 'No options',
value: 0,
options: const [
AppSelectOption(0, 'Automatic'),
AppSelectOption(1, 'Manual'),
],
onChanged: (value) => selected = value,
),
);
},
),
),
),
),
);
await tester.pumpAndSettle();
for (var i = 0; i < 2; i++) {
await tester.tap(find.text('Automatic'));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
await tester.tap(find.text('Manual'));
await tester.pumpAndSettle();
expect(selected, 1);
expect(bucket.readState(tester.element(find.byKey(ancestorKey))), isTrue);
expect(tester.takeException(), isNull);
}
});
testWidgets(
'native menu waits for right-button release and dismissal keeps left clicks working',
(tester) async {
@@ -248,7 +537,7 @@ void main() {
await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
expect(find.byIcon(Icons.check), findsOneWidget);
expect(find.byIcon(AppIcons.check), findsOneWidget);
expect(
tester.getSize(find.widgetWithText(MenuItemButton, 'Dark')).height,
28,