All files / test test-utils.ts

60% Statements 3/5
100% Branches 0/0
60% Functions 3/5
60% Lines 3/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126                                                  66x                                       25x                           602x                                                                                                                                    
import { PlayerState } from "@/systems";
import type { RenderOptions } from "@testing-library/react";
import { render } from "@testing-library/react";
import React from "react";
import { CombatState, PlayerArchetype, TrigramStance } from "../types/common";
 
/**
 * Generic mutable type - removes readonly modifier from all properties
 * Use this type when you need to modify readonly properties in tests
 */
export type Mutable<T> = {
  -readonly [K in keyof T]: T[K];
};
 
/**
 * Mutable version of PlayerState for test setup
 * Use this type when you need to modify player properties in tests
 */
export type MutablePlayerState = Mutable<PlayerState>;
 
/**
 * Cast any object to a mutable version for test setup purposes
 * This allows direct property assignment during test setup on readonly properties
 */
export function asMutable<T>(obj: T): Mutable<T> {
  return obj as Mutable<T>;
}
 
/**
 * Arena bounds for combat testing
 */
export interface ArenaBounds {
  x: number;
  y: number;
  width: number;
  height: number;
  scale?: number;
  worldWidthMeters: number;
  worldDepthMeters: number;
}
 
/**
 * Create mock arena bounds
 */
export function createMockArena(): ArenaBounds {
  return {
    x: 0,
    y: 0,
    width: 1200,
    height: 800,
    scale: 1.0,
    worldWidthMeters: 10,
    worldDepthMeters: 10,
  };
}
 
export function createMockPlayerState(
  overrides?: Partial<PlayerState>,
): PlayerState {
  return {
    id: "test",
    name: { korean: "테스트", english: "Test" },
    archetype: PlayerArchetype.MUSA,
    health: 100,
    maxHealth: 100,
    ki: 100,
    maxKi: 100,
    stamina: 100,
    maxStamina: 100,
    energy: 100,
    maxEnergy: 100,
    attackPower: 75,
    defense: 75,
    speed: 75,
    technique: 75,
    pain: 0,
    consciousness: 100,
    balance: 100,
    momentum: 0,
    currentStance: TrigramStance.GEON,
    combatState: CombatState.IDLE,
    position: { x: 0, y: 0 },
    isBlocking: false,
    isStunned: false,
    isCountering: false,
    lastActionTime: 0,
    recoveryTime: 0,
    lastStanceChangeTime: 0,
    statusEffects: [],
    activeEffects: [],
    vitalPoints: [],
    totalDamageReceived: 0,
    totalDamageDealt: 0,
    hitsTaken: 0,
    hitsLanded: 0,
    perfectStrikes: 0,
    vitalPointHits: 0,
    experiencePoints: 0,
    ...overrides,
  };
}
 
/**
 * Create a modified copy of player state (for tests that need to mutate state)
 * Use this instead of direct property assignment on readonly PlayerState
 */
export function withPlayerState(
  player: PlayerState,
  updates: Partial<PlayerState>,
): PlayerState {
  return { ...player, ...updates };
}
 
// Enhanced render function with proper options
export function customRender(
  ui: React.ReactElement,
  options?: Omit<RenderOptions, "wrapper">,
) {
  return render(ui, {
    ...options,
  });
}
 
export * from "@testing-library/react";
export { customRender as render };