2026-06-21 03:18:00 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
2026-06-23 09:51:10 +08:00
|
|
|
import 'package:badnote/l10n/app_localizations.dart';
|
2026-06-21 03:18:00 +08:00
|
|
|
import 'package:badnote/screens/home_screen.dart';
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
testWidgets('Home screen renders its app bar title', (
|
|
|
|
|
WidgetTester tester,
|
|
|
|
|
) async {
|
|
|
|
|
// The note list is backed by the on-device database, which is not
|
|
|
|
|
// available in the widget-test environment; the body therefore shows a
|
|
|
|
|
// loading/error state. The app-bar chrome renders regardless, so we assert
|
|
|
|
|
// on that. The home screen must be wrapped in a ProviderScope, which the
|
|
|
|
|
// app's real entrypoint (main.dart) provides.
|
|
|
|
|
SharedPreferences.setMockInitialValues({});
|
|
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
2026-06-23 09:51:10 +08:00
|
|
|
ProviderScope(
|
|
|
|
|
child: MaterialApp(
|
|
|
|
|
// The screen is now localized; provide the delegates it depends on.
|
|
|
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
|
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
|
|
|
home: const HomeScreen(),
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-06-21 03:18:00 +08:00
|
|
|
);
|
|
|
|
|
await tester.pump();
|
|
|
|
|
|
|
|
|
|
expect(find.text('BadNote'), findsOneWidget);
|
|
|
|
|
expect(find.byTooltip('Search'), findsOneWidget);
|
|
|
|
|
});
|
|
|
|
|
}
|