98 lines
3.2 KiB
Dart
98 lines
3.2 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:fruitshorts/core/data/models/drama.dart';
|
|
import 'package:fruitshorts/core/theme/app_colors.dart';
|
|
import 'package:fruitshorts/core/theme/app_dimens.dart';
|
|
import 'package:fruitshorts/core/theme/app_theme.dart';
|
|
import 'package:fruitshorts/l10n/app_localizations.dart';
|
|
import 'package:fruitshorts/pages/home/widgets/home_drama_grid.dart';
|
|
|
|
void main() {
|
|
testWidgets('should_render_compact_cover_badges_without_plus_action', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: AppTheme.light(),
|
|
locale: const Locale('en'),
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
home: Scaffold(
|
|
body: SingleChildScrollView(
|
|
child: Builder(
|
|
builder: (context) => SizedBox(
|
|
width: 180,
|
|
child: HomeDramaCard(
|
|
l10n: AppLocalizations.of(context)!,
|
|
drama: _drama,
|
|
onTap: () {},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
final card = find.byKey(const Key('home-drama-card-style-drama'));
|
|
final cardContainer = tester.widget<Container>(
|
|
find.ancestor(of: card, matching: find.byType(Container)).last,
|
|
);
|
|
final cardDecoration = cardContainer.decoration! as BoxDecoration;
|
|
expect(cardDecoration.color, AppColors.card);
|
|
expect(
|
|
cardDecoration.borderRadius,
|
|
BorderRadius.circular(AppDimens.cardRadius),
|
|
);
|
|
expect(cardDecoration.boxShadow, const [AppTheme.cardShadow]);
|
|
|
|
final tag = tester.widget<Container>(
|
|
find.byKey(const Key('home-drama-tag-style-drama')),
|
|
);
|
|
expect((tag.decoration! as BoxDecoration).color, AppColors.badgePink);
|
|
expect(find.text('Free'), findsOneWidget);
|
|
expect(find.text('All 24'), findsOneWidget);
|
|
expect(
|
|
find.byKey(const Key('home-drama-locked-style-drama')),
|
|
findsNothing,
|
|
);
|
|
expect(find.byKey(const Key('home-drama-add-style-drama')), findsNothing);
|
|
|
|
// 播放次数角标落在封面内,并按万位格式化。
|
|
final views = find.byKey(const Key('home-drama-views-style-drama'));
|
|
expect(
|
|
find.descendant(
|
|
of: find.byKey(const Key('home-drama-cover-style-drama')),
|
|
matching: views,
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
expect(
|
|
find.descendant(of: views, matching: find.text('1.2万')),
|
|
findsOneWidget,
|
|
);
|
|
|
|
// 压缩后卡片高度接近「卡宽 × 1.5」,明显矮于旧版 3:4 封面。
|
|
final cardSize = tester.getSize(card);
|
|
expect(cardSize.height, lessThan(cardSize.width * 1.6));
|
|
final coverSize = tester.getSize(
|
|
find.byKey(const Key('home-drama-cover-style-drama')),
|
|
);
|
|
expect(coverSize.height / coverSize.width, closeTo(6 / 5, 0.02));
|
|
});
|
|
}
|
|
|
|
const _drama = Drama(
|
|
id: 'style-drama',
|
|
title: 'Warm Orange Story',
|
|
synopsis: '暖橙短剧',
|
|
posterUrl: '/files/style.jpg',
|
|
genre: 'Romance',
|
|
totalEpisodes: 24,
|
|
freeEpisodes: 6,
|
|
viewCount: 12400,
|
|
);
|