41 lines
1.8 KiB
Dart
41 lines
1.8 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:game_test/game/data/item_table.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
test('ItemTable loads items from JSON', () async {
|
|
// We need to ensure the assets are loaded.
|
|
// In a unit test, rootBundle might not point to the real assets folder easily without setup.
|
|
// However, we can verify that the code *attempts* to load and parses correctly if we mock the bundle,
|
|
// OR we can try to run it and see if it finds the file.
|
|
|
|
// For this environment, let's try to run it. If it fails to find asset, we might need to mock.
|
|
// But since we want to verify the JSON content validity, mocking the *content* with the *actual file content* is a good middle ground if direct loading fails.
|
|
|
|
// Let's try direct load first.
|
|
try {
|
|
await ItemTable.load();
|
|
|
|
expect(ItemTable.weapons.isNotEmpty, true, reason: "Weapons should be loaded");
|
|
expect(ItemTable.armors.isNotEmpty, true, reason: "Armors should be loaded");
|
|
expect(ItemTable.shields.isNotEmpty, true, reason: "Shields should be loaded");
|
|
expect(ItemTable.accessories.isNotEmpty, true, reason: "Accessories should be loaded");
|
|
|
|
print("Loaded ${ItemTable.weapons.length} weapons");
|
|
print("Loaded ${ItemTable.armors.length} armors");
|
|
print("Loaded ${ItemTable.shields.length} shields");
|
|
print("Loaded ${ItemTable.accessories.length} accessories");
|
|
|
|
} catch (e) {
|
|
// If asset loading fails (common in raw flutter_test without integration test setup),
|
|
// we can't easily fix the environment here, but we can verify the JSON parsing logic
|
|
// by mocking the channel if we really wanted to.
|
|
// But for now, let's see if it works.
|
|
print("Error loading items: $e");
|
|
rethrow;
|
|
}
|
|
});
|
|
}
|