Files
cat-haven/test/integration/game_flow_spec.lua
T
2026-07-23 21:23:01 +00:00

190 lines
5.2 KiB
Lua

local test_helper = require('test.test_helper')
local mocks = test_helper.mocks
describe('Integration: Game Flow', function()
local core, cat, house, ui, voxel, audio, json
setup(function()
mocks.setupFilesystem()
core = require('src.core')
cat = require('src.cat.init')
house = require('src.house.init')
ui = require('src.ui.init')
voxel = require('src.voxel.init')
audio = require('src.audio.init')
json = require('src.json')
end)
it('should initialize full game', function()
core.init()
assert.are.equal(2, #core.state.cats)
assert.are.equal(0, #core.state.furniture)
end)
it('should add furniture and render', function()
core.init()
local furn = core.addFurniture('bed', { x = 0, y = 0, z = 0 })
assert.are_not.equal(nil, furn)
local pass = test_helper.utils.createMockPass()
voxel.renderFurniture(pass)
end)
it('should update cats and render', function()
core.init()
cat.updateCats(0.1)
local pass = test_helper.utils.createMockPass()
voxel.renderCats(pass)
end)
it('should render complete UI', function()
core.init()
local pass = test_helper.utils.createMockPass()
ui.renderHUD(pass)
end)
it('should save and load game state', function()
core.init()
-- Add some furniture
core.addFurniture('bed', { x = 0, y = 0, z = 0 })
core.addFurniture('cat_tree', { x = 1, y = 0, z = 1 })
-- Spawn more cats
core.spawnCat()
core.spawnCat()
-- Save
local saveResult = core.saveGame()
assert.is_true(saveResult)
-- Load
local loadResult = core.loadGame()
assert.is_true(loadResult)
-- Verify state
assert.are.equal(4, #core.state.cats)
assert.are.equal(2, #core.state.furniture)
end)
it('should handle cat interaction with furniture', function()
core.init()
local furn = core.addFurniture('bed', { x = 0, y = 0, z = 0 })
local catObj = core.state.cats[1]
-- Move cat near furniture
catObj.position = { x = 0.1, y = 0, z = 0.1 }
-- AI should seek furniture
catObj:aiBehavior()
-- Should have target position
assert.are_not.equal(nil, catObj.targetPosition)
end)
it('should handle cat personality compatibility', function()
core.init()
local c1 = core.state.cats[1]
local c2 = utils.createMockCat({
personality = { id = 'social', compatibility = { ['social'] = 0.5 } }
})
c2.position = { x = 0.5, y = 0, z = 0 }
table.insert(core.state.cats, c2)
c1:updateNeeds()
assert.is_true(c1.needs.social >= 0.7)
end)
it('should handle furniture upgrades', function()
core.init()
local furn = core.addFurniture('bed', { x = 0, y = 0, z = 0 })
local originalContribution = furn.happinessContribution
furn:upgrade()
assert.are.equal(2, furn.upgradeLevel)
assert.is_true(furn.happinessContribution > originalContribution)
furn:upgrade()
assert.are.equal(3, furn.upgradeLevel)
local result = furn:upgrade()
assert.is_false(result)
end)
it('should render audio on pet', function()
local catObj = utils.createMockCat()
local result = catObj:pet()
assert.is_true(result)
end)
it('should handle UI interaction', function()
core.init()
ui.showInventory = true
-- Simulate clicking inventory item
local scale = 0.72
local startX = 640 - 300 * scale + 20 * scale
local startY = 360 - 200 * scale + 80 * scale
local itemY = startY + (1 - 1) * 50 * scale
ui.handleMousePress(startX + 10, itemY + 10, 1)
assert.are_not.equal(nil, ui.selectedFurniture)
end)
it('should handle empty cat list', function()
core.state.cats = {}
core.calculateHouseHappiness()
assert.are.equal(0, core.state.house.totalHappiness)
end)
it('should handle empty furniture list', function()
core.state.furniture = {}
local pass = test_helper.utils.createMockPass()
voxel.renderFurniture(pass)
end)
it('should handle nil core in modules', function()
_G.core = nil
cat.updateCats(0.1)
house.checkCollision({ 0, 0, 0 }, { 1, 1, 1 })
ui.renderHUD(test_helper.utils.createMockPass())
end)
it('should handle nil core in house functions', function()
_G.core = nil
local furn = house.createFurniture(nil, { x = 0, y = 0, z = 0 })
assert.are.equal(nil, furn)
local canPlace, reason = house.canPlaceFurniture({ 0, 0, 0 }, { 1, 1, 1 })
assert.is_false(canPlace)
end)
it('should handle nil core in ui functions', function()
_G.core = nil
ui.renderHUD(test_helper.utils.createMockPass())
ui.renderInventory(test_helper.utils.createMockPass(), 1280, 720, 0.72)
ui.renderCatLog(test_helper.utils.createMockPass(), 1280, 0.72)
end)
it('should handle nil core in voxel functions', function()
_G.core = nil
voxel.renderWorld(test_helper.utils.createMockPass())
voxel.renderFurniture(test_helper.utils.createMockPass())
voxel.renderCats(test_helper.utils.createMockPass())
end)
it('should handle nil core in audio functions', function()
_G.core = nil
audio.playPurr({ 0, 0, 0 })
audio.playMeow({ 0, 0, 0 })
audio.playClick()
end)
end)