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( 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 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; }