// @vitest-environment jsdom // Copyright: © 2026 TWWIM UG. All rights reserved. (www.twwim.com) /** * Unit tests for RequestContactButton. * * Asserts the disabled-when-not-intercepted guard and the mutate-on-click * happy path. Mocks the mutation hook + translation provider so this stays * a pure render+interaction test. */ import { describe, it, expect, vi, afterEach } from 'vitest'; import { cleanup, fireEvent, render } from '@testing-library/react'; const mutateMock = vi.fn(); vi.mock('../hooks/useRequestContactMutation', () => ({ useRequestContactMutation: () => ({ mutate: mutateMock, isPending: false, }), })); vi.mock('@/i18n/TranslationProvider', () => ({ useTranslation: () => ({ t: (key: string) => key, locale: 'en' as const, setLocale: () => undefined, }), })); import { RequestContactButton } from './RequestContactButton'; afterEach(() => { cleanup(); mutateMock.mockReset(); }); describe('RequestContactButton', () => { it('is disabled when status is active', () => { const { getByTestId } = render( , ); const button = getByTestId('request-contact-btn') as HTMLButtonElement; expect(button.disabled).toBe(true); }); it('is disabled when status is idle', () => { const { getByTestId } = render( , ); const button = getByTestId('request-contact-btn') as HTMLButtonElement; expect(button.disabled).toBe(true); }); it('is disabled when status is closed', () => { const { getByTestId } = render( , ); const button = getByTestId('request-contact-btn') as HTMLButtonElement; expect(button.disabled).toBe(true); }); it('is enabled when status is intercepted', () => { const { getByTestId } = render( , ); const button = getByTestId('request-contact-btn') as HTMLButtonElement; expect(button.disabled).toBe(false); }); it('calls the mutation with the conversationId on click', () => { const { getByTestId } = render( , ); fireEvent.click(getByTestId('request-contact-btn')); expect(mutateMock).toHaveBeenCalledTimes(1); expect(mutateMock).toHaveBeenCalledWith('conv-42'); }); it('does not call the mutation when disabled', () => { const { getByTestId } = render( , ); fireEvent.click(getByTestId('request-contact-btn')); expect(mutateMock).not.toHaveBeenCalled(); }); });