diff --git a/flutter/test/admin_aliases_panel_test.dart b/flutter/test/admin_aliases_panel_test.dart index 6be53a0f..89ebfb15 100644 --- a/flutter/test/admin_aliases_panel_test.dart +++ b/flutter/test/admin_aliases_panel_test.dart @@ -2,8 +2,15 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:recipe_flutter/features/admin/data/admin_repository.dart'; +import 'package:recipe_flutter/features/admin/domain/admin_ai_categorize_result.dart'; +import 'package:recipe_flutter/features/admin/domain/admin_category_node.dart'; +import 'package:recipe_flutter/features/admin/domain/admin_inventory_item.dart'; +import 'package:recipe_flutter/features/admin/domain/admin_pantry_item.dart'; import 'package:recipe_flutter/features/admin/domain/admin_product.dart'; +import 'package:recipe_flutter/features/admin/domain/ai_model_info.dart'; +import 'package:recipe_flutter/features/admin/domain/pending_product.dart'; import 'package:recipe_flutter/features/admin/domain/receipt_alias.dart'; +import 'package:recipe_flutter/features/admin/domain/user_admin.dart'; import 'package:recipe_flutter/features/admin/presentation/admin_aliases_panel.dart'; // Test wrapper that implements AdminRepository with minimal methods @@ -129,7 +136,10 @@ class FakeAdminRepository { id: id, receiptName: receiptName ?? _aliases[index].receiptName, productId: productId ?? _aliases[index].productId, - displayProductName: _products.firstWhere((p) => p.id == (productId ?? _aliases[index].productId)).displayName, + ownerId: _aliases[index].ownerId, + productName: _products + .firstWhere((p) => p.id == (productId ?? _aliases[index].productId)) + .displayName, isGlobal: isGlobal ?? _aliases[index].isGlobal, ); } @@ -155,7 +165,12 @@ void main() { fakeRepo = FakeAdminRepository(); wrapper = TestAdminRepositoryWrapper(fakeRepo); mockProducts = [ - AdminProduct(id: 1, name: 'Test Product', displayName: 'Test Product', categoryPath: 'Test > Category'), + AdminProduct( + id: 1, + name: 'Test Product', + canonicalName: 'Test Product', + categoryPath: 'Test > Category', + ), ]; fakeRepo.setProducts(mockProducts); }); @@ -166,7 +181,8 @@ void main() { id: 1, receiptName: 'Global Alias', productId: 1, - displayProductName: 'Test Product', + ownerId: null, + productName: 'Test Product', isGlobal: true, ), ]; @@ -187,15 +203,16 @@ void main() { await tester.pumpAndSettle(); - // Find the switch in the first alias card - final switchFinder = find.byType(Switch); - expect(switchFinder, findsOneWidget); + await tester.tap(find.byIcon(Icons.edit_outlined).first); + await tester.pumpAndSettle(); - final switchWidget = tester.widget(switchFinder); - expect(switchWidget.value, isTrue); - expect(switchWidget.onChanged, isNull); // Disabled + final switchListTileFinder = find.byType(SwitchListTile); + expect(switchListTileFinder, findsOneWidget); + + final switchTile = tester.widget(switchListTileFinder); + expect(switchTile.value, isTrue); + expect(switchTile.onChanged, isNull); // Disabled - // Verify subtitle text expect(find.text('Aliaset är redan globalt.'), findsOneWidget); }); @@ -205,7 +222,8 @@ void main() { id: 1, receiptName: 'Private Alias', productId: 1, - displayProductName: 'Test Product', + ownerId: 123, + productName: 'Test Product', isGlobal: false, ), ]; @@ -226,18 +244,17 @@ void main() { await tester.pumpAndSettle(); - // Find the switch in the first alias card - final switchFinder = find.byType(Switch); - expect(switchFinder, findsOneWidget); + await tester.tap(find.byIcon(Icons.edit_outlined).first); + await tester.pumpAndSettle(); - final switchWidget = tester.widget(switchFinder); - expect(switchWidget.value, isFalse); - expect(switchWidget.onChanged, isNotNull); // Enabled + final switchListTileFinder = find.byType(SwitchListTile); + expect(switchListTileFinder, findsOneWidget); + + final switchTile = tester.widget(switchListTileFinder); + expect(switchTile.value, isFalse); + expect(switchTile.onChanged, isNotNull); // Enabled - // Verify subtitle text expect(find.text('Du kan göra privata alias globala.'), findsOneWidget); }); }); } - -