Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d0dc79206 | ||
|
|
4b8b8bccfb | ||
|
|
c0998da0a7 |
@@ -90,7 +90,7 @@ REWORK_PLAN.md.
|
||||
|
||||
### bug-3 was a halucination has been removed
|
||||
|
||||
### BUG-4: hide-player-HP breaks display view (preexisting)
|
||||
### BUG-4: hide-player-HP breaks display view (preexisting) --- PROD FIXED, TEST RED (mock bug)
|
||||
- **Broader than hide-HP**: ALL 5 `storage.setDoc(getPath.activeDisplay(), ...)` calls
|
||||
use `{merge:true}` which is IGNORED (setDoc = replace per contract).
|
||||
Each write clobbers other fields on activeDisplay/status doc.
|
||||
@@ -108,6 +108,13 @@ REWORK_PLAN.md.
|
||||
activeEncounterId with null (setDoc replace vs updateDoc patch).
|
||||
- Fix: use updateDoc (patch) not setDoc (replace); or include all existing
|
||||
fields when writing.
|
||||
- Status update (2026-07): all 5 sites now use `{merge:true}`. Real firebase
|
||||
adapter honors merge → production works. BUT jsdom test still RED because
|
||||
`src/__mocks__/firebase/firestore.js` setDoc records call, IGNORES opts
|
||||
(no actual merge). Mock must simulate firebase merge semantics for test
|
||||
to pass. Fix = mock setDoc: if opts.merge, MOCK_DB.merge(path,data) else
|
||||
replace. OR change App.js setDoc(merge) → updateDoc (cleaner, ws adapter
|
||||
uses PATCH). Decide which.
|
||||
- Test: render App + DisplayView, toggle hide-HP, assert display still shows
|
||||
encounter (not paused).
|
||||
|
||||
|
||||
+56
-18
@@ -8,7 +8,7 @@ import {
|
||||
UserCheck, UserX, HeartCrack, HeartPulse, Zap, EyeOff, ExternalLink, AlertTriangle,
|
||||
Play as PlayIcon, Pause as PauseIcon, SkipForward as SkipForwardIcon,
|
||||
StopCircle as StopCircleIcon, Users2, Dices, ChevronUp, ChevronDown, ScrollText,
|
||||
Maximize2, Minimize2, Moon, Coffee, Clock
|
||||
Maximize2, Minimize2, Moon, Coffee, Clock, ChevronRight
|
||||
} from 'lucide-react';
|
||||
|
||||
// Custom CSS for death animation (player view only)
|
||||
@@ -1658,16 +1658,26 @@ function InitiativeControls({ campaignId, encounter, encounterPath }) {
|
||||
const [showEndConfirm, setShowEndConfirm] = useState(false);
|
||||
const { data: activeDisplayData } = useFirestoreDocument(getPath.activeDisplay());
|
||||
const hidePlayerHp = activeDisplayData?.hidePlayerHp ?? true;
|
||||
const hideNpcHp = activeDisplayData?.hideNpcHp ?? false;
|
||||
|
||||
const handleToggleHidePlayerHp = async () => {
|
||||
if (!db) return;
|
||||
try {
|
||||
await storage.setDoc(getPath.activeDisplay(), { hidePlayerHp: !hidePlayerHp }, { merge: true });
|
||||
await storage.updateDoc(getPath.activeDisplay(), { hidePlayerHp: !hidePlayerHp });
|
||||
} catch (err) {
|
||||
console.error("Error toggling hidePlayerHp:", err);
|
||||
}
|
||||
};
|
||||
|
||||
const handleToggleHideNpcHp = async () => {
|
||||
if (!db) return;
|
||||
try {
|
||||
await storage.updateDoc(getPath.activeDisplay(), { hideNpcHp: !hideNpcHp });
|
||||
} catch (err) {
|
||||
console.error("Error toggling hideNpcHp:", err);
|
||||
}
|
||||
};
|
||||
|
||||
const handleStartEncounter = async () => {
|
||||
if (!db || !encounter.participants || encounter.participants.length === 0) {
|
||||
alert("Add participants first.");
|
||||
@@ -1695,10 +1705,10 @@ function InitiativeControls({ campaignId, encounter, encounterPath }) {
|
||||
turnOrderIds: sortedParticipants.map(p => p.id)
|
||||
});
|
||||
|
||||
await storage.setDoc(getPath.activeDisplay(), {
|
||||
await storage.updateDoc(getPath.activeDisplay(), {
|
||||
activeCampaignId: campaignId,
|
||||
activeEncounterId: encounter.id
|
||||
}, { merge: true });
|
||||
});
|
||||
|
||||
logAction(`Combat started: "${encounter.name}" — ${sortedParticipants[0].name}'s turn (Round 1)`, { encounterName: encounter.name }, {
|
||||
encounterPath,
|
||||
@@ -1826,10 +1836,10 @@ function InitiativeControls({ campaignId, encounter, encounterPath }) {
|
||||
turnOrderIds: []
|
||||
});
|
||||
|
||||
await storage.setDoc(getPath.activeDisplay(), {
|
||||
await storage.updateDoc(getPath.activeDisplay(), {
|
||||
activeCampaignId: null,
|
||||
activeEncounterId: null
|
||||
}, { merge: true });
|
||||
});
|
||||
|
||||
logAction(`Combat ended: "${encounter.name}"`, { encounterName: encounter.name }, {
|
||||
encounterPath,
|
||||
@@ -1915,6 +1925,17 @@ function InitiativeControls({ campaignId, encounter, encounterPath }) {
|
||||
<span className={`inline-block h-4 w-4 transform rounded-full bg-white shadow transition-transform ${hidePlayerHp ? 'translate-x-4' : 'translate-x-0'}`} />
|
||||
</button>
|
||||
</label>
|
||||
<label className="flex items-center justify-between cursor-pointer gap-2 mt-2">
|
||||
<span className="text-sm text-stone-300">Hide NPC/monster HP</span>
|
||||
<button
|
||||
role="switch"
|
||||
aria-checked={hideNpcHp}
|
||||
onClick={handleToggleHideNpcHp}
|
||||
className={`relative inline-flex h-5 w-9 flex-shrink-0 rounded-full border-2 border-transparent transition-colors focus:outline-none ${hideNpcHp ? 'bg-amber-600' : 'bg-stone-600'}`}
|
||||
>
|
||||
<span className={`inline-block h-4 w-4 transform rounded-full bg-white shadow transition-transform ${hideNpcHp ? 'translate-x-4' : 'translate-x-0'}`} />
|
||||
</button>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2044,15 +2065,15 @@ function EncounterManager({ campaignId, initialActiveEncounterId, campaignCharac
|
||||
const currentActiveEncounter = activeDisplayInfo?.activeEncounterId;
|
||||
|
||||
if (currentActiveCampaign === campaignId && currentActiveEncounter === encounterId) {
|
||||
await storage.setDoc(getPath.activeDisplay(), {
|
||||
await storage.updateDoc(getPath.activeDisplay(), {
|
||||
activeCampaignId: null,
|
||||
activeEncounterId: null,
|
||||
}, { merge: true });
|
||||
});
|
||||
} else {
|
||||
await storage.setDoc(getPath.activeDisplay(), {
|
||||
await storage.updateDoc(getPath.activeDisplay(), {
|
||||
activeCampaignId: campaignId,
|
||||
activeEncounterId: encounterId,
|
||||
}, { merge: true });
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Error toggling Player Display:", err);
|
||||
@@ -2195,6 +2216,7 @@ function AdminView({ userId }) {
|
||||
const [showCreateModal, setShowCreateModal] = useState(false);
|
||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
||||
const [itemToDelete, setItemToDelete] = useState(null);
|
||||
const [campaignsCollapsed, setCampaignsCollapsed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (campaignsData && db) {
|
||||
@@ -2322,7 +2344,18 @@ function AdminView({ userId }) {
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<div className="flex justify-between items-center mb-4">
|
||||
<h2 className="text-2xl font-semibold text-amber-300 font-cinzel tracking-wide">Campaigns</h2>
|
||||
<button
|
||||
onClick={() => setCampaignsCollapsed(c => !c)}
|
||||
className="flex items-center gap-2 text-2xl font-semibold text-amber-300 font-cinzel tracking-wide hover:text-amber-200 transition-colors"
|
||||
aria-expanded={!campaignsCollapsed}
|
||||
aria-controls="campaigns-grid"
|
||||
>
|
||||
{campaignsCollapsed
|
||||
? <ChevronRight size={24} />
|
||||
: <ChevronDown size={24} />}
|
||||
Campaigns
|
||||
<span className="text-sm font-normal text-stone-400">({campaignsWithDetails.length})</span>
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setShowCreateModal(true)}
|
||||
className="bg-red-700 hover:bg-red-800 text-white font-bold py-2 px-4 rounded-lg flex items-center transition-colors"
|
||||
@@ -2331,12 +2364,14 @@ function AdminView({ userId }) {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{campaignsWithDetails.length === 0 && !isLoadingCampaigns && (
|
||||
<p className="text-stone-400">No campaigns yet. Create one to get started!</p>
|
||||
)}
|
||||
{!campaignsCollapsed && (
|
||||
<>
|
||||
{campaignsWithDetails.length === 0 && !isLoadingCampaigns && (
|
||||
<p className="text-stone-400">No campaigns yet. Create one to get started!</p>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{campaignsWithDetails.map(campaign => {
|
||||
<div id="campaigns-grid" className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{campaignsWithDetails.map(campaign => {
|
||||
const cardStyle = campaign.playerDisplayBackgroundUrl
|
||||
? { backgroundImage: `url(${campaign.playerDisplayBackgroundUrl})` }
|
||||
: {};
|
||||
@@ -2382,7 +2417,9 @@ function AdminView({ userId }) {
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{showCreateModal && (
|
||||
@@ -2576,6 +2613,7 @@ function DisplayView() {
|
||||
|
||||
const { name, participants, round, currentTurnParticipantId, isStarted, isPaused } = activeEncounterData;
|
||||
const hidePlayerHp = activeDisplayData?.hidePlayerHp ?? true;
|
||||
const hideNpcHp = activeDisplayData?.hideNpcHp ?? false;
|
||||
|
||||
let participantsToRender = [];
|
||||
if (participants) {
|
||||
@@ -2677,7 +2715,7 @@ function DisplayView() {
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{!(hidePlayerHp && p.type === 'character') && (
|
||||
{!(hidePlayerHp && p.type === 'character') && !(hideNpcHp && p.type !== 'character') && (
|
||||
<div className="flex justify-between items-center">
|
||||
<div className="w-full bg-stone-700 rounded-full h-6 md:h-8 relative overflow-hidden border-2 border-stone-600">
|
||||
<div
|
||||
|
||||
@@ -41,7 +41,7 @@ describe('Combat -> Firebase', () => {
|
||||
test('startEncounter: also sets activeDisplay to this encounter', async () => {
|
||||
await setupWithMonsters();
|
||||
await startCombatViaUI();
|
||||
const adCalls = findCallActiveDisplay('setDoc');
|
||||
const adCalls = findCallActiveDisplay('updateDoc');
|
||||
const last = adCalls[adCalls.length - 1];
|
||||
expect(last.data.activeCampaignId).toBeTruthy();
|
||||
expect(last.data.activeEncounterId).toBeTruthy();
|
||||
@@ -111,26 +111,26 @@ describe('Combat -> Firebase', () => {
|
||||
fireEvent.click(screen.getByRole('button', { name: /End Combat/i }));
|
||||
fireEvent.click(await screen.findByRole('button', { name: /Confirm/i }));
|
||||
await waitFor(() => {
|
||||
const adCalls = findCallActiveDisplay('setDoc');
|
||||
const adCalls = findCallActiveDisplay('updateDoc');
|
||||
const last = adCalls[adCalls.length - 1];
|
||||
return last && last.data.activeCampaignId === null;
|
||||
});
|
||||
const adCalls = findCallActiveDisplay('setDoc');
|
||||
const adCalls = findCallActiveDisplay('updateDoc');
|
||||
const last = adCalls[adCalls.length - 1];
|
||||
expect(last.data).toMatchObject({ activeCampaignId: null, activeEncounterId: null });
|
||||
});
|
||||
|
||||
test('toggleHidePlayerHp: setDoc merge on activeDisplay/status', async () => {
|
||||
test('toggleHidePlayerHp: updateDoc patch on activeDisplay/status', async () => {
|
||||
await setupWithMonsters();
|
||||
await startCombatViaUI();
|
||||
const switchBtn = screen.getByRole('switch');
|
||||
fireEvent.click(switchBtn);
|
||||
await waitFor(() => {
|
||||
const adCalls = findCallActiveDisplay('setDoc');
|
||||
const adCalls = findCallActiveDisplay('updateDoc');
|
||||
const last = adCalls[adCalls.length - 1];
|
||||
return last && 'hidePlayerHp' in last.data;
|
||||
});
|
||||
const adCalls = findCallActiveDisplay('setDoc');
|
||||
const adCalls = findCallActiveDisplay('updateDoc');
|
||||
const last = adCalls[adCalls.length - 1];
|
||||
expect(last.data).toHaveProperty('hidePlayerHp');
|
||||
});
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('Encounter -> Firebase', () => {
|
||||
expect(call.path).toMatch(/campaigns\/[^/]+\/encounters\//);
|
||||
});
|
||||
|
||||
test('togglePlayerDisplay: setDoc merge on activeDisplay/status', async () => {
|
||||
test('togglePlayerDisplay: updateDoc patch on activeDisplay/status', async () => {
|
||||
await setupCampaignAndEncounter('Camp D', 'Enc D');
|
||||
await selectEncounterByName('Enc D');
|
||||
|
||||
@@ -50,33 +50,33 @@ describe('Encounter -> Firebase', () => {
|
||||
const eyeBtn = await screen.findByTitle('Activate for Player Display');
|
||||
fireEvent.click(eyeBtn);
|
||||
|
||||
await waitFor(() => findCall('setDoc', 'activeDisplay/status'));
|
||||
const call = findCall('setDoc', 'activeDisplay/status');
|
||||
// activeDisplay/status setDoc is called with merge option in App
|
||||
await waitFor(() => findCall('updateDoc', 'activeDisplay/status'));
|
||||
const call = findCall('updateDoc', 'activeDisplay/status');
|
||||
// BUG-4 fix: updateDoc patch, not setDoc replace (was clobbering fields)
|
||||
expect(call.data).toMatchObject({
|
||||
activeCampaignId: expect.any(String),
|
||||
activeEncounterId: expect.any(String),
|
||||
});
|
||||
});
|
||||
|
||||
test('togglePlayerDisplay off: setDoc nulls active ids', async () => {
|
||||
test('togglePlayerDisplay off: updateDoc nulls active ids', async () => {
|
||||
await setupCampaignAndEncounter('Camp O', 'Enc O');
|
||||
await selectEncounterByName('Enc O');
|
||||
|
||||
// turn ON
|
||||
const onBtn = await screen.findByTitle('Activate for Player Display');
|
||||
fireEvent.click(onBtn);
|
||||
await waitFor(() => findCall('setDoc', 'activeDisplay/status'));
|
||||
await waitFor(() => findCall('updateDoc', 'activeDisplay/status'));
|
||||
|
||||
// turn OFF
|
||||
const offBtn = await screen.findByTitle('Deactivate for Player Display');
|
||||
fireEvent.click(offBtn);
|
||||
await waitFor(() => {
|
||||
const calls = findCalls('setDoc', 'activeDisplay/status');
|
||||
const calls = findCalls('updateDoc', 'activeDisplay/status');
|
||||
const last = calls[calls.length - 1];
|
||||
return last.data.activeCampaignId === null;
|
||||
});
|
||||
const calls = findCalls('setDoc', 'activeDisplay/status');
|
||||
const calls = findCalls('updateDoc', 'activeDisplay/status');
|
||||
const last = calls[calls.length - 1];
|
||||
expect(last.data).toMatchObject({ activeCampaignId: null, activeEncounterId: null });
|
||||
});
|
||||
@@ -103,7 +103,7 @@ describe('Encounter -> Firebase', () => {
|
||||
// activate display first
|
||||
const onBtn = await screen.findByTitle('Activate for Player Display');
|
||||
fireEvent.click(onBtn);
|
||||
await waitFor(() => findCall('setDoc', 'activeDisplay/status'));
|
||||
await waitFor(() => findCall('updateDoc', 'activeDisplay/status'));
|
||||
|
||||
// delete the active encounter
|
||||
const trashBtn = screen.getAllByTitle('Delete Encounter')[0];
|
||||
|
||||
@@ -43,21 +43,21 @@ describe('BUG-4: hide-player-HP toggle preserves activeDisplay', () => {
|
||||
await selectCampaignByName('Camp');
|
||||
|
||||
// find the hide-player-HP toggle (role switch)
|
||||
const toggle = await screen.findByRole('switch', { name: /hide/i }, { timeout: 3000 });
|
||||
const toggle = await screen.findByRole('switch', { name: /hide player hp/i }, { timeout: 3000 });
|
||||
|
||||
// toggle ON
|
||||
fireEvent.click(toggle);
|
||||
|
||||
await waitFor(() => {
|
||||
const writes = getAdapterCalls().filter(
|
||||
c => c.fn === 'setDoc' && c.path.includes('activeDisplay/status')
|
||||
c => c.fn === 'updateDoc' && c.path.includes('activeDisplay/status')
|
||||
);
|
||||
expect(writes.length).toBeGreaterThan(0);
|
||||
const last = writes[writes.length - 1];
|
||||
// data written must include activeCampaignId AND activeEncounterId
|
||||
// BUG: writes only {hidePlayerHp:true}, clobbering them.
|
||||
expect(last.data.activeCampaignId).toBe('c1');
|
||||
expect(last.data.activeEncounterId).toBe('e1');
|
||||
// patch must NOT clobber activeCampaignId/activeEncounterId.
|
||||
// BUG: setDoc replace writes only {hidePlayerHp:true} → clobbers.
|
||||
// Fix: updateDoc patch — other fields untouched.
|
||||
expect(last.patch.hidePlayerHp).toBe(true);
|
||||
}, { timeout: 3000 });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user