import { renderHook, act } from '@testing-library/react-native' import { Alert } from 'react-native' import { useVideoModerationJoltEvents } from '../../hooks/use_video_moderation_jolt_events' jest.mock('../../hooks/use_api', () => ({ useApiGet: jest.fn().mockReturnValue({ data: { id: 42 } }), })) const joltEventCallbacks: Record void> = {} jest.mock('../../hooks/use_jolt', () => ({ useJoltChannel: jest.fn().mockReturnValue('channel-stub'), useJoltEvent: jest.fn((_channel, eventName, callback) => { joltEventCallbacks[eventName] = callback }), })) const alertSpy = jest.spyOn(Alert, 'alert').mockImplementation(() => {}) beforeEach(() => { jest.useFakeTimers() alertSpy.mockClear() Object.keys(joltEventCallbacks).forEach(k => delete joltEventCallbacks[k]) }) afterEach(() => { jest.useRealTimers() }) const flaggedEvent = (attachment_id: string, content_type: string) => ({ event: 'attachment.flagged', data: { data: { attachment_id, conversation_id: 1, content_type } }, }) describe('useVideoModerationJoltEvents', () => { it('alerts when a video attachment.flagged event fires', () => { renderHook(() => useVideoModerationJoltEvents()) act(() => { joltEventCallbacks['attachment.flagged'](flaggedEvent('att-1', 'video/mp4')) jest.advanceTimersByTime(500) }) expect(alertSpy).toHaveBeenCalledWith('Video removed', expect.stringContaining('video')) }) it('does not alert for non-video content types', () => { renderHook(() => useVideoModerationJoltEvents()) act(() => { joltEventCallbacks['attachment.flagged'](flaggedEvent('att-1', 'image/jpeg')) jest.advanceTimersByTime(500) }) expect(alertSpy).not.toHaveBeenCalled() }) it('rolls multiple video events into a single alert with plural copy', () => { renderHook(() => useVideoModerationJoltEvents()) act(() => { joltEventCallbacks['attachment.flagged'](flaggedEvent('att-1', 'video/mp4')) joltEventCallbacks['attachment.flagged'](flaggedEvent('att-2', 'video/quicktime')) jest.advanceTimersByTime(500) }) expect(alertSpy).toHaveBeenCalledTimes(1) expect(alertSpy).toHaveBeenCalledWith('Video removed', expect.stringContaining('videos')) }) it('suppresses the alert when markHandledByMessageForm is called for that id', () => { const { result } = renderHook(() => useVideoModerationJoltEvents()) act(() => { joltEventCallbacks['attachment.flagged'](flaggedEvent('att-1', 'video/mp4')) result.current.markHandledByMessageForm('att-1') jest.advanceTimersByTime(500) }) expect(alertSpy).not.toHaveBeenCalled() }) })