diff options
Diffstat (limited to 'web/test/gameLogic.test.ts')
| -rw-r--r-- | web/test/gameLogic.test.ts | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/web/test/gameLogic.test.ts b/web/test/gameLogic.test.ts new file mode 100644 index 0000000..263ba14 --- /dev/null +++ b/web/test/gameLogic.test.ts @@ -0,0 +1,149 @@ +import { describe, it, expect } from 'vitest'; +import { ELEMENTS, elementState } from '$lib/game/elements'; +import { + CONDITIONS, + conditionChipClass, + conditionLabel, + conditionName +} from '$lib/game/conditions'; +import { classColor, classIcon, monsterImage } from '$lib/game/art'; +import { + characterStatCounters, + standeeFigureId, + standeeStatCounters, + type ModifierDeckJson +} from '$lib/game/stats'; +import { t, hasLocaleKey, availableLocales } from '$lib/i18n'; + +describe('elements', () => { + it('lists the six elements in server enum order', () => { + expect(ELEMENTS.map((e) => e.name)).toEqual([ + 'fire', + 'ice', + 'air', + 'earth', + 'light', + 'dark' + ]); + }); + + it('reads the element state by index string (absent → inert)', () => { + expect(elementState({}, 0)).toBe(2); + expect(elementState({ '0': 0, '1': 1 }, 0)).toBe(0); + expect(elementState({ '0': 0, '1': 1 }, 1)).toBe(1); + expect(elementState({ '0': 9 }, 0)).toBe(2); // out-of-range → inert + }); +}); + +describe('conditions', () => { + it('keeps the server Condition index mapping', () => { + // stun = 0, wound = 3, chill = 12, retaliate = 24 + expect(conditionName(0)).toBe('stun'); + expect(conditionName(3)).toBe('wound'); + expect(conditionName(12)).toBe('chill'); + expect(conditionName(24)).toBe('retaliate'); + }); + + it('labels fall back to the index for unknown entries', () => { + expect(conditionLabel(0)).toBe('Stunned'); + expect(conditionLabel(999)).toBe('condition 999'); + }); + + it('chill and plague get coloured chips, the rest are plain', () => { + expect(conditionChipClass(12)).toBe('cond cond--chill'); + expect(conditionChipClass(16)).toBe('cond cond--plague'); + expect(conditionChipClass(0)).toBe('cond'); + }); + + it('excludes the custom character slots (character1..4)', () => { + const names = CONDITIONS.map((c) => c.name); + expect(names).not.toContain('character1'); + expect(names).not.toContain('character4'); + }); +}); + +describe('art', () => { + it('resolves class icons and monster art under /images/', () => { + // gfx values in the data carry no extension; .png is appended (the + // reference app builds the same path). + expect(classIcon('Berserker')).toBe('/images/class-icons/Berserker.png'); + expect(monsterImage('Zombie')).toBe('/images/monsters/Zombie.png'); + }); + + it('classColor accepts 0xAARRGGBB and plain hex', () => { + expect(classColor('FF9C881A')).toBe('#9C881A'); + expect(classColor('#a1b2c3')).toBe('#a1b2c3'); + expect(classColor('garbage')).toBe('#3a3f47'); + }); +}); + +describe('stat counters', () => { + function deck(cards: { gfx: string }[]): ModifierDeckJson { + return { drawPile: cards, discardPile: [] }; + } + + it('standeeFigureId is name + gfx + standeeNr', () => { + const standee = { + name: 'Zombie', + gfx: 'BLA zombie', + standeeNr: 2 + } as never; + expect(standeeFigureId(standee)).toBe('ZombieBLA zombie2'); + }); + + it('counts bless/curse/empower/enfeeble cards in the draw pile', () => { + const d = deck([ + { gfx: 'bless' }, + { gfx: 'curse' }, + { gfx: 'in-empower' }, + { gfx: 'out-enfeeble' }, + { gfx: 'bless' }, + { gfx: 'hazard-1' } + ]); + expect(standeeStatCounters(d)).toEqual({ + bless: 2, + curse: 1, + empower: 1, + enfeeble: 1 + }); + expect(standeeStatCounters(undefined)).toEqual({ + bless: 0, + curse: 0, + empower: 0, + enfeeble: 0 + }); + }); + + it('characterStatCounters reads the character\'s own deck', () => { + const character = { + id: 'Berserker', + characterState: { + modifierDeck: deck([{ gfx: 'curse' }, { gfx: 'curse' }]) + } + } as never; + expect(characterStatCounters(character).curse).toBe(2); + }); +}); + +describe('i18n', () => { + it('translates English keys', () => { + expect(t('draw')).toBe('Draw'); + expect(t('menuAddCharacter')).toBe('Add Character'); + }); + + it('substitutes {vars}', () => { + expect(t('cmdAddMonster', { name: 'Zombie' })).toBe('Add Zombie'); + expect(t('cmdIncreaseXp', { figure: 'Berserker', amount: 10 })).toBe( + "Increase Berserker's xp by 10" + ); + }); + + it('returns the key for unknown keys', () => { + expect(t('noSuchKey')).toBe('noSuchKey'); + }); + + it('only English is ported in Phase 3', () => { + expect(availableLocales).toEqual(['en']); + expect(hasLocaleKey('draw')).toBe(true); + }); +}); |
