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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user