445 lines
14 KiB
Dart
445 lines
14 KiB
Dart
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(
|
|
'desktop inspector keeps panel colors with UI3 typography and inputs',
|
|
() {
|
|
for (final palette in AppPalette.values) {
|
|
for (final brightness in Brightness.values) {
|
|
final base = AppTheme.desktopWorkspaceTheme(
|
|
AppTheme.forPalette(palette, brightness),
|
|
);
|
|
final theme = AppTheme.propertiesPanelTheme(base);
|
|
final dark = brightness == Brightness.dark;
|
|
expect(
|
|
theme.colorScheme.surface,
|
|
base.colorScheme.surfaceContainerLow,
|
|
);
|
|
expect(theme.canvasColor, base.colorScheme.surfaceContainerLow);
|
|
expect(
|
|
theme.colorScheme.surfaceContainerLow,
|
|
base.colorScheme.surfaceContainerLow,
|
|
);
|
|
expect(theme.scaffoldBackgroundColor, base.scaffoldBackgroundColor);
|
|
expect(
|
|
theme.inputDecorationTheme.fillColor,
|
|
dark ? const Color(0xFF383838) : const Color(0xFFF5F5F5),
|
|
);
|
|
expect(
|
|
theme.colorScheme.onSurface,
|
|
dark ? Colors.white : Colors.black.withValues(alpha: .9),
|
|
);
|
|
expect(
|
|
theme.colorScheme.onSurfaceVariant,
|
|
dark
|
|
? Colors.white.withValues(alpha: .7)
|
|
: Colors.black.withValues(alpha: .5),
|
|
);
|
|
expect(
|
|
theme.dividerColor,
|
|
dark ? const Color(0xFF444444) : const Color(0xFFE6E6E6),
|
|
);
|
|
expect(theme.colorScheme.primary, base.colorScheme.primary);
|
|
final text = theme.textTheme.bodyMedium!;
|
|
expect(text.fontFamily, 'packages/cutdex_ui/Inter');
|
|
expect(
|
|
text.fontFamilyFallback,
|
|
base.textTheme.bodyMedium!.fontFamilyFallback,
|
|
);
|
|
expect(text.fontSize, 11);
|
|
expect(text.height! * text.fontSize!, closeTo(16, .001));
|
|
expect(text.fontVariations, const [ui.FontVariation('wght', 450)]);
|
|
expect(text.letterSpacing, closeTo(.055, .001));
|
|
expect(
|
|
(theme.inputDecorationTheme.enabledBorder! as OutlineInputBorder)
|
|
.borderRadius,
|
|
BorderRadius.circular(5),
|
|
);
|
|
expect(
|
|
theme.inputDecorationTheme.enabledBorder!.borderSide,
|
|
BorderSide.none,
|
|
);
|
|
expect(
|
|
theme.inputDecorationTheme.focusedBorder!.borderSide.color,
|
|
base.colorScheme.primary,
|
|
);
|
|
}
|
|
}
|
|
},
|
|
);
|
|
|
|
testWidgets('slider density follows inspector and desktop contexts', (
|
|
tester,
|
|
) async {
|
|
final desktop = AppTheme.desktopWorkspaceTheme(AppTheme.penDark);
|
|
for (final (theme, height) in [
|
|
(AppTheme.propertiesPanelTheme(desktop), 24.0),
|
|
(desktop, 36.0),
|
|
(
|
|
AppTheme.propertiesPanelTheme(AppTheme.penDark),
|
|
AppControlSize.standard,
|
|
),
|
|
]) {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: theme,
|
|
home: Scaffold(
|
|
body: Center(
|
|
child: SizedBox(
|
|
width: 220,
|
|
child: AppSlider(value: .5, onChanged: (_) {}),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(tester.getSize(find.byType(AppSlider)).height, height);
|
|
expect(tester.takeException(), isNull);
|
|
}
|
|
});
|
|
|
|
test(
|
|
'inspector density leaves general desktop and touch inputs unchanged',
|
|
() {
|
|
final desktop = AppTheme.desktopWorkspaceTheme(AppTheme.penDark);
|
|
final inspector = AppTheme.propertiesPanelTheme(desktop);
|
|
expect(desktop.inputDecorationTheme.constraints!.minHeight, 36);
|
|
expect(inspector.inputDecorationTheme.constraints!.minHeight, 24);
|
|
expect(inspector.textTheme.bodyMedium!.fontSize, 11);
|
|
expect(inspector.textTheme.bodySmall!.fontSize, 11);
|
|
expect(
|
|
inspector.iconButtonTheme.style!.fixedSize!.resolve({}),
|
|
const Size.square(24),
|
|
);
|
|
expect(desktop.extension<InspectorControlDensity>(), isNull);
|
|
expect(inspector.extension<InspectorControlDensity>(), isNotNull);
|
|
final dialog = AppTheme.dialogContentTheme(inspector);
|
|
expect(dialog.extension<InspectorControlDensity>(), isNull);
|
|
expect(dialog.inputDecorationTheme.constraints!.minHeight, 36);
|
|
expect(dialog.textTheme.bodyMedium!.fontSize, 14);
|
|
final touch = AppTheme.propertiesPanelTheme(AppTheme.penDark);
|
|
expect(touch.extension<InspectorControlDensity>(), isNull);
|
|
expect(
|
|
touch.iconButtonTheme.style!.fixedSize!.resolve({}),
|
|
const Size.square(28),
|
|
);
|
|
},
|
|
);
|
|
|
|
testWidgets('multiline input keeps its first line near the top', (
|
|
tester,
|
|
) async {
|
|
final controller = TextEditingController(text: 'First\nSecond');
|
|
addTearDown(controller.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: AppTheme.desktopWorkspaceTheme(AppTheme.penDark),
|
|
home: Scaffold(
|
|
body: Center(
|
|
child: SizedBox(
|
|
width: 240,
|
|
height: 100,
|
|
child: AppTextField(
|
|
controller: controller,
|
|
minLines: 3,
|
|
maxLines: 3,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final editable = tester
|
|
.state<EditableTextState>(find.byType(EditableText))
|
|
.renderEditable;
|
|
final caret = editable.getLocalRectForCaret(const TextPosition(offset: 0));
|
|
expect(
|
|
editable.localToGlobal(caret.center).dy -
|
|
tester.getTopLeft(find.byType(TextField)).dy,
|
|
lessThan(25),
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
await tester.pumpWidget(const SizedBox());
|
|
});
|
|
|
|
testWidgets('labelled single-line inputs keep text and caret centered', (
|
|
tester,
|
|
) async {
|
|
final controller = TextEditingController(text: '125');
|
|
addTearDown(controller.dispose);
|
|
for (final brightness in Brightness.values) {
|
|
for (final desktop in [false, true]) {
|
|
final base = AppTheme.forPalette(AppPalette.graphite, brightness);
|
|
final theme = AppTheme.propertiesPanelTheme(
|
|
desktop ? AppTheme.desktopWorkspaceTheme(base) : base,
|
|
);
|
|
final height = desktop
|
|
? AppInspectorMetrics.input
|
|
: AppControlSize.propertyControl;
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: theme,
|
|
home: Scaffold(
|
|
body: Center(
|
|
child: SizedBox(
|
|
width: 240,
|
|
height: height,
|
|
child: AppTextField(
|
|
controller: controller,
|
|
label: 'W',
|
|
unit: '%',
|
|
hintText: 'Value',
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final field = find.byType(TextField);
|
|
final label = find.text('W');
|
|
expect(
|
|
tester.getRect(label).center.dy,
|
|
tester.getRect(field).center.dy,
|
|
);
|
|
expect(
|
|
tester.widget<TextField>(field).decoration!.prefixIcon,
|
|
isNotNull,
|
|
);
|
|
for (final text in ['', '125', '项目']) {
|
|
await tester.enterText(field, text);
|
|
await tester.pump();
|
|
final editable = tester
|
|
.state<EditableTextState>(find.byType(EditableText))
|
|
.renderEditable;
|
|
final caret = editable.getLocalRectForCaret(
|
|
TextPosition(offset: text.length),
|
|
);
|
|
expect(
|
|
editable.localToGlobal(caret.center).dy,
|
|
closeTo(tester.getCenter(field).dy, 1),
|
|
);
|
|
expect(tester.getSize(field).height, height);
|
|
expect(tester.takeException(), isNull);
|
|
}
|
|
await tester.pumpWidget(const SizedBox());
|
|
}
|
|
}
|
|
});
|
|
|
|
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());
|
|
}
|
|
});
|
|
}
|