import React from 'react';
import { vi, describe, it, expect } from 'vitest';
import userEvent from '@testing-library/user-event';
import { render, screen } from '@testing-library/react';
import { navigate } from '@openmrs/esm-framework';
import { mockPatient } from '__mocks__';
import EditPatientDetailsButton from './edit-patient-details-button.component';

const mockNavigate = vi.mocked(navigate);

describe('EditPatientDetailsButton', () => {
  const patientUuid = mockPatient.uuid;

  it('renders button with correct text', () => {
    render(<EditPatientDetailsButton patientUuid={patientUuid} />);

    expect(screen.getByRole('menuitem')).toBeInTheDocument();
    expect(screen.getByText(/edit patient details/i)).toBeInTheDocument();
  });

  it('navigates to edit page when clicked', async () => {
    const user = userEvent.setup();
    render(<EditPatientDetailsButton patientUuid={patientUuid} />);

    const button = screen.getByRole('menuitem');
    await user.click(button);

    expect(mockNavigate).toHaveBeenCalledWith({
      to: expect.stringContaining(`/patient/${patientUuid}/edit`),
    });
    expect(mockNavigate).toHaveBeenCalledTimes(1);
  });
});
