feat: initial Cutdex application

Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
This commit is contained in:
lingjhf committed 2026-10-05 23:36:23 +08:00
commit 27e77fff39
718 files changed
+183958

No files matched your search

@@ -0,0 +1,129 @@
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('standard dialog uses Codex spacing, type and button size', (
tester,
) async {
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: Builder(
builder: (context) => TextButton(
onPressed: () => showAppDialog<void>(
context: context,
builder: (_) => AppDialog(
title: '下载资源',
description: '下载所需模型',
actions: [
TextButton(onPressed: () {}, child: const Text('取消')),
FilledButton(onPressed: () {}, child: const Text('下载')),
],
child: const Text('正在准备资源'),
),
),
child: const Text('Open'),
),
),
),
),
);
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
final frame = tester.getRect(find.byKey(const Key('app-dialog-frame')));
final title = tester.getRect(find.text('下载资源'));
final description = tester.getRect(find.text('下载所需模型'));
final body = tester.getRect(find.text('正在准备资源'));
final close = tester.getRect(
find.byKey(const Key('app-dialog-close-button')),
);
final action = tester.getRect(find.widgetWithText(FilledButton, '下载'));
final cancel = tester.getRect(find.widgetWithText(TextButton, '取消'));
expect(title.left - frame.left, AppSpacing.large);
expect(frame.width, 420);
expect(title.top - frame.top, AppSpacing.large);
expect(body.left - frame.left, AppSpacing.large);
expect(description.top - title.bottom, AppSpacing.tiny);
expect(body.top - description.bottom, AppSpacing.compact);
expect(frame.right - close.right, AppSpacing.medium);
expect(close.top - frame.top, AppSpacing.medium);
expect(close.size, const Size.square(24));
expect(
Theme.of(tester.element(find.text('下载')))
.filledButtonTheme
.style!
.minimumSize!
.resolve({}),
const Size(0, 32),
);
expect(action.height, 32);
expect(cancel.height, 32);
expect(action.left - cancel.right, AppSpacing.compact);
expect(frame.right - action.right, AppSpacing.large);
expect(action.top - body.bottom, AppSpacing.compact);
expect(frame.bottom - action.bottom, AppSpacing.large);
expect(tester.widget<Text>(find.text('下载资源')).style?.fontSize, 20);
expect(
tester.widget<Text>(find.text('下载资源')).style?.fontWeight,
FontWeight.w600,
);
expect(
DefaultTextStyle.of(tester.element(find.text('正在准备资源'))).style.fontSize,
14,
);
expect(
Theme.of(tester.element(find.text('正在准备资源'))).dialogTheme.backgroundColor,
const Color(0xFF242424),
);
final shape = AppTheme.penDark.dialogTheme.shape! as RoundedRectangleBorder;
expect(shape.borderRadius, BorderRadius.circular(AppRadius.dialog));
expect(shape.side, BorderSide.none);
expect(
Theme.of(tester.element(find.text('取消')))
.textButtonTheme
.style!
.textStyle!
.resolve({})!
.fontSize,
14,
);
});
testWidgets('selection dialog returns the chosen option', (tester) async {
String? selected;
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: Builder(
builder: (context) => TextButton(
onPressed: () async {
selected = await showAppDialog<String>(
context: context,
builder: (dialogContext) => AppDialog(
title: '选择目标片段',
child: AppDialogOption(
label: '片段 A',
onPressed: () => Navigator.pop(dialogContext, 'a'),
),
),
);
},
child: const Text('Open'),
),
),
),
),
);
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('app-dialog-frame')), findsOneWidget);
await tester.tap(find.text('片段 A'));
await tester.pumpAndSettle();
expect(selected, 'a');
});
}
+107
View File
@@ -0,0 +1,107 @@
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('property list rows use the project item gap without a line', (
tester,
) async {
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Theme(
data: AppTheme.propertiesPanelTheme(AppTheme.penDark),
child: Scaffold(
body: AppItemGroup(
children: [
AppItem(
key: const Key('first-mask'),
leading: IconButton(
key: const Key('mask-visibility'),
icon: const Icon(Icons.visibility_outlined),
onPressed: () {},
),
actions: [
IconButton(
key: const Key('mask-delete'),
icon: const Icon(Icons.delete_outline),
onPressed: () {},
),
],
child: const Text('蒙版 1'),
),
const AppItem(key: Key('second-mask'), child: Text('蒙版 2')),
],
),
),
),
),
);
expect(
tester.getSize(find.byKey(const Key('first-mask'))).height,
AppControlSize.propertyItem,
);
expect(
tester.getSize(find.byKey(const Key('second-mask'))).height,
AppControlSize.propertyItem,
);
expect(
tester.getSize(find.byKey(const Key('mask-visibility'))).height,
AppControlSize.propertyControl,
);
expect(
tester.getRect(find.byKey(const Key('second-mask'))).top -
tester.getRect(find.byKey(const Key('first-mask'))).bottom,
AppSidebarMetrics.projectGap,
);
expect(find.byType(Divider), findsNothing);
});
testWidgets('property list hover and selection use translucent ink', (
tester,
) async {
for (final theme in [AppTheme.penLight, AppTheme.penDark]) {
Future<void> mount({required bool selected}) => tester.pumpWidget(
MaterialApp(
theme: theme,
home: Theme(
data: AppTheme.propertiesPanelTheme(theme),
child: Scaffold(
body: AppItem(
selected: selected,
onPressed: () {},
child: const Text('蒙版 1'),
),
),
),
),
);
Finder row<T extends Widget>() =>
find.descendant(of: find.byType(AppItem), matching: find.byType(T));
final ink = theme.colorScheme.onSurface;
await mount(selected: false);
expect(
tester.widget<Material>(row<Material>()).color,
Colors.transparent,
);
expect(
tester.widget<InkWell>(row<InkWell>()).hoverColor,
ink.withValues(
alpha: theme.brightness == Brightness.dark ? .078 : .058,
),
);
await mount(selected: true);
expect(
tester.widget<Material>(row<Material>()).color,
ink.withValues(alpha: .05),
);
expect(
tester.widget<InkWell>(row<InkWell>()).hoverColor,
ink.withValues(alpha: .05),
);
}
});
}
+428
View File
@@ -0,0 +1,428 @@
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'native menu waits for right-button release and dismissal keeps left clicks working',
(tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
addTearDown(() => debugDefaultTargetPlatformOverride = null);
const channel = MethodChannel('cutdex_native/context_menu');
var opened = 0;
var clicked = 0;
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
_,
) async {
opened++;
return null;
});
addTearDown(
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
channel,
null,
),
);
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penLight,
home: Scaffold(
body: Column(
children: [
AppContextMenu(
itemsBuilder: (_) => [
AppMenuItem(label: 'Action', onPressed: () {}),
],
child: const SizedBox(width: 200, height: 200),
),
TextButton(
onPressed: () => clicked++,
child: const Text('Other control'),
),
],
),
),
),
);
for (var i = 0; i < 2; i++) {
final pointer = await tester.startGesture(
tester.getCenter(find.byType(AppContextMenu)),
kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton,
);
// Hold past the tap-down deadline: native tracking must not start yet.
await tester.pump(const Duration(milliseconds: 200));
expect(opened, i);
await pointer.up();
await tester.pumpAndSettle();
expect(opened, i + 1);
expect(find.text('Action'), findsNothing);
await tester.tap(find.text('Other control'));
await tester.pumpAndSettle();
expect(clicked, i + 1);
}
expect(tester.takeException(), isNull);
debugDefaultTargetPlatformOverride = null;
},
);
testWidgets(
'searchable shared select filters languages and resets after selection',
(tester) async {
var value = 'ja';
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penLight,
home: Scaffold(
body: SizedBox(
width: 280,
child: StatefulBuilder(
builder: (context, setState) => AppSelect<String>(
emptyLabel: '没有匹配的选项',
label: '源语言',
value: value,
searchable: true,
searchHint: '搜索选项',
onChanged: (next) => setState(() => value = next),
options: const [
AppSelectOption('ja', '日语 (ja)'),
AppSelectOption('zh', '中文 (zh)'),
AppSelectOption('en', '英语 (en)', enabled: false),
],
),
),
),
),
),
);
await tester.tap(find.byType(TextField));
await tester.pumpAndSettle();
await tester.enterText(find.byType(TextField), 'zh');
await tester.pumpAndSettle();
expect(find.widgetWithText(MenuItemButton, '日语 (ja)'), findsNothing);
await tester.tap(find.widgetWithText(MenuItemButton, '中文 (zh)'));
await tester.pumpAndSettle();
expect(value, 'zh');
await tester.tap(find.byType(TextField));
await tester.pumpAndSettle();
expect(find.widgetWithText(MenuItemButton, '日语 (ja)'), findsOneWidget);
expect(
tester
.widget<MenuItemButton>(
find.widgetWithText(MenuItemButton, '英语 (en)'),
)
.onPressed,
isNull,
);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(find.byType(MenuItemButton), findsNothing);
expect(
tester.widget<TextField>(find.byType(TextField)).controller!.text,
'中文 (zh)',
);
await tester.tap(find.byType(TextField));
await tester.enterText(find.byType(TextField), 'unknown');
await tester.pumpAndSettle();
expect(find.text('没有匹配的选项'), findsOneWidget);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(value, 'zh');
expect(
tester.widget<TextField>(find.byType(TextField)).controller!.text,
'中文 (zh)',
);
await tester.tap(find.byType(TextField));
await tester.enterText(find.byType(TextField), 'ja');
await tester.pumpAndSettle();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(value, 'ja');
expect(
tester.widget<TextField>(find.byType(TextField)).controller!.text,
'日语 (ja)',
);
expect(tester.takeException(), isNull);
},
);
testWidgets(
'stationary mouse scroll releases old hover focus without shifting the menu',
(tester) async {
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: SizedBox(
width: 280,
child: AppSelect<int>(
emptyLabel: 'No matching options',
label: 'Language',
value: 0,
searchable: true,
searchHint: '搜索选项',
onChanged: (_) {},
options: [
for (var i = 0; i < 40; i++)
AppSelectOption(i, 'Language $i'),
],
),
),
),
),
);
await tester.tap(find.byType(TextField));
await tester.pumpAndSettle();
final previous = find.widgetWithText(MenuItemButton, 'Language 3');
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
await mouse.addPointer(location: Offset.zero);
await mouse.moveTo(tester.getCenter(previous));
await tester.pumpAndSettle();
expect(
tester.widget<MenuItemButton>(previous).focusNode!.hasFocus,
isFalse,
);
final scrollable = tester
.stateList<ScrollableState>(find.byType(Scrollable))
.firstWhere((state) => state.axisDirection == AxisDirection.down);
scrollable.position.jumpTo(24);
// Do not move the pointer: allow the normal transition to finish.
await tester.pumpAndSettle();
expect(
tester.widget<MenuItemButton>(previous).focusNode!.hasFocus,
isFalse,
);
expect(scrollable.position.pixels, 24);
final highlight = const Color(0xFFFCFCFC).withValues(alpha: 0.078);
final backgrounds = tester.widgetList<Material>(
find.descendant(
of: find.byType(MenuItemButton),
matching: find.byType(Material),
),
);
expect(
backgrounds.where((material) => material.color == highlight),
hasLength(1),
);
await mouse.removePointer();
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
},
);
testWidgets('select works inside a dialog in both themes', (tester) async {
for (final theme in [AppTheme.penLight, AppTheme.penDark]) {
var value = 1;
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: StatefulBuilder(
builder: (context, setState) => Scaffold(
body: AlertDialog(
content: SizedBox(
width: 360,
child: AppSelect<int>(
emptyLabel: 'No matching options',
value: value,
label: 'Theme',
options: const [
AppSelectOption(1, 'System'),
AppSelectOption(2, 'Dark'),
AppSelectOption(3, 'Disabled', enabled: false),
],
onChanged: (next) => setState(() => value = next),
),
),
),
),
),
),
);
await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
expect(find.byIcon(Icons.check), findsOneWidget);
expect(
tester.getSize(find.widgetWithText(MenuItemButton, 'Dark')).height,
28,
);
expect(
tester
.widget<MenuItemButton>(
find.widgetWithText(MenuItemButton, 'Disabled'),
)
.onPressed,
isNull,
);
await tester.tap(find.widgetWithText(MenuItemButton, 'Dark'));
await tester.pumpAndSettle();
expect(value, 2);
expect(find.byType(MenuItemButton), findsNothing);
}
});
testWidgets('dropdown supports keyboard selection and escape', (
tester,
) async {
var selected = false;
late FocusNode triggerFocus;
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penLight,
home: Scaffold(
body: AppDropdownMenu(
items: [
AppMenuItem(label: 'Action', onPressed: () => selected = true),
],
builder: (context, toggle, focus) {
triggerFocus = focus;
return TextButton(
focusNode: focus,
onPressed: toggle,
child: const Text('Open'),
);
},
),
),
),
);
triggerFocus.requestFocus();
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pumpAndSettle();
expect(find.text('Action'), findsOneWidget);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(selected, isTrue);
expect(triggerFocus.hasFocus, isTrue);
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(find.text('Action'), findsNothing);
expect(triggerFocus.hasFocus, isTrue);
});
testWidgets('context menu clamps at edges and opens submenu', (tester) async {
var selected = false;
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: AppContextMenu(
itemsBuilder: (_) => [
AppSubmenu(
label: 'More',
items: [
AppMenuItem(
label: 'Action',
onPressed: () => selected = true,
),
],
),
],
child: const SizedBox.expand(),
),
),
),
);
await tester.tapAt(const Offset(795, 595), buttons: kSecondaryMouseButton);
await tester.pumpAndSettle();
final rect = tester.getRect(find.byType(SubmenuButton));
expect(rect.right, lessThanOrEqualTo(800));
expect(rect.bottom, lessThanOrEqualTo(600));
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.pumpAndSettle();
await tester.tap(find.text('Action'));
await tester.pumpAndSettle();
expect(selected, isTrue);
expect(find.text('More'), findsNothing);
expect(tester.takeException(), isNull);
});
testWidgets(
'context menu stays beside a bottom pointer in an offset region',
(tester) async {
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: Padding(
padding: const EdgeInsets.only(left: 180, top: 120),
child: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 400,
height: 460,
child: AppContextMenu(
itemsBuilder: (_) => const [
AppMenuItem(label: 'Action 1'),
AppMenuItem(label: 'Action 2'),
AppMenuItem(label: 'Action 3'),
AppMenuItem(label: 'Action 4'),
AppMenuItem(label: 'Action 5'),
],
child: const ColoredBox(color: Colors.black),
),
),
),
),
),
),
);
const pointer = Offset(340, 560);
await tester.tapAt(pointer, buttons: kSecondaryMouseButton);
await tester.pumpAndSettle();
final items = find.byType(MenuItemButton);
expect(items, findsNWidgets(5));
final first = tester.getRect(items.first);
final last = tester.getRect(items.last);
expect(first.left, closeTo(pointer.dx + 6, 1));
expect(first.top, greaterThan(380));
expect(last.bottom, lessThanOrEqualTo(pointer.dy));
},
);
testWidgets(
'context menu only focuses its first item when opened by keyboard',
(tester) async {
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: AppContextMenu(
itemsBuilder: (_) => const [AppMenuItem(label: 'Action')],
child: const SizedBox.expand(),
),
),
),
);
await tester.tapAt(
const Offset(300, 300),
buttons: kSecondaryMouseButton,
);
await tester.pumpAndSettle();
expect(find.text('Action'), findsOneWidget);
expect(FocusManager.instance.primaryFocus, isA<FocusNode>());
expect(FocusManager.instance.primaryFocus, isNot(isA<FocusScopeNode>()));
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
await tester.sendKeyEvent(LogicalKeyboardKey.contextMenu);
await tester.pumpAndSettle();
expect(find.text('Action'), findsOneWidget);
expect(FocusManager.instance.primaryFocus, isA<FocusScopeNode>());
},
);
}
@@ -0,0 +1,101 @@
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'popover anchors below its trigger and dismisses outside and with Escape',
(tester) async {
var outsideClicks = 0;
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penLight,
home: Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppPopover(
builder: (_, toggle) => IconButton(
key: const Key('trigger'),
onPressed: toggle,
icon: const Icon(Icons.task_alt),
),
child: const Text('Tasks'),
),
const SizedBox(height: 200),
TextButton(
onPressed: () => outsideClicks++,
child: const Text('Outside'),
),
],
),
),
),
);
await tester.tap(find.byKey(const Key('trigger')));
await tester.pumpAndSettle();
expect(find.text('Tasks'), findsOneWidget);
// The menu host must not add a second outline around the inner surface.
final menuSurface = tester
.widgetList<Material>(
find.ancestor(
of: find.text('Tasks'),
matching: find.byType(Material),
),
)
.firstWhere((material) => material.shape is OutlinedBorder);
expect(
(menuSurface.shape! as OutlinedBorder).side.style,
BorderStyle.none,
);
expect(
tester.getTopLeft(find.text('Tasks')).dy,
greaterThan(tester.getBottomLeft(find.byKey(const Key('trigger'))).dy),
);
await tester.tap(find.text('Outside'));
await tester.pumpAndSettle();
expect(find.text('Tasks'), findsNothing);
expect(outsideClicks, 1);
await tester.tap(find.byKey(const Key('trigger')));
await tester.pumpAndSettle();
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(find.text('Tasks'), findsNothing);
expect(tester.takeException(), isNull);
},
);
testWidgets('end-aligned popover stays inside the viewport', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penLight,
home: Scaffold(
body: Align(
alignment: Alignment.topLeft,
child: AppPopover(
width: 288,
alignment: AlignmentDirectional.bottomEnd,
surfaceKey: const Key('surface'),
builder: (_, toggle) => TextButton(
key: const Key('trigger'),
onPressed: toggle,
child: const Text('Open'),
),
child: const Text('Content'),
),
),
),
),
);
await tester.tap(find.byKey(const Key('trigger')));
await tester.pumpAndSettle();
expect(
tester.getRect(find.byKey(const Key('surface'))).left,
greaterThanOrEqualTo(0),
);
expect(tester.takeException(), isNull);
});
}
@@ -0,0 +1,120 @@
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'dialog fits small screens and restores trigger focus on escape',
(tester) async {
tester.view.physicalSize = const Size(320, 400);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final focus = FocusNode();
addTearDown(focus.dispose);
for (final theme in [AppTheme.penLight, AppTheme.penDark]) {
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Scaffold(
body: Builder(
builder: (context) => TextButton(
focusNode: focus,
onPressed: () => showAppDialog<void>(
context: context,
builder: (_) => AppDialog(
title: 'Settings',
width: 1040,
height: 680,
actions: [
TextButton(onPressed: () {}, child: const Text('Save')),
],
child: Column(
children: List.generate(
12,
(index) => AppField(
label: 'Field $index',
error: index == 0 ? 'Invalid' : null,
orientation: AppFieldOrientation.horizontal,
child: const TextField(),
),
),
),
),
),
child: const Text('Open'),
),
),
),
),
);
focus.requestFocus();
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(find.text('Settings'), findsOneWidget);
expect(
tester.getRect(find.byType(Dialog)).right,
lessThanOrEqualTo(320),
);
expect(tester.takeException(), isNull);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(find.text('Settings'), findsNothing);
expect(focus.hasFocus, isTrue);
}
},
);
testWidgets('tabs navigate enabled options and switch supports keyboard', (
tester,
) async {
var tab = 0;
var enabled = false;
final focus = FocusNode();
addTearDown(focus.dispose);
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: StatefulBuilder(
builder: (context, update) => Column(
children: [
AppTabs<int>(
tabs: const [
AppTab(0, 'General'),
AppTab(1, 'Disabled', enabled: false),
AppTab(2, 'MCP'),
],
value: tab,
onChanged: (value) => update(() => tab = value),
),
AppSwitch(
value: enabled,
focusNode: focus,
semanticLabel: 'Service',
onChanged: (value) => update(() => enabled = value),
),
],
),
),
),
),
);
await tester.tap(find.text('General'));
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.pump();
expect(tab, 2);
await tester.sendKeyEvent(LogicalKeyboardKey.home);
await tester.pump();
expect(tab, 0);
focus.requestFocus();
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.space);
await tester.pumpAndSettle();
expect(enabled, isTrue);
expect(tester.takeException(), isNull);
});
}
+216
View File
@@ -0,0 +1,216 @@
import 'dart:ui' as ui;
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('Icon button states use translucent ink without stacking selection', () {
final style = AppTheme.penDark.iconButtonTheme.style!;
const ink = Color(0xFFFCFCFC);
expect(style.foregroundColor!.resolve({}), ink.withValues(alpha: .498));
expect(style.backgroundColor!.resolve({}), Colors.transparent);
expect(
style.overlayColor!.resolve({WidgetState.hovered}),
ink.withValues(alpha: .078),
);
expect(
style.overlayColor!.resolve({WidgetState.pressed}),
ink.withValues(alpha: .078),
);
expect(
style.backgroundColor!.resolve({WidgetState.selected}),
ink.withValues(alpha: .05),
);
expect(style.foregroundColor!.resolve({WidgetState.selected}), ink);
expect(
style.foregroundColor!.resolve({WidgetState.hovered}),
ink.withValues(alpha: .498),
);
expect(
style.backgroundColor!.resolve({
WidgetState.selected,
WidgetState.hovered,
}),
ink.withValues(alpha: .10),
);
expect(
style.overlayColor!.resolve({WidgetState.selected, WidgetState.hovered}),
Colors.transparent,
);
expect(
style.overlayColor!.resolve({WidgetState.disabled, WidgetState.hovered}),
Colors.transparent,
);
});
test('Scrollbar uses neutral translucent states and a transparent track', () {
final theme = AppTheme.penDark.scrollbarTheme;
const ink = Color(0xFFFCFCFC);
expect(theme.thumbColor!.resolve({}), ink.withValues(alpha: .084));
expect(
theme.thumbColor!.resolve({WidgetState.hovered}),
ink.withValues(alpha: .156),
);
expect(
theme.thumbColor!.resolve({WidgetState.dragged}),
ink.withValues(alpha: .156),
);
expect(
theme.trackColor!.resolve({WidgetState.hovered}),
Colors.transparent,
);
expect(
theme.trackBorderColor!.resolve({WidgetState.hovered}),
Colors.transparent,
);
});
testWidgets('property inputs use the composer surface and text colors', (
tester,
) async {
for (final theme in [AppTheme.penLight, AppTheme.penDark]) {
final inspector = AppTheme.propertiesPanelTheme(theme);
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Theme(
data: inspector,
child: const Scaffold(
body: AppTextField(label: 'X', hintText: 'Value'),
),
),
),
);
final input = tester.widget<TextField>(find.byType(TextField));
final decoration = input.decoration!;
expect(
decoration.fillColor,
theme.extension<AppSurfaces>()!.composerBackground,
);
expect(input.style!.color, theme.colorScheme.onSurface);
expect(input.cursorHeight, input.style!.fontSize);
expect(
decoration.hintStyle!.color,
inspector.inputDecorationTheme.hintStyle!.color,
);
for (final border in [
decoration.border,
decoration.enabledBorder,
decoration.disabledBorder,
decoration.focusedBorder,
decoration.errorBorder,
decoration.focusedErrorBorder,
]) {
expect(border, isA<OutlineInputBorder>());
expect(border!.borderSide, BorderSide.none);
expect(
(border as OutlineInputBorder).borderRadius,
BorderRadius.circular(AppRadius.large),
);
}
await tester.tap(find.byType(TextField));
await tester.pump();
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
}
});
testWidgets('property input fill paints the full 28px control height', (
tester,
) async {
const boundaryKey = ValueKey('property-input-pixels');
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Theme(
data: AppTheme.propertiesPanelTheme(AppTheme.penDark),
child: const Scaffold(
body: Center(
child: RepaintBoundary(
key: boundaryKey,
child: SizedBox(
width: 120,
height: AppControlSize.propertyControl,
child: AppTextField(label: 'X'),
),
),
),
),
),
),
);
await tester.pump();
expect(
tester.getSize(find.byType(TextField)).height,
AppControlSize.propertyControl,
);
final boundary = tester.renderObject<RenderRepaintBoundary>(
find.byKey(boundaryKey),
);
await tester.runAsync(() async {
final image = await boundary.toImage(pixelRatio: 1);
final pixels = (await image.toByteData(
format: ui.ImageByteFormat.rawRgba,
))!;
List<int> pixel(int x, int y) {
final offset = (y * image.width + x) * 4;
return List.generate(4, (channel) => pixels.getUint8(offset + channel));
}
expect(pixel(60, 14), [47, 47, 47, 255]);
expect(pixel(60, 0), pixel(60, 14));
expect(pixel(60, 27), pixel(60, 14));
image.dispose();
});
});
testWidgets('system typography and themed controls work in light and dark', (
tester,
) async {
for (final theme in [AppTheme.penLight, AppTheme.penDark]) {
var enabled = false;
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Scaffold(
body: Center(
child: SizedBox(
width: 280,
child: StatefulBuilder(
builder: (context, setState) => Column(
mainAxisSize: MainAxisSize.min,
children: [
const AppTextField(label: 'W', unit: '%'),
AppSwitch(
value: enabled,
onChanged: (value) => setState(() => enabled = value),
),
AppSlider(value: .5, onChanged: (_) {}),
],
),
),
),
),
),
),
);
await tester.pumpAndSettle();
expect(
tester.widget<TextField>(find.byType(TextField)).style!.fontFamily,
AppTheme.systemFontFamily(
Theme.of(tester.element(find.byType(TextField))).platform,
),
);
await tester.tap(find.byType(Switch));
await tester.pumpAndSettle();
expect(enabled, isTrue);
await tester.enterText(find.byType(TextField), '125');
expect(find.text('125'), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
}
});
}
@@ -0,0 +1,33 @@
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('brief loading finishes without showing the indicator', (
tester,
) async {
const indicator = Key('loading-indicator');
await tester.pumpWidget(
const DelayedLoadingIndicator(child: SizedBox(key: indicator)),
);
await tester.pump(const Duration(milliseconds: 100));
expect(find.byKey(indicator), findsNothing);
await tester.pumpWidget(const SizedBox());
await tester.pump(const Duration(milliseconds: 200));
expect(find.byKey(indicator), findsNothing);
expect(tester.takeException(), isNull);
});
testWidgets('slow loading shows the indicator after the shared delay', (
tester,
) async {
const indicator = Key('loading-indicator');
await tester.pumpWidget(
const DelayedLoadingIndicator(child: SizedBox(key: indicator)),
);
await tester.pump(DelayedLoadingIndicator.delay);
await tester.pump();
expect(find.byKey(indicator), findsOneWidget);
});
}
@@ -0,0 +1,84 @@
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
const channel = MethodChannel('cutdex_native/context_menu');
setUp(() => debugDefaultTargetPlatformOverride = TargetPlatform.macOS);
tearDown(() {
debugDefaultTargetPlatformOverride = null;
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, null);
});
test(
'native entries preserve nested actions, disabled items and coordinates',
() async {
var invoked = false;
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (call) async {
expect(call.method, 'show');
final args = call.arguments as Map;
expect(args['x'], 120.0);
expect(args['y'], 80.0);
final items = args['items'] as List;
expect(items[0]['enabled'], false);
expect(items[1]['separator'], true);
expect(items[2]['children'][0]['selected'], true);
return 1;
});
expect(
await showNativeContextMenu(
[
const AppMenuItem(label: 'Disabled'),
const AppMenuSeparator(),
AppSubmenu(
label: 'More',
items: [
AppMenuItem(
label: 'Selected',
selected: true,
onPressed: () => invoked = true,
),
],
),
],
const Offset(120, 80),
() => true,
),
isTrue,
);
expect(invoked, isTrue);
},
);
test('dismissal and disposed owners do not invoke actions', () async {
var invoked = false;
final items = [
AppMenuItem(label: 'Action', onPressed: () => invoked = true),
];
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (_) async => null);
expect(await showNativeContextMenu(items, Offset.zero, () => true), isTrue);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (_) async => 0);
expect(
await showNativeContextMenu(items, Offset.zero, () => false),
isTrue,
);
expect(invoked, isFalse);
});
test('missing native plugin falls back to Flutter', () async {
expect(
await showNativeContextMenu(
[const AppMenuItem(label: 'Action')],
Offset.zero,
() => true,
),
isFalse,
);
});
}
@@ -0,0 +1,71 @@
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('active resource progress omits a redundant status suffix', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: ResourceDownloadProgress(
downloadedBytes: 7100000,
totalBytes: 618000000,
status: '',
),
),
),
);
expect(find.text('0 B/s - 7.1 MB/618 MB'), findsOneWidget);
});
testWidgets('progress displays the download speed supplied by the task', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: ResourceDownloadProgress(
downloadedBytes: 7100000,
totalBytes: 618000000,
bytesPerSecond: 1200000,
status: '',
),
),
),
);
expect(find.text('1.2 MB/s - 7.1 MB/618 MB'), findsOneWidget);
});
testWidgets('resource download shows byte progress above a thin track', (
tester,
) async {
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: const Scaffold(
body: SizedBox(
width: 300,
child: ResourceDownloadProgress(
downloadedBytes: 7100000,
totalBytes: 618000000,
status: '已暂停',
paused: true,
),
),
),
),
);
final label = find.text('7.1 MB/618 MB, 已暂停');
final bar = find.byType(LinearProgressIndicator);
expect(label, findsOneWidget);
expect(tester.getRect(label).bottom, lessThan(tester.getRect(bar).top));
final indicator = tester.widget<LinearProgressIndicator>(bar);
expect(indicator.value, closeTo(7.1 / 618, 0.00001));
expect(indicator.minHeight, 3);
expect(indicator.backgroundColor, AppTheme.penDark.dividerColor);
});
}