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

const instance: ServiceInstance = {
	id: "bkp-1",
	service_type: "backups",
	name: "Main Backups",
	config: { ingestion_label: "default" },
	secrets_set: {},
	enabled: true,
	created_at: 1_700_000_000,
	updated_at: 1_700_000_000,
};

vi.mock("../../../hooks/useBackups", () => ({
	useBackupJobs: () => ({
		data: [
			{
				id: "job-1",
				name: "nightly",
				source: "/data",
				target: "s3://bucket",
				schedule_interval_seconds: 86400,
				created_at: 1_700_000_000,
			},
		],
		isLoading: false,
	}),
	useBackupRuns: () => ({
		data: [],
		isLoading: false,
	}),
	useBackupAlerts: () => ({
		data: [],
		isLoading: false,
	}),
	useAcknowledgeAlert: () => ({ mutate: vi.fn() }),
}));

function renderTab() {
	return render(<JobsTab instance={instance} />);
}

describe("JobsTab", () => {
	it("renders the Jobs, Runs, and Alerts sub-tabs", () => {
		renderTab();
		expect(screen.getByRole("tab", { name: "Jobs" })).toBeInTheDocument();
		expect(screen.getByRole("tab", { name: "Runs" })).toBeInTheDocument();
		expect(screen.getByRole("tab", { name: /Alerts/ })).toBeInTheDocument();
	});

	it("renders the backup job name in the Jobs tab", () => {
		renderTab();
		expect(screen.getByText("nightly")).toBeInTheDocument();
	});
});
