refactor: remove GUARDIANS constant, consolidate into guardian-data.ts
- Delete src/lib/game/constants/guardians.ts (the old static GUARDIANS constant) - Create src/lib/game/data/guardian-data.ts with BASE_GUARDIANS (same data, new home) - Remove GUARDIANS export from constants/index.ts - Update all 11 files that imported GUARDIANS to use getGuardianForFloor() or BASE_GUARDIANS: - useGameDerived.ts, combat-actions.ts, gameStore.ts, prestigeStore.ts - combat-utils.ts, room-utils.ts, floor-utils.ts, spire-utils.ts - SpireCombatPage.tsx, SpireHeader.tsx - Update 4 test files to use getGuardianForFloor() instead of GUARDIANS constant - guardian-encounters.ts now imports BASE_GUARDIANS from guardian-data.ts - Split room-utils.test.ts (505 lines) into room-utils.test.ts + room-utils-floor-state.test.ts
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { generateFloorState } from '../utils/room-utils';
|
||||
import { PUZZLE_ROOMS, SWARM_CONFIG, SPEED_ROOM_CONFIG } from '../constants';
|
||||
import { getGuardianForFloor } from '../data/guardian-encounters';
|
||||
import { getFloorMaxHP, getDodgeChance } from '../utils/floor-utils';
|
||||
|
||||
// ─── generateFloorState ───────────────────────────────────────────────────────
|
||||
|
||||
describe('generateFloorState', () => {
|
||||
it('should return a FloorState object', () => {
|
||||
const state = generateFloorState(1);
|
||||
expect(typeof state).toBe('object');
|
||||
expect(state).toHaveProperty('roomType');
|
||||
expect(state).toHaveProperty('enemies');
|
||||
});
|
||||
|
||||
it('should generate guardian state for guardian floor', () => {
|
||||
const state = generateFloorState(10);
|
||||
expect(state.roomType).toBe('guardian');
|
||||
expect(state.enemies.length).toBe(1);
|
||||
const g10 = getGuardianForFloor(10)!;
|
||||
expect(state.enemies[0].name).toBe(g10.name);
|
||||
expect(state.enemies[0].hp).toBe(g10.hp);
|
||||
expect(state.enemies[0].element).toBe(g10.element);
|
||||
});
|
||||
|
||||
it('should generate combat state for non-guardian floor with combat', () => {
|
||||
const originalRandom = Math.random;
|
||||
Math.random = () => 0.5; // Won't trigger special rooms
|
||||
const state = generateFloorState(5);
|
||||
expect(state.roomType).toBe('combat');
|
||||
expect(state.enemies.length).toBe(1);
|
||||
expect(state.enemies[0].hp).toBe(getFloorMaxHP(5));
|
||||
Math.random = originalRandom;
|
||||
});
|
||||
|
||||
it('should generate swarm state for swarm room', () => {
|
||||
const originalRandom = Math.random;
|
||||
Math.random = () => 0.14; // < SWARM_ROOM_CHANCE (0.15)
|
||||
const state = generateFloorState(5);
|
||||
expect(state.roomType).toBe('swarm');
|
||||
expect(Array.isArray(state.enemies)).toBe(true);
|
||||
expect(state.enemies.length).toBeGreaterThanOrEqual(SWARM_CONFIG.minEnemies);
|
||||
Math.random = originalRandom;
|
||||
});
|
||||
|
||||
it('should generate speed state for speed room', () => {
|
||||
const originalRandom = Math.random;
|
||||
Math.random = () => 0.09; // < SPEED_ROOM_CHANCE (0.10)
|
||||
const state = generateFloorState(5);
|
||||
expect(state.roomType).toBe('speed');
|
||||
expect(state.enemies.length).toBe(1);
|
||||
Math.random = originalRandom;
|
||||
});
|
||||
|
||||
it('should generate puzzle state for puzzle room', () => {
|
||||
const originalRandom = Math.random;
|
||||
Math.random = () => 0.19; // < PUZZLE_ROOM_CHANCE (0.20)
|
||||
const state = generateFloorState(7);
|
||||
expect(state.roomType).toBe('puzzle');
|
||||
expect(Array.isArray(state.enemies)).toBe(true);
|
||||
expect(state.enemies).toEqual([]);
|
||||
expect(state.puzzleProgress).toBe(0);
|
||||
expect(typeof state.puzzleRequired).toBe('number');
|
||||
expect(typeof state.puzzleId).toBe('string');
|
||||
expect(typeof state.puzzleAttunements).toBe('object');
|
||||
Math.random = originalRandom;
|
||||
});
|
||||
|
||||
it('should fill puzzle attunements from PUZZLE_ROOMS', () => {
|
||||
const originalRandom = Math.random;
|
||||
Math.random = () => 0.19;
|
||||
const state = generateFloorState(7);
|
||||
expect(state.roomType).toBe('puzzle');
|
||||
expect(state.puzzleAttunements.length).toBeGreaterThan(0);
|
||||
expect(typeof state.puzzleAttunements[0]).toBe('string');
|
||||
Math.random = originalRandom;
|
||||
});
|
||||
|
||||
it('should use correct element for floor', () => {
|
||||
const state = generateFloorState(1);
|
||||
expect(state.enemies[0].element).toBe('fire');
|
||||
const state2 = generateFloorState(2);
|
||||
expect(state2.enemies[0].element).toBe('water');
|
||||
});
|
||||
|
||||
it('combat enemy HP should match floor max HP', () => {
|
||||
const state = generateFloorState(50);
|
||||
expect(state.enemies[0].hp).toBe(getFloorMaxHP(50));
|
||||
});
|
||||
|
||||
it('speed room should have correct dodge chance', () => {
|
||||
const originalRandom = Math.random;
|
||||
Math.random = () => 0.09; // Speed room
|
||||
const speedState = generateFloorState(50);
|
||||
expect(speedState.roomType).toBe('speed');
|
||||
expect(speedState.enemies[0].dodgeChance).toBe(getDodgeChance(50));
|
||||
Math.random = originalRandom;
|
||||
});
|
||||
|
||||
it('should handle very high floor number', () => {
|
||||
const state = generateFloorState(1000);
|
||||
expect(state.roomType).toBe('guardian');
|
||||
});
|
||||
|
||||
it('should handle floor 0', () => {
|
||||
const state = generateFloorState(0);
|
||||
expect(state.roomType).toBe('combat');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user