import 'package:block_seasons/data/save_repository.dart';
import 'package:block_seasons/state/providers.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
  test('exposes saved best and reports new records', () async {
    SharedPreferences.setMockInitialValues({});
    final repo = SaveRepository(await SharedPreferences.getInstance());
    await repo.recordEndlessScore(400);
    final container = ProviderContainer(
      overrides: [saveRepositoryProvider.overrideWithValue(repo)],
    );
    addTearDown(container.dispose);

    expect(container.read(endlessBestProvider), 400);

    final n = container.read(endlessBestProvider.notifier);
    expect(await n.record(300), isFalse);
    expect(container.read(endlessBestProvider), 400);
    expect(await n.record(900), isTrue);
    expect(container.read(endlessBestProvider), 900);
  });
}
