// Author: fruit.com.cn import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:fruitshorts/core/theme/app_colors.dart'; import 'package:fruitshorts/core/theme/app_theme.dart'; import 'package:fruitshorts/core/widgets/subpage_header.dart'; void main() { testWidgets('should_render_unified_dark_header_dimensions', (tester) async { await tester.pumpWidget( MaterialApp( theme: AppTheme.light(), home: Scaffold( body: AppSubpageHeader( title: 'Title', backKey: const Key('sample-back'), ), ), ), ); expect(tester.getSize(find.byKey(const Key('subpage-header'))).height, 52); expect( tester.getSize(find.byKey(const Key('sample-back'))), const Size(40, 40), ); final title = tester.widget(find.byKey(const Key('subpage-title'))); expect(title.style?.fontSize, 18); expect(title.style?.fontWeight, FontWeight.w800); expect(title.style?.color, AppColors.textPrimary); final back = tester.getRect(find.byKey(const Key('sample-back'))); final titleRect = tester.getRect(find.byKey(const Key('subpage-title'))); expect(titleRect.left - back.right, closeTo(12, 0.5)); final surface = tester.widget( find.descendant( of: find.byKey(const Key('sample-back')), matching: find.byType(Material), ), ); expect(surface.color, AppColors.transparent); expect((surface.shape! as CircleBorder).side, BorderSide.none); final shadow = tester .widget( find.byKey(const Key('subpage-back-shadow')), ) .decoration as BoxDecoration; expect(shadow.boxShadow, isEmpty); }); testWidgets('should_use_64_height_when_subtitle_exists', (tester) async { await tester.pumpWidget( MaterialApp( theme: AppTheme.light(), home: Scaffold( body: AppSubpageHeader( title: 'Title', subtitle: 'Subtitle', backKey: const Key('sample-back'), ), ), ), ); expect(tester.getSize(find.byKey(const Key('subpage-header'))).height, 64); expect(find.byKey(const Key('subpage-subtitle')), findsOneWidget); }); testWidgets('should_use_translucent_dark_back_button', (tester) async { await tester.pumpWidget( MaterialApp( theme: AppTheme.light(), home: const Scaffold( backgroundColor: AppColors.mediaBlack, body: AppSubpageHeader( title: 'Title', backKey: Key('sample-back'), dark: true, ), ), ), ); final material = tester.widget( find.descendant( of: find.byKey(const Key('sample-back')), matching: find.byType(Material), ), ); final icon = tester.widget( find.descendant( of: find.byKey(const Key('sample-back')), matching: find.byIcon(Icons.chevron_left_rounded), ), ); expect(material.color, AppColors.headerScrim); expect(icon.color, AppColors.onSurface); expect(icon.size, 22); expect(icon.weight, 600); final shadow = tester .widget( find.byKey(const Key('subpage-back-shadow')), ) .decoration as BoxDecoration; expect(shadow.boxShadow!.single.color, AppColors.shadowSoft); expect(shadow.boxShadow!.single.blurRadius, 8); }); }