Fix issue #2: Add animations
This commit is contained in:
85
frontend/test/gameAnimations.test.ts
Normal file
85
frontend/test/gameAnimations.test.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { diffGameState } from '../app/utils/gameAnimations.ts'
|
||||
|
||||
test('diffGameState ignores the first snapshot', () => {
|
||||
const animations = diffGameState(undefined, {
|
||||
id: 'game',
|
||||
players: [{ id: 'p1', life: 40, battlefield: [{ id: 'card-1' }] }],
|
||||
game: { manaPool: { G: 2 } },
|
||||
})
|
||||
|
||||
assert.deepEqual(animations, {
|
||||
enteringCardIds: [],
|
||||
attackingCardIds: [],
|
||||
damagedCards: [],
|
||||
lifeChanges: [],
|
||||
manaGains: [],
|
||||
})
|
||||
})
|
||||
|
||||
test('diffGameState detects entering and attacking permanents', () => {
|
||||
const animations = diffGameState(
|
||||
{ id: 'game', players: [{ id: 'p1', battlefield: [{ id: 'old' }] }] },
|
||||
{
|
||||
id: 'game',
|
||||
players: [{
|
||||
id: 'p1',
|
||||
battlefield: [{ id: 'old' }, { id: 'new', attacking: 'p2' }],
|
||||
}],
|
||||
},
|
||||
)
|
||||
|
||||
assert.deepEqual(animations.enteringCardIds, ['new'])
|
||||
assert.deepEqual(animations.attackingCardIds, ['new'])
|
||||
})
|
||||
|
||||
test('diffGameState reports damage and life changes', () => {
|
||||
const animations = diffGameState(
|
||||
{
|
||||
id: 'game',
|
||||
players: [
|
||||
{ id: 'p1', life: 40, battlefield: [{ id: 'creature', damage: 1 }] },
|
||||
{ id: 'p2', life: 40 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'game',
|
||||
players: [
|
||||
{ id: 'p1', life: 40, battlefield: [{ id: 'creature', damage: 4 }] },
|
||||
{ id: 'p2', life: 33 },
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
assert.deepEqual(animations.damagedCards, [{ cardId: 'creature', amount: 3 }])
|
||||
assert.deepEqual(animations.lifeChanges, [{ playerId: 'p2', amount: -7 }])
|
||||
})
|
||||
|
||||
test('diffGameState only animates mana gains', () => {
|
||||
const animations = diffGameState(
|
||||
{ id: 'game', players: [], game: { manaPool: { G: 1, R: 2 } } },
|
||||
{ id: 'game', players: [], game: { manaPool: { G: 3, R: 0, U: 1 } } },
|
||||
)
|
||||
|
||||
assert.deepEqual(animations.manaGains, [
|
||||
{ color: 'G', amount: 2 },
|
||||
{ color: 'U', amount: 1 },
|
||||
])
|
||||
})
|
||||
|
||||
test('diffGameState is quiet when nothing visible changed', () => {
|
||||
const state = {
|
||||
id: 'game',
|
||||
players: [{ id: 'p1', life: 40, battlefield: [{ id: 'creature', damage: 2 }] }],
|
||||
game: { manaPool: { W: 1 } },
|
||||
}
|
||||
|
||||
assert.deepEqual(diffGameState(state, state), {
|
||||
enteringCardIds: [],
|
||||
attackingCardIds: [],
|
||||
damagedCards: [],
|
||||
lifeChanges: [],
|
||||
manaGains: [],
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user