fix: load WorldStore on direct /hunt navigation

HuntPageComponent never called WorldStore.load(), so opening /hunt
directly (bookmark/hard refresh) without first visiting /world left
currentLocation() at null forever, stranding the page and the context
panel on their empty states with no recovery. Add ngOnInit that calls
worldStore.load() only when no location is present yet, mirroring
WorldPageComponent's existing call and avoiding a duplicate request.
This commit is contained in:
Bastian Wagner
2026-08-19 14:33:15 +02:00
parent 4e684dc45e
commit 26909d7e2a
2 changed files with 22 additions and 3 deletions

View File

@@ -76,6 +76,7 @@ const threeEncounterHunt: HuntResult = {
describe('HuntPageComponent', () => {
let worldStore: {
currentLocation: ReturnType<typeof signal<CurrentLocationResponse | null>>;
load: ReturnType<typeof vi.fn>;
};
let huntingStore: {
currentHunt: ReturnType<typeof signal<HuntResult | null>>;
@@ -89,7 +90,7 @@ describe('HuntPageComponent', () => {
let router: Router;
async function setup(location: CurrentLocationResponse | null, hunt: HuntResult | null = null) {
worldStore = { currentLocation: signal(location) };
worldStore = { currentLocation: signal(location), load: vi.fn(() => Promise.resolve()) };
const currentHunt = signal(hunt);
huntingStore = {
currentHunt,
@@ -196,6 +197,18 @@ describe('HuntPageComponent', () => {
expect(huntingStore.startHunt).not.toHaveBeenCalled();
});
it('loads the world state on init when no location has been loaded yet (direct navigation/hard refresh)', async () => {
await setup(null);
expect(worldStore.load).toHaveBeenCalledOnce();
});
it('does not call load again when a location is already present', async () => {
await setup(burnedRoad);
expect(worldStore.load).not.toHaveBeenCalled();
});
it('shows a loading state and disables the triggering action', async () => {
const fixture = await setup(burnedRoad);
huntingStore.loading.set(true);