67 lines
2.5 KiB
TypeScript
67 lines
2.5 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { UpgradeManager } from '../UpgradeManager';
|
|
import { createMeleeWeapon, createArmour, createConsumable } from '../../../core/config/Items';
|
|
import type { WeaponItem, ArmourItem } from '../../../core/types';
|
|
|
|
describe('UpgradeManager', () => {
|
|
it('should correctly identify upgradeable items', () => {
|
|
const sword = createMeleeWeapon("iron_sword");
|
|
const armor = createArmour("leather_armor");
|
|
const potion = createConsumable("health_potion");
|
|
|
|
expect(UpgradeManager.canUpgrade(sword)).toBe(true);
|
|
expect(UpgradeManager.canUpgrade(armor)).toBe(true);
|
|
expect(UpgradeManager.canUpgrade(potion)).toBe(false);
|
|
});
|
|
|
|
it('should upgrade weapon stats and name', () => {
|
|
const sword = createMeleeWeapon("iron_sword") as WeaponItem;
|
|
const initialAttack = sword.stats.attack!;
|
|
const initialName = sword.name;
|
|
|
|
const success = UpgradeManager.applyUpgrade(sword);
|
|
|
|
expect(success).toBe(true);
|
|
expect(sword.stats.attack).toBe(initialAttack + 1);
|
|
expect(sword.upgradeLevel).toBe(1);
|
|
expect(sword.name).toBe(`${initialName} +1`);
|
|
});
|
|
|
|
it('should upgrade armour stats and name', () => {
|
|
const armor = createArmour("leather_armor") as ArmourItem;
|
|
const initialDefense = armor.stats.defense!;
|
|
const initialName = armor.name;
|
|
|
|
const success = UpgradeManager.applyUpgrade(armor);
|
|
|
|
expect(success).toBe(true);
|
|
expect(armor.stats.defense).toBe(initialDefense + 1);
|
|
expect(armor.upgradeLevel).toBe(1);
|
|
expect(armor.name).toBe(`${initialName} +1`);
|
|
});
|
|
|
|
it('should handle sequential upgrades', () => {
|
|
const sword = createMeleeWeapon("iron_sword") as WeaponItem;
|
|
const initialAttack = sword.stats.attack!;
|
|
const initialName = sword.name;
|
|
|
|
UpgradeManager.applyUpgrade(sword); // +1
|
|
UpgradeManager.applyUpgrade(sword); // +2
|
|
|
|
expect(sword.stats.attack).toBe(initialAttack + 2);
|
|
expect(sword.upgradeLevel).toBe(2);
|
|
expect(sword.name).toBe(`${initialName} +2`);
|
|
});
|
|
|
|
it('should not upgrade non-upgradeable items', () => {
|
|
const potion = createConsumable("health_potion");
|
|
const initialName = potion.name;
|
|
|
|
const success = UpgradeManager.applyUpgrade(potion);
|
|
|
|
expect(success).toBe(false);
|
|
expect(potion.upgradeLevel).toBeUndefined();
|
|
expect(potion.name).toBe(initialName);
|
|
});
|
|
});
|