import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:minstrel/admin/admin_landing_screen.dart';
import 'package:minstrel/admin/admin_providers.dart';
import 'package:minstrel/auth/auth_provider.dart';
import 'package:minstrel/models/user.dart';
import 'package:minstrel/theme/theme_data.dart';

class _StubAuth extends AuthController {
  @override
  Future<User?> build() async =>
      const User(id: 'u1', username: 'admin', isAdmin: true);
}

void main() {
  testWidgets('renders three section cards with counts from provider',
      (t) async {
    await t.pumpWidget(
      ProviderScope(
        overrides: [
          authControllerProvider.overrideWith(() => _StubAuth()),
          adminCountsProvider.overrideWith(
            (_) async => const AdminCounts(
              requests: 3,
              quarantine: 1,
              users: 5,
            ),
          ),
        ],
        child: MaterialApp(
          theme: buildThemeData(),
          home: const AdminLandingScreen(),
        ),
      ),
    );
    await t.pumpAndSettle();
    expect(find.byKey(const Key('admin_card_requests')), findsOneWidget);
    expect(find.byKey(const Key('admin_card_quarantine')), findsOneWidget);
    expect(find.byKey(const Key('admin_card_users')), findsOneWidget);
    expect(find.text('3'), findsOneWidget);
    expect(find.text('1'), findsOneWidget);
    expect(find.text('5'), findsOneWidget);
  });
}
