Files
jacob-mathison 13aa686fa8
Lint and Build Checks / Lint, Test, and Build (push) Failing after 560h41m34s
feat(gameplay): scaffold phase flow and saves
2026-06-16 10:56:06 -05:00

134 lines
3.4 KiB
TypeScript

jest.mock('@react-native-async-storage/async-storage', () => {
const storage = new Map<string, string>();
return {
__esModule: true,
default: {
getItem: jest.fn((key: string) => Promise.resolve(storage.get(key) ?? null)),
removeItem: jest.fn((key: string) => {
storage.delete(key);
return Promise.resolve();
}),
setItem: jest.fn((key: string, value: string) => {
storage.set(key, value);
return Promise.resolve();
}),
},
};
});
import { act } from 'react-test-renderer';
import { useGameplayStore, useSaveGameStore } from '../src/state';
describe('useGameplayStore', () => {
beforeEach(() => {
act(() => {
useGameplayStore.setState({ activeRun: null });
useSaveGameStore.setState({ saveSlots: [] });
});
});
it('starts a new game on day one at the daily seed phase', () => {
act(() => {
useGameplayStore.getState().startNewGame();
});
expect(useGameplayStore.getState().activeRun).toEqual(
expect.objectContaining({
currentPhaseId: 'dailySeed',
runName: 'Ossuary Dominion Run',
turn: 1,
}),
);
});
it('moves forward and backward through the fixed phase order', () => {
act(() => {
useGameplayStore.getState().startNewGame();
useGameplayStore.getState().goToNextPhase();
});
expect(useGameplayStore.getState().activeRun?.currentPhaseId).toBe(
'throneRoom',
);
act(() => {
useGameplayStore.getState().goToNextPhase();
});
expect(useGameplayStore.getState().activeRun?.currentPhaseId).toBe(
'worldMap',
);
act(() => {
useGameplayStore.getState().goToPreviousPhase();
});
expect(useGameplayStore.getState().activeRun?.currentPhaseId).toBe(
'throneRoom',
);
});
it('increments the day when ending the daily summary phase', () => {
act(() => {
useGameplayStore.getState().startNewGame();
useGameplayStore.getState().goToNextPhase();
useGameplayStore.getState().goToNextPhase();
useGameplayStore.getState().goToNextPhase();
useGameplayStore.getState().goToNextPhase();
});
expect(useGameplayStore.getState().activeRun).toEqual(
expect.objectContaining({
currentPhaseId: 'dailySeed',
turn: 2,
}),
);
});
it('saves and loads a run through save slots', () => {
act(() => {
useGameplayStore.getState().startNewGame();
useGameplayStore.getState().goToNextPhase();
useGameplayStore.getState().saveCurrentRun();
});
const saveSlot = useSaveGameStore.getState().saveSlots[0];
expect(saveSlot).toEqual(
expect.objectContaining({
phaseId: 'throneRoom',
turn: 1,
}),
);
act(() => {
useGameplayStore.getState().goToNextPhase();
useGameplayStore.getState().loadGame(saveSlot.id);
});
expect(useGameplayStore.getState().activeRun).toEqual(
expect.objectContaining({
currentPhaseId: 'throneRoom',
gameId: saveSlot.id,
turn: 1,
}),
);
});
it('keeps the active run available after exiting to home', () => {
act(() => {
useGameplayStore.getState().startNewGame();
});
const gameId = useGameplayStore.getState().activeRun?.gameId;
act(() => {
useGameplayStore.getState().exitToHome();
});
expect(useGameplayStore.getState().activeRun?.gameId).toBe(gameId);
});
});