115 lines
4.0 KiB
Dart
115 lines
4.0 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:fruitshorts/core/data/models/drama.dart';
|
|
import 'package:fruitshorts/core/data/models/home_feed.dart';
|
|
import 'package:fruitshorts/core/data/repositories/catalog_repository.dart';
|
|
import 'package:fruitshorts/core/data/services/catalog_controller.dart';
|
|
import 'package:fruitshorts/core/theme/app_colors.dart';
|
|
import 'package:fruitshorts/l10n/app_localizations.dart';
|
|
import 'package:fruitshorts/pages/home/home_view.dart';
|
|
import 'package:fruitshorts/pages/splash/splash_page.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
void main() {
|
|
testWidgets('should_keep_splash_with_loading_until_home_feed_settles', (
|
|
tester,
|
|
) async {
|
|
final repository = _PendingCatalog();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
home: ChangeNotifierProvider(
|
|
create: (_) => CatalogController(repository)..load(),
|
|
child: const HomePage(),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(find.byKey(const Key('splash-screen')), findsOneWidget);
|
|
expect(find.byKey(const Key('splash-loading')), findsOneWidget);
|
|
expect(find.byKey(const Key('home-empty')), findsNothing);
|
|
final clip = tester.widget<ClipRRect>(find.byType(ClipRRect));
|
|
expect(clip.borderRadius, BorderRadius.circular(24));
|
|
|
|
repository.pending.complete(const HomeFeed());
|
|
await tester.pump();
|
|
await tester.pump();
|
|
|
|
expect(find.byKey(const Key('splash-screen')), findsNothing);
|
|
expect(find.byKey(const Key('home-empty')), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('should_animate_brand_copy_and_loading_to_full_opacity', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(const MaterialApp(home: SplashPage()));
|
|
|
|
expect(find.byKey(const Key('splash-screen')), findsOneWidget);
|
|
expect(find.byKey(const Key('splash-brand')), findsOneWidget);
|
|
expect(find.byKey(const Key('splash-tagline')), findsOneWidget);
|
|
expect(find.byKey(const Key('splash-loading')), findsOneWidget);
|
|
final mark = tester.widget<Image>(
|
|
find.byKey(const Key('splash-logo-mark')),
|
|
);
|
|
expect((mark.image as AssetImage).assetName, 'assets/icon/splash_mark.png');
|
|
expect(mark.width, 112);
|
|
expect(mark.height, 112);
|
|
final glow = tester.widget<Container>(
|
|
find.descendant(
|
|
of: find.byKey(const Key('splash-logo-glow')),
|
|
matching: find.byType(Container),
|
|
),
|
|
);
|
|
final glowGradient = (glow.decoration as BoxDecoration).gradient;
|
|
expect(
|
|
(glowGradient as RadialGradient).colors.first,
|
|
const Color(0x33FF7A1A),
|
|
);
|
|
expect(
|
|
tester.widget<ColoredBox>(find.byKey(const Key('splash-screen'))).color,
|
|
AppColors.ink,
|
|
);
|
|
expect(
|
|
tester.widget<Text>(find.byKey(const Key('splash-brand'))).style?.color,
|
|
AppColors.onSurface,
|
|
);
|
|
expect(
|
|
tester.widget<Text>(find.byKey(const Key('splash-tagline'))).style?.color,
|
|
AppColors.muted,
|
|
);
|
|
final overlay = tester.widget<AnnotatedRegion<SystemUiOverlayStyle>>(
|
|
find.byType(AnnotatedRegion<SystemUiOverlayStyle>).first,
|
|
);
|
|
expect(overlay.value.statusBarIconBrightness, Brightness.dark);
|
|
|
|
await tester.pump(const Duration(milliseconds: 1200));
|
|
|
|
double opacity(String key) =>
|
|
tester.widget<FadeTransition>(find.byKey(Key(key))).opacity.value;
|
|
expect(opacity('splash-logo-fade'), 1);
|
|
expect(opacity('splash-brand-fade'), 1);
|
|
expect(opacity('splash-tagline-fade'), 1);
|
|
expect(opacity('splash-loading-fade'), 1);
|
|
});
|
|
}
|
|
|
|
class _PendingCatalog implements CatalogRepository {
|
|
final Completer<HomeFeed> pending = Completer<HomeFeed>();
|
|
|
|
@override
|
|
Future<HomeFeed> fetchHomeFeed() => pending.future;
|
|
|
|
@override
|
|
Future<HomeFeed> fetchDiscoverFeed() => pending.future;
|
|
|
|
@override
|
|
Future<Drama> fetchDrama(String dramaId) =>
|
|
Future<Drama>.error(StateError('unused'));
|
|
}
|