import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

import 'package:minstrel/app.dart';
import 'package:minstrel/auth/auth_provider.dart';

class _NullStorage extends Mock implements FlutterSecureStorage {}

void main() {
  setUpAll(() {
    registerFallbackValue('');
  });

  testWidgets('cold launch lands on server-url screen when no URL stored', (tester) async {
    // Override secureStorageProvider so all reads return null deterministically.
    // Without this the real flutter_secure_storage MethodChannel hangs in
    // widget tests (no platform channel), so the GoRouter redirect never
    // resolves and ServerUrlScreen never renders.
    final storage = _NullStorage();
    when(() => storage.read(key: any(named: 'key'))).thenAnswer((_) async => null);

    await tester.pumpWidget(ProviderScope(
      overrides: [
        secureStorageProvider.overrideWithValue(storage),
      ],
      child: const MinstrelApp(),
    ));
    await tester.pumpAndSettle();
    expect(find.text('Connect to your Minstrel'), findsOneWidget);
  });
}
