Files
cutdex/test/resource_navigation_test.dart
T
lingjhf abc1868550
Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
feat(workspace): 桌面工作区、主题与交互更新,发布 0.1.2
2026-10-08 18:17:12 +00:00

174 lines
5.9 KiB
Dart

import 'package:cutdex/features/media/resource_navigation.dart';
import 'package:cutdex/l10n/app_localizations.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
Future<void> mount(
WidgetTester tester, {
double width = 240,
double scale = 1,
Locale locale = const Locale('zh'),
AppPalette palette = AppPalette.graphite,
Brightness brightness = Brightness.dark,
}) async {
var selected = ResourceSection.imported;
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.desktopWorkspaceTheme(
AppTheme.forPalette(palette, brightness),
),
locale: locale,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: width,
child: MediaQuery(
data: MediaQueryData(textScaler: TextScaler.linear(scale)),
child: StatefulBuilder(
builder: (context, setState) => ResourceSectionTabs(
selected: selected,
onSelected: (value) => setState(() => selected = value),
),
),
),
),
),
),
),
);
await tester.pumpAndSettle();
}
testWidgets('translated tabs fit scaled text in all desktop palettes', (
tester,
) async {
for (final palette in AppPalette.values) {
for (final brightness in Brightness.values) {
for (final locale in [
const Locale('zh'),
const Locale('en'),
const Locale('de'),
const Locale('ru'),
]) {
for (final width in [120.0, 240.0, 400.0, 640.0]) {
await mount(
tester,
width: width,
scale: 1.3,
locale: locale,
palette: palette,
brightness: brightness,
);
expect(
tester.takeException(),
isNull,
reason: '$palette $brightness $locale $width',
);
expect(
tester
.getSize(find.byKey(const Key('resource-section-tabs')))
.height,
36,
);
final header = tester.getRect(
find.byKey(const Key('resource-section-tabs')),
);
for (final button in find.byType(TextButton).evaluate()) {
final bounds = tester.getRect(find.byWidget(button.widget));
expect(bounds.top, greaterThanOrEqualTo(header.top));
expect(bounds.bottom, lessThanOrEqualTo(header.bottom));
expect(bounds.height, AppDesktopMetrics.timelineTabControl);
}
}
}
}
}
});
testWidgets(
'narrow tabs scroll with wheel and drag through the shared edge fade',
(tester) async {
await mount(tester, width: 160);
final list = find.byKey(const Key('resource-tabs-list'));
final scroll = tester.widget<SingleChildScrollView>(list);
final fade = tester.widget<ScrollEdgeFade>(find.byType(ScrollEdgeFade));
expect(fade.axis, Axis.horizontal);
expect(fade.controller, same(scroll.controller));
final position = scroll.controller!.position;
expect(position.pixels, 0);
expect(position.extentAfter, greaterThan(0));
expect(find.byKey(const Key('resource-tabs-more')), findsNothing);
for (final section in ResourceSection.values) {
expect(
find.byKey(ValueKey('resource-tab-${section.name}')),
findsOneWidget,
);
}
await tester.sendEventToBinding(
PointerScrollEvent(
position: tester.getCenter(list),
scrollDelta: const Offset(0, 70),
),
);
await tester.pumpAndSettle();
expect(position.pixels, 70);
expect(position.extentBefore, greaterThan(0));
expect(position.extentAfter, greaterThan(0));
await tester.drag(list, const Offset(-600, 0));
await tester.pumpAndSettle();
expect(position.pixels, position.maxScrollExtent);
await tester.tap(find.byKey(const ValueKey('resource-tab-transitions')));
await tester.pumpAndSettle();
expect(
tester
.widget<ResourceSectionTabs>(find.byType(ResourceSectionTabs))
.selected,
ResourceSection.transitions,
);
tester
.widget<ResourceSectionTabs>(find.byType(ResourceSectionTabs))
.onSelected!(ResourceSection.imported);
await tester.pumpAndSettle();
expect(position.pixels, 0);
expect(tester.takeException(), isNull);
},
);
testWidgets('a programmatically selected tab scrolls into view', (
tester,
) async {
await mount(tester, width: 160);
tester
.widget<ResourceSectionTabs>(find.byType(ResourceSectionTabs))
.onSelected!(ResourceSection.transitions);
await tester.pumpAndSettle();
final viewport = tester.getRect(
find.byKey(const Key('resource-tabs-list')),
);
final selected = tester.getRect(
find.byKey(const ValueKey('resource-tab-transitions')),
);
expect(selected.left, greaterThanOrEqualTo(viewport.left));
expect(selected.right, lessThanOrEqualTo(viewport.right));
expect(tester.takeException(), isNull);
});
testWidgets('wide panel exposes every category directly', (tester) async {
await mount(tester, width: 640);
for (final section in ResourceSection.values) {
expect(
find.byKey(ValueKey('resource-tab-${section.name}')),
findsOneWidget,
);
}
expect(find.byKey(const Key('resource-tabs-more')), findsNothing);
});
}