import { describe, expect, it, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import { Settings } from "../Settings";

vi.mock("../../hooks/useSettings", () => ({
	useSSHKeys: () => ({ data: [] }),
	useResetLocalDatabase: () => ({}),
	useSaveSSHKey: () => ({ mutateAsync: vi.fn() }),
	useGenerateSSHKey: () => ({ mutateAsync: vi.fn(), isPending: false }),
	useDeleteSSHKey: () => ({ mutate: vi.fn() }),
}));

vi.mock("../../hooks/useServices", () => ({
	useServiceInstances: () => ({ data: [] }),
	useServiceTypes: () => ({ data: [] }),
	useSaveServiceInstance: () => ({ mutateAsync: vi.fn(), isPending: false }),
	useDeleteServiceInstance: () => ({ mutate: vi.fn() }),
	useTestServiceInstance: () => ({ mutateAsync: vi.fn(), isPending: false }),
}));

describe("Settings", () => {
	it("uses Services instead of a standalone Machines tab", () => {
		render(
			<MemoryRouter>
				<Settings />
			</MemoryRouter>,
		);

		expect(screen.getByRole("tab", { name: "Services" })).toBeInTheDocument();
		expect(screen.getByRole("tab", { name: "SSH Keys" })).toBeInTheDocument();
		expect(
			screen.queryByRole("tab", { name: "Machines" }),
		).not.toBeInTheDocument();
		expect(
			screen.getByText("No service instances configured yet."),
		).toBeInTheDocument();
	});
});
