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() { testWidgets('slider density follows inspector and desktop contexts', ( tester, ) async { final desktop = AppTheme.desktopWorkspaceTheme(AppTheme.penDark); for (final (theme, height) in [ (AppTheme.propertiesPanelTheme(desktop), 28.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, 28); expect(inspector.textTheme.bodyMedium!.fontSize, 13); expect(inspector.textTheme.bodySmall!.fontSize, 12); expect( inspector.iconButtonTheme.style!.fixedSize!.resolve({}), const Size.square(24), ); expect(desktop.extension(), isNull); expect(inspector.extension(), isNotNull); final dialog = AppTheme.dialogContentTheme(inspector); expect(dialog.extension(), isNull); expect(dialog.inputDecorationTheme.constraints!.minHeight, 36); expect(dialog.textTheme.bodyMedium!.fontSize, 14); final touch = AppTheme.propertiesPanelTheme(AppTheme.penDark); expect(touch.extension(), 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(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(field).decoration!.prefixIcon, isNotNull, ); for (final text in ['', '125', '项目']) { await tester.enterText(field, text); await tester.pump(); final editable = tester .state(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(find.byType(TextField)); final decoration = input.decoration!; expect( decoration.fillColor, theme.extension()!.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()); 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( find.byKey(boundaryKey), ); await tester.runAsync(() async { final image = await boundary.toImage(pixelRatio: 1); final pixels = (await image.toByteData( format: ui.ImageByteFormat.rawRgba, ))!; List 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(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()); } }); }