Files
novafarma/old_logic/src_backup_1768938138/utils/IntegrationTests.js
2026-01-21 01:08:21 +01:00

253 lines
8.1 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* INTEGRATION TEST SUITE
* Automated tests to verify all systems work together
* Run with: IntegrationTests.runAll()
*/
class IntegrationTests {
constructor(scene) {
this.scene = scene;
this.results = [];
this.passCount = 0;
this.failCount = 0;
}
/**
* Run all integration tests
*/
runAll() {
console.log('🧪 Starting Integration Tests...');
this.results = [];
this.passCount = 0;
this.failCount = 0;
// System existence tests
this.testSystemsExist();
// Cross-system integration tests
this.testInventorySystem();
this.testMountSystem();
this.testPerennialCrops();
this.testGemDropSystem();
this.testCraftingRecipes();
this.testPlaytimeTracker();
this.testSaveSystem();
// Performance tests
this.testPerformance();
// Output results
this.printResults();
}
/**
* Test helper
*/
test(name, condition, errorMsg = '') {
const passed = condition;
this.results.push({ name, passed, errorMsg });
if (passed) {
this.passCount++;
console.log(`${name}`);
} else {
this.failCount++;
console.error(`${name}${errorMsg ? ': ' + errorMsg : ''}`);
}
return passed;
}
/**
* TEST SUITE: Systems Existence
*/
testSystemsExist() {
console.log('\n🔍 Testing System Existence...');
this.test('TerrainSystem exists', !!this.scene.terrainSystem);
this.test('InventorySystem exists', !!this.scene.inventorySystem);
this.test('LootSystem exists', !!this.scene.lootSystem);
this.test('WeatherSystem exists', !!this.scene.weatherSystem);
this.test('Player exists', !!this.scene.player);
// Check Antigravity namespace
this.test('Antigravity namespace exists', !!window.Antigravity);
this.test('Antigravity.Systems exists', !!window.Antigravity.Systems);
}
/**
* TEST SUITE: Inventory System
*/
testInventorySystem() {
console.log('\n🎒 Testing Inventory System...');
const inv = this.scene.inventorySystem;
if (!inv) {
this.test('Inventory System Integration', false, 'InventorySystem not found');
return;
}
// Test add/remove items
const initialCount = inv.getItemCount('wheat_seed') || 0;
inv.addItem('wheat_seed', 10);
const afterAdd = inv.getItemCount('wheat_seed');
this.test('Inventory add item', afterAdd === initialCount + 10);
inv.removeItem('wheat_seed', 5);
const afterRemove = inv.getItemCount('wheat_seed');
this.test('Inventory remove item', afterRemove === initialCount + 5);
// Cleanup
inv.removeItem('wheat_seed', 5);
}
/**
* TEST SUITE: Mount System
*/
testMountSystem() {
console.log('\n🫏 Testing Mount System...');
// Check if MountSystem class exists
this.test('MountSystem class exists', typeof MountSystem !== 'undefined');
// Check mount data
if (typeof MountSystem !== 'undefined') {
const tempMount = new MountSystem(this.scene, this.scene.player);
this.test('Donkey mount data exists', !!tempMount.mountData['donkey']);
this.test('Horse mount data exists', !!tempMount.mountData['horse']);
}
}
/**
* TEST SUITE: Perennial Crops
*/
testPerennialCrops() {
console.log('\n🍎 Testing Perennial Crops System...');
this.test('PerennialCropSystem class exists', typeof PerennialCropSystem !== 'undefined');
if (typeof PerennialCropSystem !== 'undefined') {
const tempSystem = new PerennialCropSystem(this.scene);
this.test('Apple tree data exists', !!tempSystem.perennialData['apple_tree']);
}
}
/**
* TEST SUITE: Gem Drop System
*/
testGemDropSystem() {
console.log('\n💎 Testing Gem Drop System...');
this.test('GemDropSystem class exists', typeof GemDropSystem !== 'undefined');
if (typeof GemDropSystem !== 'undefined') {
const tempSystem = new GemDropSystem(this.scene);
this.test('Diamond gem data exists', !!tempSystem.gems['diamond']);
this.test('Emerald gem data exists', !!tempSystem.gems['emerald']);
this.test('Ruby gem data exists', !!tempSystem.gems['ruby']);
this.test('Sapphire gem data exists', !!tempSystem.gems['sapphire']);
}
}
/**
* TEST SUITE: Crafting Recipes
*/
testCraftingRecipes() {
console.log('\n🔨 Testing Crafting Recipes...');
this.test('CRAFTING_RECIPES exists', typeof CRAFTING_RECIPES !== 'undefined');
if (typeof CRAFTING_RECIPES !== 'undefined') {
this.test('Bone pickaxe recipe exists', !!CRAFTING_RECIPES['bone_pickaxe']);
this.test('Bone axe recipe exists', !!CRAFTING_RECIPES['bone_axe']);
this.test('Bone hoe recipe exists', !!CRAFTING_RECIPES['bone_hoe']);
this.test('Bone sword recipe exists', !!CRAFTING_RECIPES['bone_sword']);
}
}
/**
* TEST SUITE: Playtime Tracker
*/
testPlaytimeTracker() {
console.log('\n⏱ Testing Playtime Tracker...');
this.test('PlaytimeTrackerSystem class exists', typeof PlaytimeTrackerSystem !== 'undefined');
if (typeof PlaytimeTrackerSystem !== 'undefined') {
const tempTracker = new PlaytimeTrackerSystem(this.scene);
this.test('Tracker has stats object', !!tempTracker.stats);
this.test('Tracker has playtimeSeconds', typeof tempTracker.stats.playtimeSeconds === 'number');
}
}
/**
* TEST SUITE: Save System
*/
testSaveSystem() {
console.log('\n💾 Testing Save System...');
this.test('SaveSystem class exists', typeof SaveSystem !== 'undefined');
this.test('localStorage available', typeof localStorage !== 'undefined');
}
/**
* TEST SUITE: Performance
*/
testPerformance() {
console.log('\n📊 Testing Performance...');
// Check if game is running at acceptable FPS
if (this.scene.game && this.scene.game.loop) {
const fps = this.scene.game.loop.actualFps;
this.test('FPS above 30', fps > 30, `Current FPS: ${fps.toFixed(1)}`);
this.test('FPS above 50 (good)', fps > 50, `Current FPS: ${fps.toFixed(1)}`);
}
// Check sprite count (should not be too high)
if (this.scene.children) {
const spriteCount = this.scene.children.list.length;
this.test('Sprite count reasonable (<10000)', spriteCount < 10000, `Count: ${spriteCount}`);
}
}
/**
* Print test results summary
*/
printResults() {
console.log('\n' + '='.repeat(50));
console.log('🧪 INTEGRATION TEST RESULTS');
console.log('='.repeat(50));
console.log(`✅ PASSED: ${this.passCount}`);
console.log(`❌ FAILED: ${this.failCount}`);
console.log(`📊 TOTAL: ${this.results.length}`);
console.log(`📈 SUCCESS RATE: ${((this.passCount / this.results.length) * 100).toFixed(1)}%`);
console.log('='.repeat(50));
if (this.failCount === 0) {
console.log('🎉 All tests passed! Systems are integrated correctly!');
} else {
console.log('⚠️ Some tests failed. Check errors above.');
}
return {
passed: this.passCount,
failed: this.failCount,
total: this.results.length,
successRate: (this.passCount / this.results.length) * 100,
results: this.results
};
}
}
// Make available globally
window.IntegrationTests = IntegrationTests;
// Convenience function
window.runTests = function () {
const scene = game.scene.scenes[0]; // Get GameScene
const tests = new IntegrationTests(scene);
return tests.runAll();
};
console.log('🧪 Integration Tests loaded. Run with: runTests()');