Files
cutdex/test/theme_switch_controls_test.dart
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

147 lines
5.1 KiB
Dart

import 'package:cutdex/app/editor_theme.dart';
import 'package:cutdex/l10n/app_localizations.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:cutdex/shared/widgets/drop_to_add_overlay.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'theme switches preserve combobox query, focus and control styles',
(tester) async {
var selected = 0;
Future<void> mount(ThemeData theme) async {
await tester.pumpWidget(
MaterialApp(
theme: theme,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: SizedBox(
width: 300,
child: Column(
children: [
AppTabs<int>(
tabs: const [AppTab(0, 'General'), AppTab(1, 'Other')],
value: 0,
onChanged: (_) {},
),
AppCombobox<int>(
emptyLabel: 'No matching options',
searchHint: 'Search options',
label: 'Choice',
value: selected,
options: const [
AppSelectOption(0, 'Alpha'),
AppSelectOption(1, 'Beta'),
],
onChanged: (value) => selected = value,
),
AppSwitch(value: false, onChanged: (_) {}),
const ResourceDownloadProgress(
downloadedBytes: 0,
totalBytes: 1000,
status: '',
),
const SizedBox(height: 40, child: DropToAddOverlay()),
],
),
),
),
),
);
await tester.pumpAndSettle();
}
await mount(EditorTheme.penLight);
final combo = find.byType(AppCombobox<int>);
final initialState = tester.state(combo);
final input = find.descendant(
of: combo,
matching: find.byType(TextField),
);
await tester.tap(input);
await tester.enterText(input, 'Bet');
await tester.pumpAndSettle();
for (final (theme, background, border, label, scrim, track, thumb) in [
(
EditorTheme.penDark,
const Color(0xFF3F3F46).withValues(alpha: .3),
const Color(0xFFFCFCFC).withValues(alpha: .084),
const Color(0xFFFCFCFC).withValues(alpha: .55),
Colors.black.withValues(alpha: .62),
const Color(0x1AC8C8C8),
const Color(0xFFFCFCFC),
),
(
EditorTheme.penLight,
Colors.transparent,
Colors.transparent,
const Color(0xFF71717A),
Colors.black.withValues(alpha: .38),
const Color(0x0A020202),
const Color(0xFF020202),
),
]) {
await mount(theme);
expect(tester.state(combo), same(initialState));
final field = tester.widget<TextField>(input);
expect(field.controller!.text, 'Bet');
expect(field.focusNode!.hasFocus, isTrue);
expect(find.text('Beta'), findsOneWidget);
final container = tester.widget<Container>(
find.descendant(of: combo, matching: find.byType(Container)).first,
);
expect((container.decoration! as BoxDecoration).color, background);
final tab = tester.widget<TextButton>(
find.widgetWithText(TextButton, 'General'),
);
expect(tab.style!.side!.resolve({})!.color, border);
final progressLabel = tester.widget<Text>(
find.descendant(
of: find.byType(ResourceDownloadProgress),
matching: find.byType(Text),
),
);
expect(progressLabel.style!.color, label);
final overlay = tester.widget<ColoredBox>(
find.descendant(
of: find.byType(DropToAddOverlay),
matching: find.byType(ColoredBox),
),
);
expect(overlay.color, scrim);
final switchTrack = tester.widget<AnimatedContainer>(
find
.descendant(
of: find.byType(AppSwitch),
matching: find.byType(AnimatedContainer),
)
.first,
);
expect((switchTrack.decoration! as BoxDecoration).color, track);
final switchThumb = tester
.widgetList<DecoratedBox>(
find.descendant(
of: find.byType(AppSwitch),
matching: find.byType(DecoratedBox),
),
)
.firstWhere(
(box) =>
(box.decoration as BoxDecoration).shape == BoxShape.circle,
);
expect((switchThumb.decoration as BoxDecoration).color, thumb);
expect(tester.takeException(), isNull);
}
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(selected, 1);
},
);
}