import { fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { App } from "./App";

describe("Teamserver 工作区", () => {
  it("切换服务器时只显示对应服务器标签，并恢复各自激活标签", () => {
    render(<App />);
    expect(screen.getByRole("tab", { name: /Session Overview/ })).toBeInTheDocument();
    fireEvent.click(screen.getByRole("tab", { name: /Session Overview/ }));
    fireEvent.click(screen.getByRole("button", { name: "切换到 Ember Lab" }));
    expect(screen.queryByRole("tab", { name: /Session Overview/ })).not.toBeInTheDocument();
    expect(screen.getByRole("tab", { name: /Task Output/ })).toBeInTheDocument();
    fireEvent.click(screen.getByRole("button", { name: "切换到 Atlas Teamserver" }));
    expect(screen.getByRole("tab", { name: /Session Overview/ })).toHaveAttribute("aria-selected", "true");
  });

  it("显示锁定上下文和高密度 Session 表格", () => {
    render(<App />);
    expect(screen.getByLabelText("锁定的操作上下文")).toHaveTextContent("Atlas Teamserver / Northwind / All sessions / Sessions");
    expect(screen.getByLabelText("Session 表格")).toBeInTheDocument();
    expect(screen.getByText("NW-042")).toBeInTheDocument();
    expect(screen.getByText("10.42.8.17")).toBeInTheDocument();
  });
});
