1ad2fec073
YouTube, Google and login pages refuse framing and the browser draws a broken-page icon; the hint lived only in the empty state. A page not on this machine now gets a strip under the address bar with Open tab. The refused- address toast says what is allowed in plain words.
60 lines
2.6 KiB
TypeScript
60 lines
2.6 KiB
TypeScript
/**
|
|
* @file UrlPreview.test.tsx
|
|
* @description The Preview tab: port chips before a page is open, the
|
|
* address bar opening a page in a sandboxed frame without top navigation,
|
|
* a link's request opening its page, the dashboard's own origin refused, and
|
|
* the framing-refusal strip shown for an outside site only.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import "../../../i18n";
|
|
import { UrlPreview } from "../UrlPreview";
|
|
|
|
beforeEach(() => window.localStorage.clear());
|
|
|
|
describe("UrlPreview", () => {
|
|
it("offers the workspace's ports, and a chip opens that page", () => {
|
|
render(<UrlPreview laneId={1} ports={{ web: 3001 }} request={null} />);
|
|
fireEvent.click(screen.getByText("localhost:3001"));
|
|
const frame = screen.getByTestId("url-preview-frame");
|
|
expect(frame.getAttribute("src")).toBe("http://localhost:3001/");
|
|
expect(frame.getAttribute("sandbox")).not.toMatch(/top-navigation/);
|
|
expect(window.localStorage.getItem("agenthub.preview.url.1")).toBe("http://localhost:3001/");
|
|
});
|
|
|
|
it("opens what the address bar names, and refuses the dashboard itself", () => {
|
|
render(<UrlPreview laneId={2} ports={{}} request={null} />);
|
|
const input = screen.getByRole("textbox");
|
|
fireEvent.change(input, { target: { value: window.location.origin + "/settings" } });
|
|
fireEvent.keyDown(input, { key: "Enter" });
|
|
expect(screen.queryByTestId("url-preview-frame")).toBeNull();
|
|
fireEvent.change(input, { target: { value: "127.0.0.1:8080/app" } });
|
|
fireEvent.keyDown(input, { key: "Enter" });
|
|
expect(screen.getByTestId("url-preview-frame").getAttribute("src")).toBe(
|
|
"http://127.0.0.1:8080/app"
|
|
);
|
|
});
|
|
|
|
it("warns that an outside site may refuse to be framed, never for a local page", () => {
|
|
render(<UrlPreview laneId={4} ports={{}} request={null} />);
|
|
const input = screen.getByRole("textbox");
|
|
fireEvent.change(input, { target: { value: "localhost:3000" } });
|
|
fireEvent.keyDown(input, { key: "Enter" });
|
|
expect(screen.queryByTestId("url-preview-blocked-hint")).toBeNull();
|
|
fireEvent.change(input, { target: { value: "https://youtube.com" } });
|
|
fireEvent.keyDown(input, { key: "Enter" });
|
|
expect(screen.getByTestId("url-preview-blocked-hint")).toBeTruthy();
|
|
});
|
|
|
|
it("opens a link's request", () => {
|
|
render(
|
|
<UrlPreview laneId={3} ports={{}} request={{ url: "http://localhost:5173/", nonce: 1 }} />
|
|
);
|
|
expect(screen.getByTestId("url-preview-frame").getAttribute("src")).toBe(
|
|
"http://localhost:5173/"
|
|
);
|
|
});
|
|
});
|