The merge brought in `CombatDto.rewards`, which the resume spec's fixture predates. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
import { TestBed } from '@angular/core/testing';
|
|
import { Router, provideRouter } from '@angular/router';
|
|
import { vi } from 'vitest';
|
|
import type { Combat } from './api/game-api.models';
|
|
import { App } from '../app';
|
|
import { CombatStore } from '../features/combat/combat.store';
|
|
|
|
const runningCombat: Combat = {
|
|
id: 'combat-running',
|
|
status: 'ACTIVE',
|
|
round: 4,
|
|
player: { name: 'Aric Duskwalker', maxHp: 100, currentHp: 62 },
|
|
monster: {
|
|
key: 'road-bandit',
|
|
name: 'Straßenräuber',
|
|
level: 3,
|
|
maxHp: 75,
|
|
currentHp: 30,
|
|
artworkPath: '/images/enemies/RoadBandit.png',
|
|
},
|
|
events: [],
|
|
rewards: null,
|
|
};
|
|
|
|
describe('resuming an interrupted combat', () => {
|
|
let combatStore: { loadActiveCombat: ReturnType<typeof vi.fn> };
|
|
let router: Router;
|
|
|
|
async function bootstrap() {
|
|
await TestBed.configureTestingModule({
|
|
imports: [App],
|
|
providers: [
|
|
provideRouter([
|
|
{ path: 'world', children: [] },
|
|
{ path: 'combat/:combatId', children: [] },
|
|
]),
|
|
{ provide: CombatStore, useValue: combatStore },
|
|
],
|
|
}).compileComponents();
|
|
|
|
router = TestBed.inject(Router);
|
|
vi.spyOn(router, 'navigate').mockResolvedValue(true);
|
|
|
|
const fixture = TestBed.createComponent(App);
|
|
fixture.detectChanges();
|
|
await fixture.whenStable();
|
|
return fixture;
|
|
}
|
|
|
|
it('drops the player straight back into the fight they left running', async () => {
|
|
combatStore = { loadActiveCombat: vi.fn(() => Promise.resolve(runningCombat)) };
|
|
|
|
await bootstrap();
|
|
|
|
expect(combatStore.loadActiveCombat).toHaveBeenCalledOnce();
|
|
expect(router.navigate).toHaveBeenCalledWith(['/combat', 'combat-running']);
|
|
});
|
|
|
|
it('leaves navigation alone when no fight is running', async () => {
|
|
combatStore = { loadActiveCombat: vi.fn(() => Promise.resolve(null)) };
|
|
|
|
await bootstrap();
|
|
|
|
expect(combatStore.loadActiveCombat).toHaveBeenCalledOnce();
|
|
expect(router.navigate).not.toHaveBeenCalled();
|
|
});
|
|
});
|