import React from 'react';
import { render, screen } from '@testing-library/react';
import BarChart from '../components/Barchart.js';
import '@testing-library/jest-dom';

describe('BarChart', () => {
  const mockData = [
    {
      Results: [
        {
          LoginDate: '2023-05-15T09:00:00Z',
          StartedOn: '2023-05-15T09:00:00Z',
          ActiveCount: 5,
          IdleCount: 3,
          SleepCount: 2,
          LogInCount: 4,
          LogOutCount: 2,
          TotalCountActivity: 10,
          CallsCount: 7,
          ApplicationCount: 8
        }
      ]
    }
  ];

  it('renders with Sessions and "Active" selectedValue3', () => {
    render(<BarChart data={mockData} selectedValue="Sessions" selectedValue3="Active" />);
    expect(screen.getByTestId('mock-chart')).toBeInTheDocument();
  });

  it('renders with Sessions and "Idle" selectedValue3', () => {
    render(<BarChart data={mockData} selectedValue="Sessions" selectedValue3="Idle" />);
    expect(screen.getByTestId('mock-chart')).toBeInTheDocument();
  });

  it('renders with Sessions and default selectedValue3', () => {
    render(<BarChart data={mockData} selectedValue="Sessions" selectedValue3="Unknown" />);
    expect(screen.getByTestId('mock-chart')).toBeInTheDocument();
  });

  it('renders with Calls', () => {
    render(<BarChart data={mockData} selectedValue="Calls" selectedValue3="X" />);
    expect(screen.getByTestId('mock-chart')).toBeInTheDocument();
  });

  it('renders with Applications (default)', () => {
    render(<BarChart data={mockData} selectedValue="Apps" selectedValue3="X" />);
    expect(screen.getByTestId('mock-chart')).toBeInTheDocument();
  });

  it('shows fallback message when no data', () => {
    render(<BarChart data={[]} selectedValue="Sessions" selectedValue3="Active" />);
    expect(screen.getByText(/No Data found/i)).toBeInTheDocument();
  });

  it('renders with Sessions and "Sleep" selectedValue3', () => {
    render(<BarChart data={mockData} selectedValue="Sessions" selectedValue3="Sleep" />);
    expect(screen.getByTestId('mock-chart')).toBeInTheDocument();
  });

  it('renders with Sessions and "Login" selectedValue3', () => {
    render(<BarChart data={mockData} selectedValue="Sessions" selectedValue3="Log In" />);
    expect(screen.getByTestId('mock-chart')).toBeInTheDocument();
  });

  it('renders with Sessions and "Logout" selectedValue3', () => {
    render(<BarChart data={mockData} selectedValue="Sessions" selectedValue3="Log Out" />);
    expect(screen.getByTestId('mock-chart')).toBeInTheDocument();
  });
});
