|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { BOILER_MANA_PER_SEC } from '@/config/constants'; |
| 3 | +import { getBlueprint } from './blueprints'; |
| 4 | +import { placeInfra } from './infra'; |
| 5 | +import { resetBoilerRuntime, tickBoilers } from './boilers'; |
| 6 | +import { selectPipeConnectivityReport } from './pipes'; |
| 7 | +import { createInitialState } from './game'; |
| 8 | +import { createRoom, createTower, placeRoom } from './tower'; |
| 9 | + |
| 10 | +function boilerWithPorts() { |
| 11 | + const state = createInitialState('boiler0'); |
| 12 | + state.tower = createTower(); |
| 13 | + // Water column at col 4; boiler 1×2 at (5,0) covering (5,0)–(5,1); steam outlet at (6,1). |
| 14 | + state.tower = placeRoom(state.tower, createRoom('g4', getBlueprint('stem')!, { col: 4, row: 0 })); |
| 15 | + state.tower = placeRoom(state.tower, createRoom('w1', getBlueprint('stem')!, { col: 4, row: 1 })); |
| 16 | + state.tower = placeRoom(state.tower, createRoom('boiler', getBlueprint('boilerRoom')!, { col: 5, row: 0 })); |
| 17 | + state.tower = placeRoom(state.tower, createRoom('s0', getBlueprint('stem')!, { col: 6, row: 0 })); |
| 18 | + state.tower = placeRoom(state.tower, createRoom('s1', getBlueprint('stem')!, { col: 6, row: 1 })); |
| 19 | + state.tower = placeInfra(state.tower, { col: 4, row: 0 }, 'pipe'); |
| 20 | + state.tower = placeInfra(state.tower, { col: 4, row: 1 }, 'pipe'); |
| 21 | + state.tower = placeInfra(state.tower, { col: 6, row: 1 }, 'pipe'); |
| 22 | + state.phase = 'attack'; |
| 23 | + resetBoilerRuntime(state); |
| 24 | + return state; |
| 25 | +} |
| 26 | + |
| 27 | +describe('tickBoilers', () => { |
| 28 | + it('drains mana and marks steam available when both ports are connected', () => { |
| 29 | + const state = boilerWithPorts(); |
| 30 | + const before = state.player.mana; |
| 31 | + tickBoilers(state, 1); |
| 32 | + expect(state.player.mana).toBeCloseTo(before - BOILER_MANA_PER_SEC, 5); |
| 33 | + expect(state.boilerRuntime.boiler?.producing).toBe(true); |
| 34 | + expect(state.boilerRuntime.boiler?.steamAvailable).toBe(true); |
| 35 | + }); |
| 36 | + |
| 37 | + it('stops producing when mana is empty', () => { |
| 38 | + const state = boilerWithPorts(); |
| 39 | + state.player.mana = 0; |
| 40 | + tickBoilers(state, 1); |
| 41 | + expect(state.boilerRuntime.boiler?.producing).toBe(false); |
| 42 | + expect(state.boilerRuntime.boiler?.steamAvailable).toBe(false); |
| 43 | + }); |
| 44 | + |
| 45 | + it('does not produce without a steam outlet', () => { |
| 46 | + const state = createInitialState('boiler-dry'); |
| 47 | + state.tower = createTower(); |
| 48 | + state.tower = placeRoom(state.tower, createRoom('g4', getBlueprint('stem')!, { col: 4, row: 0 })); |
| 49 | + state.tower = placeRoom(state.tower, createRoom('w1', getBlueprint('stem')!, { col: 4, row: 1 })); |
| 50 | + state.tower = placeRoom(state.tower, createRoom('boiler', getBlueprint('boilerRoom')!, { col: 5, row: 0 })); |
| 51 | + state.tower = placeInfra(state.tower, { col: 4, row: 0 }, 'pipe'); |
| 52 | + state.tower = placeInfra(state.tower, { col: 4, row: 1 }, 'pipe'); |
| 53 | + state.phase = 'attack'; |
| 54 | + resetBoilerRuntime(state); |
| 55 | + const before = state.player.mana; |
| 56 | + tickBoilers(state, 1); |
| 57 | + expect(state.player.mana).toBe(before); |
| 58 | + expect(state.boilerRuntime.boiler?.producing).toBe(false); |
| 59 | + }); |
| 60 | +}); |
| 61 | + |
| 62 | +describe('selectPipeConnectivityReport', () => { |
| 63 | + it('warns when a boiler lacks water', () => { |
| 64 | + const state = createInitialState('pipe-warn'); |
| 65 | + state.tower = createTower(); |
| 66 | + state.tower = placeRoom(state.tower, createRoom('g5', getBlueprint('stem')!, { col: 4, row: 0 })); |
| 67 | + state.tower = placeRoom(state.tower, createRoom('boiler', getBlueprint('boilerRoom')!, { col: 5, row: 0 })); |
| 68 | + const report = selectPipeConnectivityReport(state); |
| 69 | + expect(report.boilers.some((b) => b.roomId === 'boiler' && b.warning.includes('water'))).toBe(true); |
| 70 | + }); |
| 71 | +}); |
0 commit comments