/// <reference types="vitest" />
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { render, screen } from "@testing-library/react";
import TradingViewChart from "../TradingViewChart";

// Mock lightweight-charts
vi.mock("lightweight-charts", () => ({
  createChart: vi.fn(() => ({
    addSeries: vi.fn(() => ({
      setData: vi.fn(),
    })),
    remove: vi.fn(),
  })),
  CandlestickSeries: {},
}));

describe("TradingViewChart", () => {
  it("renders the ticker symbol as heading", () => {
    render(<TradingViewChart ticker="AAPL" />);
    expect(screen.getByText("AAPL Price Chart")).toBeInTheDocument();
  });

  it("renders without data prop", () => {
    render(<TradingViewChart ticker="MSFT" />);
    expect(screen.getByText("MSFT Price Chart")).toBeInTheDocument();
  });

  it("renders with data prop", () => {
    const data = [
      { time: "2024-01-01", open: 100, high: 110, low: 95, close: 105 },
      { time: "2024-01-02", open: 105, high: 115, low: 100, close: 110 },
    ];
    render(<TradingViewChart ticker="GOOGL" data={data} />);
    expect(screen.getByText("GOOGL Price Chart")).toBeInTheDocument();
  });
});