test: update admin aliases panel tests for product model changes
Test Suite / backend-pr-quick (push) Has been skipped
Test Suite / quick-import-pr-quick (push) Has been skipped
Test Suite / backend-full (push) Successful in 2m28s
Test Suite / flutter-quality (push) Successful in 2m21s

- Add imports for new domain models
- Update AdminProduct initialization to include canonicalName
- Update ReceiptAlias initialization to include ownerId and productName
- Replace Switch widget checks with SwitchListTile for global alias test
- Update test data to match new model structure
This commit is contained in:
Nils-Johan Gynther
2026-05-18 18:48:26 +02:00
parent f42132ed5b
commit a31aff7c35
+37 -20
View File
@@ -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<Switch>(switchFinder);
expect(switchWidget.value, isTrue);
expect(switchWidget.onChanged, isNull); // Disabled
final switchListTileFinder = find.byType(SwitchListTile);
expect(switchListTileFinder, findsOneWidget);
final switchTile = tester.widget<SwitchListTile>(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<Switch>(switchFinder);
expect(switchWidget.value, isFalse);
expect(switchWidget.onChanged, isNotNull); // Enabled
final switchListTileFinder = find.byType(SwitchListTile);
expect(switchListTileFinder, findsOneWidget);
final switchTile = tester.widget<SwitchListTile>(switchListTileFinder);
expect(switchTile.value, isFalse);
expect(switchTile.onChanged, isNotNull); // Enabled
// Verify subtitle text
expect(find.text('Du kan göra privata alias globala.'), findsOneWidget);
});
});
}