M2: refactor DisplayView to storage adapter (red test first)

DisplayView missed in original M2 refactor — raw onSnapshot(doc(db,path))
survived. In ws/memory mode db is a stub sentinel, so raw SDK calls crash
('Expected first argument to collection() to be a CollectionReference...').
Reported by human testing player display after start combat.

TDD:
1. RED: DisplayView.characterization.test.js asserts adapter.subscribeDoc
   called for campaign + encounter + activeDisplay paths. Adapter recorder
   (getAdapterCalls/resetAdapterCalls in firebase.js) instruments subscribe
   calls — catches raw-SDK bypass that firebase mock alone cannot (mock db
   satisfies raw onSnapshot, hiding the bug).
2. Fix: 2 raw onSnapshot sites in DisplayView -> storage.subscribeDoc.
3. GREEN: 2 new tests pass, 116 total green.

Audit confirmed DisplayView was the ONLY remaining raw SDK site in App.js.
This commit is contained in:
david raistrick
2026-06-29 13:13:46 -04:00
parent 52866784b2
commit 84a8b78acd
3 changed files with 79 additions and 22 deletions
+10 -22
View File
@@ -2453,35 +2453,23 @@ function DisplayView() {
setIsLoadingEncounter(true);
setEncounterError(null);
const campaignDocRef = doc(db, getPath.campaign(activeCampaignId));
unsubscribeCampaign = onSnapshot(
campaignDocRef,
(campSnap) => {
if (campSnap.exists()) {
setCampaignBackgroundUrl(campSnap.data().playerDisplayBackgroundUrl || '');
} else {
setCampaignBackgroundUrl('');
}
},
(err) => console.error("Error fetching campaign background:", err)
unsubscribeCampaign = storage.subscribeDoc(
getPath.campaign(activeCampaignId),
(camp) => {
setCampaignBackgroundUrl((camp && camp.playerDisplayBackgroundUrl) || '');
}
);
const encounterPath = getPath.encounter(activeCampaignId, activeEncounterId);
unsubscribeEncounter = onSnapshot(
doc(db, encounterPath),
(encDocSnap) => {
if (encDocSnap.exists()) {
setActiveEncounterData({ id: encDocSnap.id, ...encDocSnap.data() });
unsubscribeEncounter = storage.subscribeDoc(
getPath.encounter(activeCampaignId, activeEncounterId),
(enc) => {
if (enc) {
setActiveEncounterData({ id: activeEncounterId, ...enc });
} else {
setActiveEncounterData(null);
setEncounterError("Active encounter data not found.");
}
setIsLoadingEncounter(false);
},
(err) => {
console.error("Error fetching active encounter details:", err);
setEncounterError("Error loading active encounter data.");
setIsLoadingEncounter(false);
}
);
} else {