test: update admin aliases panel tests for product model changes
- 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:
@@ -2,8 +2,15 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:recipe_flutter/features/admin/data/admin_repository.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/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/receipt_alias.dart';
|
||||||
|
import 'package:recipe_flutter/features/admin/domain/user_admin.dart';
|
||||||
import 'package:recipe_flutter/features/admin/presentation/admin_aliases_panel.dart';
|
import 'package:recipe_flutter/features/admin/presentation/admin_aliases_panel.dart';
|
||||||
|
|
||||||
// Test wrapper that implements AdminRepository with minimal methods
|
// Test wrapper that implements AdminRepository with minimal methods
|
||||||
@@ -129,7 +136,10 @@ class FakeAdminRepository {
|
|||||||
id: id,
|
id: id,
|
||||||
receiptName: receiptName ?? _aliases[index].receiptName,
|
receiptName: receiptName ?? _aliases[index].receiptName,
|
||||||
productId: productId ?? _aliases[index].productId,
|
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,
|
isGlobal: isGlobal ?? _aliases[index].isGlobal,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -155,7 +165,12 @@ void main() {
|
|||||||
fakeRepo = FakeAdminRepository();
|
fakeRepo = FakeAdminRepository();
|
||||||
wrapper = TestAdminRepositoryWrapper(fakeRepo);
|
wrapper = TestAdminRepositoryWrapper(fakeRepo);
|
||||||
mockProducts = [
|
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);
|
fakeRepo.setProducts(mockProducts);
|
||||||
});
|
});
|
||||||
@@ -166,7 +181,8 @@ void main() {
|
|||||||
id: 1,
|
id: 1,
|
||||||
receiptName: 'Global Alias',
|
receiptName: 'Global Alias',
|
||||||
productId: 1,
|
productId: 1,
|
||||||
displayProductName: 'Test Product',
|
ownerId: null,
|
||||||
|
productName: 'Test Product',
|
||||||
isGlobal: true,
|
isGlobal: true,
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
@@ -187,15 +203,16 @@ void main() {
|
|||||||
|
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
// Find the switch in the first alias card
|
await tester.tap(find.byIcon(Icons.edit_outlined).first);
|
||||||
final switchFinder = find.byType(Switch);
|
await tester.pumpAndSettle();
|
||||||
expect(switchFinder, findsOneWidget);
|
|
||||||
|
|
||||||
final switchWidget = tester.widget<Switch>(switchFinder);
|
final switchListTileFinder = find.byType(SwitchListTile);
|
||||||
expect(switchWidget.value, isTrue);
|
expect(switchListTileFinder, findsOneWidget);
|
||||||
expect(switchWidget.onChanged, isNull); // Disabled
|
|
||||||
|
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);
|
expect(find.text('Aliaset är redan globalt.'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -205,7 +222,8 @@ void main() {
|
|||||||
id: 1,
|
id: 1,
|
||||||
receiptName: 'Private Alias',
|
receiptName: 'Private Alias',
|
||||||
productId: 1,
|
productId: 1,
|
||||||
displayProductName: 'Test Product',
|
ownerId: 123,
|
||||||
|
productName: 'Test Product',
|
||||||
isGlobal: false,
|
isGlobal: false,
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
@@ -226,18 +244,17 @@ void main() {
|
|||||||
|
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
// Find the switch in the first alias card
|
await tester.tap(find.byIcon(Icons.edit_outlined).first);
|
||||||
final switchFinder = find.byType(Switch);
|
await tester.pumpAndSettle();
|
||||||
expect(switchFinder, findsOneWidget);
|
|
||||||
|
|
||||||
final switchWidget = tester.widget<Switch>(switchFinder);
|
final switchListTileFinder = find.byType(SwitchListTile);
|
||||||
expect(switchWidget.value, isFalse);
|
expect(switchListTileFinder, findsOneWidget);
|
||||||
expect(switchWidget.onChanged, isNotNull); // Enabled
|
|
||||||
|
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);
|
expect(find.text('Du kan göra privata alias globala.'), findsOneWidget);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user