diff --git a/index.html b/index.html index 521bbf9..f735746 100644 --- a/index.html +++ b/index.html @@ -71,6 +71,7 @@ + diff --git a/src/utils/IntegrationTests.js b/src/utils/IntegrationTests.js new file mode 100644 index 0000000..fae9349 --- /dev/null +++ b/src/utils/IntegrationTests.js @@ -0,0 +1,252 @@ +/** + * 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()');