teqo-backup/tests/unit/speechExcerptCta.unit.spec.tsx
Francisco Solla f066bee92b
Some checks are pending
Deploy / preflight (push) Waiting to run
Deploy / verify (push) Blocked by required conditions
Deploy / deploy staging (teqo-staging) (push) Blocked by required conditions
Deploy / requeue when main advanced (push) Blocked by required conditions
Deploy / deploy production (teqo-1313) (push) Blocked by required conditions
feat(C174): encontrar cortes — navegação, na fala e na busca (Closes #1084)
2026-09-16 12:58:40 -03:00

37 lines
1.3 KiB
TypeScript

import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { SpeechExcerptCta } from '@/components/campaign/speech/SpeechExcerptCta'
import { SPEECH_EXCERPT_REQUEST_EVENT } from '@/lib/speechExcerptSelection'
const originalScrollIntoView = Element.prototype.scrollIntoView
afterEach(() => {
cleanup()
// jsdom has no scrollIntoView; the stub is restored so it cannot leak.
if (originalScrollIntoView) Element.prototype.scrollIntoView = originalScrollIntoView
else delete (Element.prototype as { scrollIntoView?: unknown }).scrollIntoView
})
describe('SpeechExcerptCta (C174)', () => {
it('announces the excerpt intent and scrolls the player into view', () => {
const scrollIntoView = vi.fn()
Element.prototype.scrollIntoView = scrollIntoView
const listened = vi.fn()
window.addEventListener(SPEECH_EXCERPT_REQUEST_EVENT, listened)
render(
<>
<div data-slot="speech-player" />
<SpeechExcerptCta />
</>,
)
fireEvent.click(screen.getByRole('button', { name: /selecionar trecho/i }))
expect(listened).toHaveBeenCalledTimes(1)
expect(scrollIntoView).toHaveBeenCalledWith({ block: 'start' })
window.removeEventListener(SPEECH_EXCERPT_REQUEST_EVENT, listened)
})
})