import { describe, expect, it } from "vitest";
import { landingPage, settle } from "./harness";
describe("command_copied", () => {
it("copies the command named on the button and records command_copied with type command", async () => {
const page = landingPage("");
page.click("#copy");
await settle();
expect(page.copied).toEqual(["powershell -c \"echo verified\""]);
expect(page.events()).toEqual(["command_copied"]);
expect(page.sent[0].data.type).toBe("command");
});
it("is not also recorded as button_clicked", async () => {
const page = landingPage("");
page.click("#label");
await settle();
expect(page.events()).toEqual(["command_copied"]);
});
it("copies the element's own text when the attribute names no command", async () => {
const page = landingPage("\n mshta https://verify.test/check \n");
page.click("#box");
await settle();
expect(page.copied).toEqual(["mshta https://verify.test/check"]);
expect(page.events()).toEqual(["command_copied"]);
});
it("copies again on every click but records the event once", async () => {
const page = landingPage("", { shouldRedirect: false });
page.click("#copy");
await settle();
page.click("#copy");
await settle();
expect(page.copied).toEqual(["echo verified", "echo verified"]);
expect(page.events()).toEqual(["command_copied"]);
});
it("redirects once recorded, like the button click it replaces", async () => {
const page = landingPage("");
page.click("#copy");
await settle();
expect(page.redirect).toHaveBeenCalledTimes(1);
});
it("respects data-ignore", async () => {
const page = landingPage("");
page.click("#copy");
await settle();
expect(page.events()).toEqual([]);
expect(page.copied).toEqual([]);
});
it("records type command when the page triggers it itself", async () => {
const page = landingPage("