import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:userfront/core/theme/theme_controller.dart';

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();

  setUp(() async {
    SharedPreferences.setMockInitialValues({});
    await ThemeController.app.setThemeMode(ThemeMode.light);
  });

  test('저장된 dark 값을 복원한다', () async {
    SharedPreferences.setMockInitialValues({
      ThemeController.appStorageKey: 'dark',
    });

    await ThemeController.app.restore();

    expect(ThemeController.app.value, ThemeMode.dark);
  });

  test('toggle 결과를 저장한다', () async {
    await ThemeController.app.restore();
    await ThemeController.app.toggle();

    final prefs = await SharedPreferences.getInstance();
    expect(ThemeController.app.value, ThemeMode.dark);
    expect(prefs.getString(ThemeController.appStorageKey), 'dark');
  });
}
