fix: SpireTab store props, mana regen display, skill cost deduction, grimoire cost format, unequip store, add test suite
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m34s

This commit is contained in:
2026-05-08 11:45:31 +02:00
parent 0fadbfef4a
commit 71fbc7c964
12 changed files with 354 additions and 22 deletions
@@ -0,0 +1,55 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { useSkillStore } from '@/lib/game/stores';
import { useManaStore } from '@/lib/game/stores';
import { initialSkillState } from '@/lib/game/stores/skillStore';
import { initialManaState } from '@/lib/game/stores/manaStore';
describe('useSkillStore', () => {
beforeEach(() => {
useSkillStore.setState(initialSkillState);
useManaStore.setState(initialManaState);
});
it('startStudyingSkill returns { started: false } if rawMana < cost', () => {
// Set rawMana to 0
useManaStore.setState({ rawMana: 0 });
const result = useSkillStore.getState().startStudyingSkill('manaWell', false);
expect(result.started).toBe(false);
});
it('startStudyingSkill deducts mana via manaStore.spendRawMana when started', () => {
// Set rawMana to 100, skill cost is maybe 50? We need to know the cost.
// Let's mock spendRawMana to track calls
const spendRawManaSpy = vi.spyOn(useManaStore.getState(), 'spendRawMana');
useManaStore.setState({ rawMana: 100 });
const result = useSkillStore.getState().startStudyingSkill('manaWell', false);
if (result.started) {
expect(spendRawManaSpy).toHaveBeenCalledWith(result.cost);
}
});
it('startStudyingSkill does NOT deduct if isAlreadyPaid', () => {
const spendRawManaSpy = vi.spyOn(useManaStore.getState(), 'spendRawMana');
useManaStore.setState({ rawMana: 100 });
const result = useSkillStore.getState().startStudyingSkill('manaWell', true);
if (result.started) {
expect(spendRawManaSpy).not.toHaveBeenCalled();
expect(result.cost).toBe(0); // cost should be 0 if already paid
}
});
it('cancelStudy clears currentStudyTarget', () => {
// First start studying
useManaStore.setState({ rawMana: 100 });
useSkillStore.getState().startStudyingSkill('manaWell', false);
expect(useSkillStore.getState().currentStudyTarget).not.toBeNull();
// Cancel study
useSkillStore.getState().cancelStudy();
expect(useSkillStore.getState().currentStudyTarget).toBeNull();
});
});