Files
cutdex/packages/cutdex_ui/test/app_icons_test.dart
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

154 lines
4.5 KiB
Dart

import 'dart:ui' as ui;
import 'package:cutdex_ui/cutdex_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUpAll(() async {
for (final family in ['PhosphorRegular', 'PhosphorFill']) {
final loader = FontLoader('packages/cutdex_ui/$family')
..addFont(
rootBundle.load('packages/cutdex_ui/assets/fonts/$family.ttf'),
);
await loader.load();
}
});
testWidgets('bundled fonts render distinct glyphs and filled shapes', (
tester,
) async {
final close = await renderIcon(tester, AppIcons.close);
final check = await renderIcon(tester, AppIcons.check);
final star = await renderIcon(tester, AppIcons.star);
final filledStar = await renderIcon(tester, AppIcons.starFilled);
// Missing fonts would render identical fallback boxes for these codepoints.
expect(close, isNot(orderedEquals(check)));
expect(paintedPixels(close), greaterThan(0));
expect(paintedPixels(star), greaterThan(0));
expect(paintedPixels(filledStar), greaterThan(paintedPixels(star)));
});
testWidgets('IconData works in WorkspacePanel and inherits IconTheme', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(
home: IconTheme(
data: IconThemeData(color: Colors.purple),
child: WorkspacePanel(
title: 'Media',
icon: AppIcons.video,
child: SizedBox(),
),
),
),
);
final icon = find.byIcon(AppIcons.video);
expect(icon, findsOneWidget);
final text = tester.widget<RichText>(
find.descendant(of: icon, matching: find.byType(RichText)),
);
expect(text.text.style!.color, Colors.purple);
expect(text.text.style!.fontFamily, 'packages/cutdex_ui/PhosphorRegular');
expect(tester.takeException(), isNull);
});
testWidgets('RTL mirrors navigation while preserving playback direction', (
tester,
) async {
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.rtl,
child: Row(children: [Icon(AppIcons.arrowBack), Icon(AppIcons.play)]),
),
);
expect(
find.descendant(
of: find.byIcon(AppIcons.arrowBack),
matching: find.byType(Transform),
),
findsOneWidget,
);
expect(
find.descendant(
of: find.byIcon(AppIcons.play),
matching: find.byType(Transform),
),
findsNothing,
);
});
testWidgets('workspace themes replace implicit Material action icons', (
tester,
) async {
var backPressed = 0;
for (final theme in [AppTheme.penLight, AppTheme.penDark]) {
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Scaffold(
body: Row(
children: [
BackButton(onPressed: () => backPressed++),
CloseButton(onPressed: () {}),
const DrawerButton(),
const EndDrawerButton(),
],
),
),
),
);
expect(find.byIcon(AppIcons.arrowBack), findsOneWidget);
expect(find.byIcon(AppIcons.close), findsOneWidget);
expect(find.byIcon(AppIcons.menu), findsNWidgets(2));
expect(find.byTooltip('Back'), findsOneWidget);
await tester.tap(find.byIcon(AppIcons.arrowBack));
}
expect(backPressed, 2);
});
}
Future<Uint8List> renderIcon(WidgetTester tester, IconData icon) async {
final key = GlobalKey();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: RepaintBoundary(
key: key,
child: SizedBox.square(
dimension: 48,
child: Icon(icon, size: 48, color: Colors.black),
),
),
),
),
);
final boundary =
key.currentContext!.findRenderObject()! as RenderRepaintBoundary;
final pixels = await tester.runAsync(() async {
final image = await boundary.toImage();
try {
final data = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
return Uint8List.fromList(data!.buffer.asUint8List());
} finally {
image.dispose();
}
});
return pixels!;
}
int paintedPixels(Uint8List rgba) {
var result = 0;
for (var index = 3; index < rgba.length; index += 4) {
if (rgba[index] != 0) result++;
}
return result;
}