import React from "react";
import { render, screen, fireEvent } from "@testing-library/react";
import { jest } from "@jest/globals";   
import PopupForAuditLogs from "../components/PopupForAuditLogs"; 

describe("PopupForAuditLogs Component", () => {
  const mockTogglePopup = jest.fn();

  const mockData = {
    changed_by: "John Doe",
    old_data: "Name: Yash, Age: 25, Country: India",
    new_data: "Name: Yash Khanna, Age: 26, Country: USA",
  };

  beforeEach(() => {
    jest.clearAllMocks();
  });


  it("displays the updated by text", () => {
    render(<PopupForAuditLogs togglePopup={mockTogglePopup} data={mockData} />);
    expect(screen.getByText(/Updated By/i)).toBeInTheDocument();
    expect(screen.getByText(/John Doe/i)).toBeInTheDocument();
  });


  it("calls togglePopup when close button is clicked", () => {
    render(<PopupForAuditLogs togglePopup={mockTogglePopup} data={mockData} />);
    const closeButton = screen.getByRole("button");
    fireEvent.click(closeButton);
    expect(mockTogglePopup).toHaveBeenCalledTimes(1);
  });

  
});
