import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import { MetricsTab } from "../MetricsTab";
import type { ServiceInstance } from "../../../types";

const instance: ServiceInstance = {
	id: "prom-1",
	service_type: "prometheus",
	name: "Main Prometheus",
	config: { base_url: "https://prom.example.com", timeout_seconds: 10 },
	secrets_set: {},
	enabled: true,
	created_at: 1_700_000_000,
	updated_at: 1_700_000_000,
};

vi.mock("../../../hooks/useObservability", () => ({
	usePrometheusStatus: () => ({
		data: {
			up: true,
			version: "2.52.0",
			service_id: "prom-1",
			name: "Main Prometheus",
		},
		isLoading: false,
		error: null,
	}),
	usePrometheusTargets: () => ({
		data: [
			{
				targets: ["10.0.0.5:9100"],
				labels: { instance: "storage", job: "node_exporter" },
			},
		],
		isLoading: false,
		error: null,
	}),
}));

describe("MetricsTab", () => {
	it("renders the Prometheus version and target list", () => {
		render(<MetricsTab instance={instance} />);
		expect(screen.getByText(/version 2\.52\.0/)).toBeInTheDocument();
		expect(screen.getByText("10.0.0.5:9100")).toBeInTheDocument();
	});

	it("renders the target count in the heading", () => {
		render(<MetricsTab instance={instance} />);
		expect(screen.getByText(/Node Exporter Targets \(1\)/)).toBeInTheDocument();
	});
});
