diff --git a/src/components/campaign/municipality/MunicipalityListLevelControl.tsx b/src/components/campaign/municipality/MunicipalityListLevelControl.tsx index c40cd2de..771cc63d 100644 --- a/src/components/campaign/municipality/MunicipalityListLevelControl.tsx +++ b/src/components/campaign/municipality/MunicipalityListLevelControl.tsx @@ -12,7 +12,6 @@ import { useCampaignCellFailureChannel } from '@/components/campaign/shared/useC import { Alert, AlertDescription } from '@/components/ui/Alert' import { Button } from '@/components/ui/button' import { Checkbox } from '@/components/ui/Checkbox' -import { DrawerCloseButton } from '@/components/ui/Drawer' import { Field, FieldContent, FieldLabel } from '@/components/ui/field' import { NativeSelect, NativeSelectOption } from '@/components/ui/native-select' import { Spinner } from '@/components/ui/Spinner' @@ -239,7 +238,14 @@ export const MunicipalityListLevelControl = ({ isSheet && open ? ( <> {submitButton} - Cancelar + ) : undefined } diff --git a/src/components/campaign/municipality/MunicipalityListSignalControl.tsx b/src/components/campaign/municipality/MunicipalityListSignalControl.tsx index 2cbe9adf..40c6d409 100644 --- a/src/components/campaign/municipality/MunicipalityListSignalControl.tsx +++ b/src/components/campaign/municipality/MunicipalityListSignalControl.tsx @@ -10,7 +10,6 @@ import { import { CampaignFormActionMessage } from '@/components/campaign/shared/CampaignFormActionMessage' import { useCampaignFormSuccessToast } from '@/components/campaign/shared/useCampaignFormSuccessToast' import { Button } from '@/components/ui/button' -import { DrawerCloseButton } from '@/components/ui/Drawer' import { Spinner } from '@/components/ui/Spinner' import type { CampaignFormActionState } from '@/utilities/campaignFormActionError' import { @@ -85,7 +84,14 @@ export const MunicipalityListSignalControl = ({ isSheet && open ? ( <> {submitButton} - Cancelar + ) : undefined } diff --git a/src/components/campaign/shared/CampaignCellEditOverlay.tsx b/src/components/campaign/shared/CampaignCellEditOverlay.tsx index 9bb86bc6..3ac83fc6 100644 --- a/src/components/campaign/shared/CampaignCellEditOverlay.tsx +++ b/src/components/campaign/shared/CampaignCellEditOverlay.tsx @@ -204,6 +204,7 @@ export const CampaignCellEditOverlay = ({ {triggerButton} {liveRegion} {showPortals && bodyTarget ? createPortal(children, bodyTarget) : null} + {/* Portaled footer is outside the Drawer React tree — no DrawerCloseButton (B119). */} {showPortals && footerTarget && footer ? createPortal(footer, footerTarget) : null} ) diff --git a/tests/e2e/campaignMunicipalities.e2e.spec.ts b/tests/e2e/campaignMunicipalities.e2e.spec.ts index 3df22418..0f322a09 100644 --- a/tests/e2e/campaignMunicipalities.e2e.spec.ts +++ b/tests/e2e/campaignMunicipalities.e2e.spec.ts @@ -424,6 +424,33 @@ test.describe('Municípios — cards no celular (B42)', () => { await expect(page).toHaveURL(`${campaign.baseURL}/campanha/municipios/${municipality.slug}`) await expect(page.getByRole('heading', { name: municipality.name })).toBeVisible() }) + + test('opens the nivel Drawer without navigating or crashing (B119)', async ({ + campaign, + page, + }) => { + const { fixtures } = campaign + const coordinator = await fixtures.createCampaignUser('coordinator', { + name: fixtures.value('Coordenador Mobile Nivel'), + }) + const municipality = await fixtures.claimMunicipality() + + await campaign.login(page, coordinator.email!, coordinator.password) + const listURL = `${campaign.baseURL}/campanha/municipios?q=${encodeURIComponent(municipality.name)}` + await page.goto(listURL) + + const card = page.locator('[data-view="mobile-cards"] article').first() + await expect(card).toBeVisible() + + await card.getByRole('button', { name: 'Nível de envolvimento' }).click() + const drawer = page.getByRole('dialog', { name: 'Registrar nível de envolvimento' }) + await expect(drawer).toBeVisible() + await expect(drawer.getByText(municipality.name, { exact: true })).toBeVisible() + await expect(page).toHaveURL(listURL) + + await drawer.getByRole('button', { name: 'Cancelar' }).click() + await expect(drawer).toBeHidden() + }) }) /** diff --git a/tests/unit/campaignCellEditOverlay.unit.spec.ts b/tests/unit/campaignCellEditOverlay.unit.spec.ts index b9455b4c..e40d0f25 100644 --- a/tests/unit/campaignCellEditOverlay.unit.spec.ts +++ b/tests/unit/campaignCellEditOverlay.unit.spec.ts @@ -8,6 +8,7 @@ import { MunicipalityListLevelControl } from '@/components/campaign/municipality import { MunicipalityListSignalControl } from '@/components/campaign/municipality/MunicipalityListSignalControl' import { MunicipalityListTrendControl } from '@/components/campaign/municipality/MunicipalityListTrendControl' import type { CampaignCellEditOverlayVariant } from '@/components/campaign/shared/CampaignCellEditOverlay' +import { CampaignListSheetProvider } from '@/components/campaign/shared/CampaignListSheetHost' import { MunicipalityPortfolioCell } from '@/components/campaign/shared/MunicipalityPortfolioCell' import { TooltipProvider } from '@/components/ui/tooltip' import { toVoteEstimateScenarioViewModel } from '@/lib/voteEstimate' @@ -179,6 +180,27 @@ describe('campaign cell edit overlay', () => { }, ) + /** + * B119: the mobile cards host ONE shared Drawer (`CampaignListSheetProvider`) + * and portal cell footers into it. `DrawerCloseButton` must stay inside the + * Drawer React tree — portaled footers call `onOpenChange(false)` instead. + */ + it('opens the nivel sheet through CampaignListSheetProvider without crashing', async () => { + const nivelCase = overlayCases.find((item) => item.name === 'nível de envolvimento') + expect(nivelCase).toBeDefined() + + renderWithTooltip(createElement(CampaignListSheetProvider, null, nivelCase!.element('sheet'))) + + fireEvent.click(screen.getByRole('button', { name: nivelCase!.triggerLabel })) + + const dialog = await screen.findByRole('dialog') + expect(dialog.querySelector('[data-slot="drawer-title"]')?.textContent).toBe( + nivelCase!.drawerTitle, + ) + expect(dialog.textContent).toContain('Cancelar') + expect(dialog.textContent).toContain(nivelCase!.footerLabel) + }) + it.each(overlayCases)( 'keeps $name in a Popover on the desktop table', async ({ triggerLabel, element }) => {