teqo-backup/tests/unit/campaignHomeSummary.unit.spec.tsx
Cursor Agent 7a0f9ffed5
B111 — strip edge-to-edge bleed + silent flat delta on Início
- Allow horizontal bleed on home-actions retraction shell (overflow-y-hidden
  instead of overflow-hidden) so -mx-4 is not clipped by the chrome wrapper.
- Hide HomeSummaryDelta chip and period caption when delta is 0 or null;
  add shouldShowHomeSummaryDelta helper and unit pins.

Closes #150

Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
2026-08-01 20:36:19 +00:00

78 lines
2.3 KiB
TypeScript

import { cleanup, render, screen } from '@testing-library/react'
import { afterEach, describe, expect, it } from 'vitest'
import { CampaignHomeSummary } from '@/components/campaign/dashboard/CampaignHomeSummary'
afterEach(() => {
cleanup()
})
describe('CampaignHomeSummary', () => {
it('renders central staff vote total and coverage bar', () => {
render(
<CampaignHomeSummary
view={{
staffVoteTotalCentral: 125_430,
homeSummaryDelta: 5_000,
goalCoverage: {
goal: 200_000,
committed: 80_000,
coverageRatio: 0.4,
deficit: 120_000,
},
}}
/>,
)
expect(screen.getByRole('region', { name: 'Resumo da campanha' })).toBeTruthy()
expect(screen.getByText('Votos estimados')).toBeTruthy()
expect(screen.getByText('125.430')).toBeTruthy()
expect(screen.getByLabelText('Aumento de 5.000 votos nos últimos 7 dias')).toBeTruthy()
expect(screen.getByText('nos últimos 7 dias')).toBeTruthy()
expect(screen.getByText('Cobertura por lideranças')).toBeTruthy()
expect(screen.getByText('40%')).toBeTruthy()
expect(screen.getByRole('progressbar', { name: 'Cobertura por lideranças: 40%' })).toBeTruthy()
})
it('omits the progress bar when coverage is unknown', () => {
render(
<CampaignHomeSummary
view={{
staffVoteTotalCentral: 0,
homeSummaryDelta: null,
goalCoverage: {
goal: 0,
committed: 0,
coverageRatio: null,
deficit: 0,
},
}}
/>,
)
expect(screen.queryByLabelText(/nos últimos 7 dias/)).toBeNull()
expect(screen.queryByRole('progressbar')).toBeNull()
})
it('omits the delta chip and period caption when delta is flat', () => {
render(
<CampaignHomeSummary
view={{
staffVoteTotalCentral: 12_345,
homeSummaryDelta: 0,
goalCoverage: {
goal: 0,
committed: 0,
coverageRatio: null,
deficit: 0,
},
}}
/>,
)
expect(screen.getByText('12.345')).toBeTruthy()
expect(screen.queryByLabelText(/nos últimos 7 dias/)).toBeNull()
expect(screen.queryByText('nos últimos 7 dias')).toBeNull()
expect(screen.queryByText('0')).toBeNull()
})
})