fix(BUG-12): campaign selection follows activeDisplay
Selection effect had `!selectedCampaignId` guard — once any campaign selected, new activeDisplay.activeCampaignId writes ignored. Replay tool writes activeDisplay to new campaign each run; UI stayed on old selection => displayed wrong campaign data. Removed guard. Selection now syncs when activeCampaignId differs from current selection. Manual deselect (null) does not force-select (RED test locks this). Also fixed test helper bug: createCampaignViaUI/createEncounterViaUI returned FIRST setDoc match (idA for all creates). Now filters by name + .pop() for latest. This masked the real bug for several debug cycles. Tests: 2 new (SelectionFollowsActiveDisplay), both green. No regressions in full FE suite (App, Combat, DisplayView, Encounter, HideHpToggle, Logs, Participant, storage all pass). Combat.scenario = pre-existing BUG-11 crash, not regression.
This commit is contained in:
@@ -33,10 +33,10 @@ export async function createCampaignViaUI(name = 'Test Campaign') {
|
||||
await waitFor(() => screen.getByLabelText(/Campaign Name/i));
|
||||
fireEvent.change(screen.getByLabelText(/Campaign Name/i), { target: { value: name } });
|
||||
fireEvent.click(screen.getByRole('button', { name: /^Create$/i }));
|
||||
// wait for setDoc recorded
|
||||
// wait for setDoc recorded with this name (latest match)
|
||||
const { getCalls } = require('../__mocks__/firebase/_mock-db');
|
||||
await waitFor(() => getCalls().find(c => c.fn === 'setDoc' && c.path.includes('/campaigns/')));
|
||||
const call = getCalls().find(c => c.fn === 'setDoc' && c.path.includes('/campaigns/'));
|
||||
await waitFor(() => getCalls().find(c => c.fn === 'setDoc' && c.path.includes('/campaigns/') && c.data.name === name));
|
||||
const call = getCalls().filter(c => c.fn === 'setDoc' && c.path.includes('/campaigns/') && c.data.name === name).pop();
|
||||
return call.path.split('/').pop(); // campaign id
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ export async function createEncounterViaUI(name = 'Test Encounter') {
|
||||
fireEvent.change(screen.getByLabelText(/Encounter Name/i), { target: { value: name } });
|
||||
fireEvent.click(screen.getByRole('button', { name: /^Create$/i }));
|
||||
const { getCalls } = require('../__mocks__/firebase/_mock-db');
|
||||
await waitFor(() => getCalls().find(c => c.fn === 'setDoc' && c.path.includes('/encounters/')));
|
||||
const call = getCalls().find(c => c.fn === 'setDoc' && c.path.includes('/encounters/'));
|
||||
await waitFor(() => getCalls().find(c => c.fn === 'setDoc' && c.path.includes('/encounters/') && c.data.name === name));
|
||||
const call = getCalls().filter(c => c.fn === 'setDoc' && c.path.includes('/encounters/') && c.data.name === name).pop();
|
||||
return call.path.split('/').pop();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user