const test = require("node:test"); const assert = require("node:assert"); const { loadContentScript, wait } = require("./helpers"); test("zero delay still clicks immediately (default behavior preserved)", async () => { const { window } = loadContentScript({ url: "https://app.plex.tv/web/index.html", html: `
`, settings: { introDelaySeconds: 0 } }); await wait(50); assert.strictEqual(window.__clickedElements.length, 1); }); test("does not click immediately when a delay is configured, but clicks once it elapses", async () => { const { window } = loadContentScript({ url: "https://app.plex.tv/web/index.html", html: ``, settings: { creditsDelaySeconds: 1 } }); await wait(50); assert.strictEqual(window.__clickedElements.length, 0, "should not click before the delay elapses"); await wait(1100); assert.strictEqual(window.__clickedElements.length, 1, "should click once the delay elapses"); }); test("does not schedule duplicate clicks while a delay is already pending", async () => { const { window } = loadContentScript({ url: "https://app.plex.tv/web/index.html", html: ``, settings: { introDelaySeconds: 1 } }); await wait(50); window.document.body.appendChild(window.document.createElement("div")); await wait(50); window.document.body.appendChild(window.document.createElement("div")); await wait(1200); assert.strictEqual(window.__clickedElements.length, 1); }); test("cancels a scheduled click if its toggle is turned off mid-delay", async () => { const { window, fireStorageChange } = loadContentScript({ url: "https://app.plex.tv/web/index.html", html: ``, settings: { introDelaySeconds: 1 } }); await wait(50); fireStorageChange({ skipIntro: false }); await wait(1200); assert.strictEqual(window.__clickedElements.length, 0); }); test("does not click if the button is removed from the page before the delay elapses", async () => { const { window } = loadContentScript({ url: "https://app.plex.tv/web/index.html", html: ``, settings: { introDelaySeconds: 1 } }); await wait(50); window.document.getElementById("skip").remove(); await wait(1200); assert.strictEqual(window.__clickedElements.length, 0); }); test("does not click if the delayed button is hidden before the delay elapses", async () => { const { window } = loadContentScript({ url: "https://app.plex.tv/web/index.html", html: ``, settings: { introDelaySeconds: 1 } }); await wait(50); window.document.getElementById("skip").style.display = "none"; await wait(1200); assert.strictEqual(window.__clickedElements.length, 0); }); test("intro and credits delays run independently", async () => { const { window } = loadContentScript({ url: "https://app.plex.tv/web/index.html", html: ` `, settings: { introDelaySeconds: 0, creditsDelaySeconds: 1 } }); await wait(50); assert.strictEqual(window.__clickedElements.length, 1, "Skip Intro should click immediately"); assert.strictEqual(window.__clickedElements[0], window.document.getElementById("intro")); await wait(1100); assert.strictEqual(window.__clickedElements.length, 2, "Skip Credits should click after its own delay"); });