diff --git a/src/App.js b/src/App.js index b6599bf..f5965a9 100644 --- a/src/App.js +++ b/src/App.js @@ -1329,8 +1329,7 @@ function EffectModal({ encounter, defaultScope, defaultTargetParticipantId, onCl ); } -function EffectControlRow({ effect, participants, onAdjust, onSet, onRemove }) { - const owner = participants.find(p => p.id === effect.ownerParticipantId); +function EffectControlRow({ effect, participants, onAdjust, onSet, onSetOwner, onRemove }) { const [draftRounds, setDraftRounds] = useState(String(effect.remainingRounds)); useEffect(() => setDraftRounds(String(effect.remainingRounds)), [effect.remainingRounds]); const commitRounds = () => { @@ -1357,7 +1356,18 @@ function EffectControlRow({ effect, participants, onAdjust, onSet, onRemove }) { /> rounds - {owner && Owner: {owner.name}} + {effect.expiresOnDamage && Ends on damage} @@ -1788,7 +1798,7 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp } else if (presetId === 'spiritual_weapon') { await combatAddEffect(encounter, { presetId: 'spiritual_weapon', name: 'Spiritual Weapon', scope: 'encounter', - ownerParticipantId: participant.id, + ownerParticipantId: encounter.currentTurnParticipantId || participant.id, remainingRounds: 10, expiresOnDamage: false, playerDisplay: 'prominent', createdRound: encounter.round || 0, }, buildCtx(encounterPath)); @@ -1817,6 +1827,15 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp } }; + const handleSetEffectOwner = async (effect, ownerParticipantId) => { + if (!db) return; + try { + await combatUpdateEffect(encounter, effect.id, { ownerParticipantId }, buildCtx(encounterPath)); + } catch (err) { + showToast(err.message || 'Failed to update effect owner.'); + } + }; + const handleRemoveEffect = async (effect) => { if (!db) return; try { @@ -2114,7 +2133,7 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp

Encounter Effects

{(encounter.effects || []).filter(effect => effect.scope === 'encounter' && (!effect.ownerParticipantId || !participants.some(p => p.id === effect.ownerParticipantId))).map(effect => ( - + ))}
)} @@ -2352,7 +2371,7 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp (effect.scope === 'participant' && effect.targetParticipantId === p.id) || (effect.scope === 'encounter' && effect.ownerParticipantId === p.id) ).map(effect => ( - + ))} {/* Expandable conditions picker */} diff --git a/src/tests/TrackedEffects.test.js b/src/tests/TrackedEffects.test.js index c6fd5d2..5605cf5 100644 --- a/src/tests/TrackedEffects.test.js +++ b/src/tests/TrackedEffects.test.js @@ -2,7 +2,7 @@ import { screen, fireEvent, waitFor, within } from '@testing-library/react'; import '@testing-library/jest-dom'; import { setupReady, addMonsterViaUI, renderApp, createCampaignViaUI, - selectCampaignByName, selectEncounterByName, MOCK_DB, + selectCampaignByName, selectEncounterByName, startCombatViaUI, MOCK_DB, } from './testHelpers'; function latestEncounter() { @@ -57,16 +57,27 @@ describe('tracked effects DM UI', () => { test('Spiritual Weapon preset creates 10-round encounter effect', async () => { await setupReady('Weapon Camp', 'Weapon Encounter'); await addMonsterViaUI('Cleric', 30, 2); + await addMonsterViaUI('Wizard', 24, 3); - fireEvent.click(screen.getByRole('button', { name: 'Open conditions' })); + await startCombatViaUI(); + const activeId = latestEncounter().currentTurnParticipantId; + const otherId = latestEncounter().participants.find(p => p.id !== activeId).id; + fireEvent.click(within(screen.getByTestId(`admin-participant-card-${otherId}`)).getByRole('button', { name: 'Open conditions' })); fireEvent.click(screen.getByRole('button', { name: 'Spiritual Weapon' })); await waitFor(() => expect(latestEncounter().effects[0]).toMatchObject({ presetId: 'spiritual_weapon', name: 'Spiritual Weapon', scope: 'encounter', - remainingRounds: 10, expiresOnDamage: false, playerDisplay: 'prominent', + ownerParticipantId: activeId, remainingRounds: 10, + expiresOnDamage: false, playerDisplay: 'prominent', })); - const clericId = latestEncounter().participants.find(p => p.name === 'Cleric').id; - expect(within(screen.getByTestId(`admin-participant-card-${clericId}`)).getByText('SPIRITUAL WEAPON')).toBeInTheDocument(); + expect(within(screen.getByTestId(`admin-participant-card-${activeId}`)).getByText('SPIRITUAL WEAPON')).toBeInTheDocument(); + + const ownerSelect = screen.getByLabelText('Owner for Spiritual Weapon'); + expect(ownerSelect).toHaveValue(activeId); + fireEvent.change(ownerSelect, { target: { value: otherId } }); + await waitFor(() => expect(latestEncounter().effects[0].ownerParticipantId).toBe(otherId)); + expect(within(screen.getByTestId(`admin-participant-card-${otherId}`)).getByText('SPIRITUAL WEAPON')).toBeInTheDocument(); + expect(within(screen.getByTestId(`admin-participant-card-${activeId}`)).queryByText('SPIRITUAL WEAPON')).not.toBeInTheDocument(); }); test('generic ruleset offers custom effects only and rounds only', async () => {