import 'package:flutter_test/flutter_test.dart';
import 'package:recipe_flutter/features/inventory/domain/inventory_item.dart';

void main() {
  group('InventoryItem.l1Category', () {
    test('uses first category level from category path', () {
      final item = InventoryItem.fromJson({
        'id': 1,
        'productId': 10,
        'quantity': 1,
        'unit': 'st',
        'product': {
          'name': 'Tomat',
          'categoryRef': {
            'name': 'Tomater',
            'parent': {
              'name': 'Grönsaker',
              'parent': {'name': 'Mat'},
            },
          },
        },
      });

      expect(item.categoryPath, 'Mat > Grönsaker > Tomater');
      expect(item.l1Category, 'Mat');
    });

    test('falls back to Övrigt when category path is missing', () {
      final item = InventoryItem.fromJson({
        'id': 1,
        'productId': 10,
        'quantity': 1,
        'unit': 'st',
        'product': {'name': 'Okänd', 'categoryRef': null},
      });

      expect(item.categoryPath, isNull);
      expect(item.l1Category, 'Övrigt');
    });
  });
}
