import React from 'react';
import { render, screen } from '@testing-library/react';
import PieChart from '../utils/PieCharts.js';
import '@testing-library/jest-dom';

describe('PieChart', () => {
  const baseData = [
    {
      Results: [
        { SystemStatus: 'Online', Count: 10, EmpCode: 'E1', CallsCount: 5, ApplicationName: 'App1', ApplicationCount: 7 },
        { SystemStatus: 'Offline', Count: 20, EmpCode: 'E2', CallsCount: 10, ApplicationName: 'App2', ApplicationCount: 12 },
      ]
    }
  ];

  it('renders the pie chart when valid data is provided', () => {
    render(<PieChart data={baseData} selectedValue="Sessions" selectedValue3="X" />);
    expect(screen.getByTestId('mock-chart')).toBeInTheDocument();
  });

  it('renders "No Data found" when data is empty', () => {
    render(<PieChart data={[]} selectedValue="Sessions" selectedValue3="X" />);
    expect(screen.getByText(/No Data found/i)).toBeInTheDocument();
  });

  it('renders different data for "Calls" view', () => {
    render(<PieChart data={baseData} selectedValue="Calls" selectedValue3="X" />);
    expect(screen.getByTestId('mock-chart')).toBeInTheDocument();
  });

  it('renders different data for default view', () => {
    render(<PieChart data={baseData} selectedValue="Other" selectedValue3="X" />);
    expect(screen.getByTestId('mock-chart')).toBeInTheDocument();
  });
});
