import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tane/bootstrap.dart';
import 'package:tane/i18n/strings.g.dart';

void main() {
  setUp(() => LocaleSettings.setLocaleSync(AppLocale.en));

  testWidgets('shows a spinner and no error while booting', (tester) async {
    await tester.pumpWidget(
      TranslationProvider(child: const BootstrapSplash(error: false)),
    );

    expect(find.byType(CircularProgressIndicator), findsOneWidget);
    expect(find.text(t.bootstrap.failed), findsNothing);
    expect(find.text(t.bootstrap.retry), findsNothing);
  });

  testWidgets('on error shows the message and a working retry', (tester) async {
    var retries = 0;
    await tester.pumpWidget(
      TranslationProvider(
        child: BootstrapSplash(error: true, onRetry: () => retries++),
      ),
    );

    expect(find.byType(CircularProgressIndicator), findsNothing);
    expect(find.text(t.bootstrap.failed), findsOneWidget);

    await tester.tap(find.text(t.bootstrap.retry));
    expect(retries, 1);
  });
}
