118 lines
4.1 KiB
Dart
118 lines
4.1 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:fruitshorts/core/data/remote/api_client.dart';
|
|
import 'package:fruitshorts/core/data/remote/auth_api.dart';
|
|
import 'package:fruitshorts/core/data/services/auth_controller.dart';
|
|
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
|
|
import 'package:fruitshorts/core/theme/app_colors.dart';
|
|
import 'package:fruitshorts/core/theme/app_theme.dart';
|
|
import 'package:fruitshorts/l10n/app_localizations.dart';
|
|
import 'package:fruitshorts/pages/watch_records/watch_records_page.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
|
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
|
|
|
import '../support/fake_http_adapter.dart';
|
|
|
|
void main() {
|
|
setUp(() {
|
|
SharedPreferencesAsyncPlatform.instance =
|
|
InMemorySharedPreferencesAsync.empty();
|
|
});
|
|
|
|
testWidgets('should_render_material_app_with_dark_default_theme', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: AppTheme.dark(),
|
|
darkTheme: AppTheme.dark(),
|
|
themeMode: ThemeMode.dark,
|
|
locale: const Locale('en'),
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
home: Scaffold(
|
|
key: const Key('dark-smoke-scaffold'),
|
|
appBar: AppBar(title: const Text('Dark')),
|
|
body: Card(
|
|
key: const Key('dark-smoke-card'),
|
|
child: ListTile(
|
|
title: Text(
|
|
'Primary',
|
|
style: TextStyle(color: AppColors.onSurface),
|
|
),
|
|
subtitle: Text('Muted', style: TextStyle(color: AppColors.muted)),
|
|
trailing: Text('128', style: TextStyle(color: AppColors.gold)),
|
|
),
|
|
),
|
|
bottomNavigationBar: NavigationBar(
|
|
selectedIndex: 0,
|
|
destinations: const [
|
|
NavigationDestination(icon: Icon(Icons.home), label: 'Home'),
|
|
NavigationDestination(icon: Icon(Icons.person), label: 'Mine'),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
final context = tester.element(
|
|
find.byKey(const Key('dark-smoke-scaffold')),
|
|
);
|
|
final theme = Theme.of(context);
|
|
expect(theme.brightness, Brightness.dark);
|
|
expect(theme.scaffoldBackgroundColor, AppColors.ink);
|
|
expect(theme.appBarTheme.backgroundColor, AppColors.card);
|
|
expect(theme.cardTheme.color, AppColors.card);
|
|
|
|
final card = tester.widget<Card>(find.byKey(const Key('dark-smoke-card')));
|
|
expect(card.color ?? theme.cardTheme.color, AppColors.card);
|
|
expect(find.text('Primary'), findsOneWidget);
|
|
expect(find.text('Muted'), findsOneWidget);
|
|
expect(find.text('128'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('should_render_watch_records_page_on_dark_surface', (
|
|
tester,
|
|
) async {
|
|
final auth = AuthController(
|
|
AuthApi(
|
|
ApiClient(
|
|
baseUrl: 'http://127.0.0.1:1',
|
|
adapter: FakeHttpAdapter(
|
|
(_) async =>
|
|
FakeHttpResponse('{"code":0,"message":"ok","data":null}'),
|
|
),
|
|
),
|
|
),
|
|
AuthSessionStore(),
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
ChangeNotifierProvider<AuthController>.value(
|
|
value: auth,
|
|
child: MaterialApp(
|
|
theme: AppTheme.dark(),
|
|
darkTheme: AppTheme.dark(),
|
|
themeMode: ThemeMode.dark,
|
|
locale: const Locale('en'),
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
home: const WatchRecordsPage(),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
final scaffold = tester.widget<Scaffold>(
|
|
find.byKey(const Key('watch-records-page')),
|
|
);
|
|
expect(scaffold.backgroundColor, AppColors.ink);
|
|
expect(find.byKey(const Key('auth-gate-panel')), findsOneWidget);
|
|
expect(find.byType(Scaffold), findsOneWidget);
|
|
});
|
|
}
|