115 lines
3.6 KiB
Dart
115 lines
3.6 KiB
Dart
// 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_light_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<Text>(find.byKey(const Key('subpage-title')));
|
|
expect(title.style?.fontSize, 18);
|
|
expect(title.style?.fontWeight, FontWeight.w800);
|
|
expect(title.style?.color, AppColors.onSurface);
|
|
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<Material>(
|
|
find.descendant(
|
|
of: find.byKey(const Key('sample-back')),
|
|
matching: find.byType(Material),
|
|
),
|
|
);
|
|
expect(surface.color, AppColors.card);
|
|
expect((surface.shape! as CircleBorder).side.color, AppColors.border);
|
|
final shadow =
|
|
tester
|
|
.widget<DecoratedBox>(
|
|
find.byKey(const Key('subpage-back-shadow')),
|
|
)
|
|
.decoration
|
|
as BoxDecoration;
|
|
expect(shadow.boxShadow!.single.color, const Color(0x14000000));
|
|
expect(shadow.boxShadow!.single.blurRadius, 8);
|
|
expect(shadow.boxShadow!.single.offset, const Offset(0, 2));
|
|
});
|
|
|
|
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: Colors.black,
|
|
body: AppSubpageHeader(
|
|
title: 'Title',
|
|
backKey: Key('sample-back'),
|
|
dark: true,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
final material = tester.widget<Material>(
|
|
find.descendant(
|
|
of: find.byKey(const Key('sample-back')),
|
|
matching: find.byType(Material),
|
|
),
|
|
);
|
|
final icon = tester.widget<Icon>(
|
|
find.descendant(
|
|
of: find.byKey(const Key('sample-back')),
|
|
matching: find.byIcon(Icons.chevron_left_rounded),
|
|
),
|
|
);
|
|
expect(material.color, const Color(0x59000000));
|
|
expect(icon.color, Colors.white);
|
|
expect(icon.size, 22);
|
|
expect(icon.weight, 600);
|
|
final shadow =
|
|
tester
|
|
.widget<DecoratedBox>(
|
|
find.byKey(const Key('subpage-back-shadow')),
|
|
)
|
|
.decoration
|
|
as BoxDecoration;
|
|
expect(shadow.boxShadow!.single.color, const Color(0x33000000));
|
|
expect(shadow.boxShadow!.single.blurRadius, 8);
|
|
});
|
|
}
|