import 'package:afterwork/data/services/category_service.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/services.dart';

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();

  group('CategoryService Integration Tests', () {
    late CategoryService categoryService;

    setUp(() {
      categoryService = CategoryService();
    });

    test('should load categories from actual JSON file', () async {
      // Arrange & Act
      // This test loads the actual JSON file from assets
      final result = await categoryService.loadCategories();

      // Assert
      expect(result, isA<Map<String, List<String>>>());
      expect(result.isNotEmpty, isTrue);
      
      // Verify that the result contains category types
      // The exact structure depends on the actual JSON file
      for (final categoryType in result.keys) {
        expect(categoryType, isA<String>());
        expect(result[categoryType], isA<List<String>>());
        expect(result[categoryType]!.isNotEmpty, isTrue);
      }
    });

    test('should return valid category structure', () async {
      // Arrange & Act
      final result = await categoryService.loadCategories();

      // Assert
      expect(result, isA<Map<String, List<String>>>());
      
      // Verify that each category type has a non-empty list of categories
      result.forEach((key, value) {
        expect(key.isNotEmpty, isTrue);
        expect(value, isNotEmpty);
        expect(value.every((category) => category.isNotEmpty), isTrue);
      });
    });

    test('should handle loading categories multiple times', () async {
      // Arrange & Act
      final result1 = await categoryService.loadCategories();
      final result2 = await categoryService.loadCategories();

      // Assert
      expect(result1, equals(result2));
      expect(result1.length, equals(result2.length));
    });
  });
}

