Lab 3 Terminal UI

This commit is contained in:
2026-04-13 12:10:19 -06:00
parent 9f3af49845
commit 7e4d35b6a3
8 changed files with 479 additions and 3 deletions
@@ -0,0 +1,60 @@
import { fireEvent, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it } from "vitest";
import {
LAB3_DEFAULT_TERMINAL_PATH,
Lab3TerminalFrame,
getLab3TerminalPath,
} from "~/components/labs/Lab3TerminalFrame";
describe("getLab3TerminalPath", () => {
it("falls back to the default same-origin terminal path", () => {
expect(getLab3TerminalPath()).toBe(LAB3_DEFAULT_TERMINAL_PATH);
expect(getLab3TerminalPath("")).toBe(LAB3_DEFAULT_TERMINAL_PATH);
});
it("normalizes relative and absolute terminal values to a same-origin path", () => {
expect(getLab3TerminalPath("wetty")).toBe("/wetty");
expect(getLab3TerminalPath("https://labs.example.com/wetty?view=lab3")).toBe(
"https://labs.example.com/wetty?view=lab3",
);
});
});
describe("Lab3TerminalFrame", () => {
const originalEnvValue = process.env.NEXT_PUBLIC_LAB3_TERMINAL_PATH;
afterEach(() => {
process.env.NEXT_PUBLIC_LAB3_TERMINAL_PATH = originalEnvValue;
});
it("renders the embedded terminal with the configured path", () => {
process.env.NEXT_PUBLIC_LAB3_TERMINAL_PATH = "lab-terminal";
render(<Lab3TerminalFrame />);
const frame = screen.getByTitle("Lab 3 terminal session");
expect(frame).toHaveAttribute("src", "/lab-terminal");
expect(
screen.getAllByRole("link", { name: "Open in New Tab" }).every((link) => {
return link.getAttribute("href") === "/lab-terminal";
}),
).toBe(true);
expect(screen.getAllByText("/home/student/lab3")).toHaveLength(2);
});
it("toggles the dock open and closed", () => {
render(<Lab3TerminalFrame srcPath="/wetty" />);
const toggle = screen.getAllByRole("button", { name: /open terminal|hide terminal|lab 3 terminal/i })[0];
expect(toggle).toHaveAttribute("aria-expanded", "false");
fireEvent.click(toggle);
expect(toggle).toHaveAttribute("aria-expanded", "true");
});
it("renders fallback guidance alongside the embedded frame", () => {
render(<Lab3TerminalFrame srcPath="/wetty" />);
expect(screen.getByText(/If the terminal page does not appear/i)).toBeInTheDocument();
});
});