Files
cutdex/packages/cutdex_ui/test/app_theme_test.dart
T
lingjhf 27e77fff39 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.
2026-10-05 23:36:23 +08:00

217 lines
6.7 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('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());
}
});
}