mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-15 02:23:07 +00:00
Publish flow navigation from CampaignWizardShell via layout-level chrome so wizards no longer stack a second sticky header under the app bar.
82 lines
2.9 KiB
TypeScript
82 lines
2.9 KiB
TypeScript
import { cleanup, fireEvent, render, screen, within } from '@testing-library/react'
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { WizardExpectedVotesStep } from '@/components/campaign/shared/WizardExpectedVotesStep'
|
|
import { CampaignWizardChromeProvider } from '@/components/campaign/shell/CampaignWizardChromeContext'
|
|
|
|
const replace = vi.fn()
|
|
|
|
vi.mock('next/navigation', () => ({
|
|
useRouter: () => ({ replace }),
|
|
}))
|
|
|
|
vi.mock('next/link', () => ({
|
|
default: ({ children, href, ...props }: { children: React.ReactNode; href: string }) => (
|
|
<a href={href} {...props}>
|
|
{children}
|
|
</a>
|
|
),
|
|
}))
|
|
|
|
vi.mock('@/lib/campaignJsonRequest', () => ({
|
|
postCampaignJson: vi.fn(),
|
|
}))
|
|
|
|
const defaultProps = {
|
|
actionSlug: 'atualizar-votos',
|
|
municipalityId: 1,
|
|
municipalityName: 'Cairu',
|
|
municipalitySlug: 'cairu',
|
|
initialExpectedVotes: { pessimistic: 100, central: 200, optimistic: 300 },
|
|
}
|
|
|
|
const renderVotesStep = (props: React.ComponentProps<typeof WizardExpectedVotesStep>) =>
|
|
render(
|
|
<CampaignWizardChromeProvider>
|
|
<WizardExpectedVotesStep {...props} />
|
|
</CampaignWizardChromeProvider>,
|
|
)
|
|
|
|
describe('WizardExpectedVotesStep', () => {
|
|
afterEach(() => {
|
|
cleanup()
|
|
replace.mockClear()
|
|
})
|
|
|
|
it('shows violation banner on média immediately after pessimista breaks order', () => {
|
|
const { rerender } = renderVotesStep({ ...defaultProps, currentScenario: 'pessimistic' })
|
|
|
|
fireEvent.change(screen.getByLabelText(/Pessimista em Cairu/i), { target: { value: '900' } })
|
|
fireEvent.click(screen.getByRole('button', { name: 'Ajustar estimativa pessimista →' }))
|
|
|
|
expect(replace).toHaveBeenCalledWith(expect.stringContaining('cenario=central'))
|
|
|
|
rerender(
|
|
<CampaignWizardChromeProvider>
|
|
<WizardExpectedVotesStep {...defaultProps} currentScenario="central" />
|
|
</CampaignWizardChromeProvider>,
|
|
)
|
|
|
|
const step = screen.getByRole('main', { name: /Qual a nova estimativa média/i })
|
|
expect(within(step).getByRole('alert').textContent).toMatch(/Pessimista/i)
|
|
expect(within(step).getByRole('button', { name: /Voltar para pessimista/i })).toBeTruthy()
|
|
})
|
|
|
|
it('clears violation banner when média draft is edited', () => {
|
|
const { rerender } = renderVotesStep({ ...defaultProps, currentScenario: 'pessimistic' })
|
|
|
|
fireEvent.change(screen.getByLabelText(/Pessimista em Cairu/i), { target: { value: '900' } })
|
|
fireEvent.click(screen.getByRole('button', { name: 'Ajustar estimativa pessimista →' }))
|
|
rerender(
|
|
<CampaignWizardChromeProvider>
|
|
<WizardExpectedVotesStep {...defaultProps} currentScenario="central" />
|
|
</CampaignWizardChromeProvider>,
|
|
)
|
|
|
|
const step = screen.getByRole('main', { name: /Qual a nova estimativa média/i })
|
|
expect(within(step).getByRole('alert')).toBeTruthy()
|
|
|
|
fireEvent.change(screen.getByLabelText(/Média em Cairu/i), { target: { value: '250' } })
|
|
expect(within(step).queryByRole('alert')).toBeNull()
|
|
})
|
|
})
|