Files
plex-auto-skip/tests/popup.test.js
T

136 lines
5.2 KiB
JavaScript

const test = require("node:test");
const assert = require("node:assert");
const { loadPopupScript, wait } = require("./helpers");
test("defaults to app.plex.tv preset with both toggles on and delays at 0s", async () => {
const { window } = loadPopupScript();
await wait(20);
assert.strictEqual(window.document.getElementById("urlPreset").value, "default");
assert.strictEqual(window.document.getElementById("skipIntro").checked, true);
assert.strictEqual(window.document.getElementById("skipCredits").checked, true);
assert.strictEqual(window.document.getElementById("customUrlRow").style.display, "none");
assert.strictEqual(window.document.getElementById("introDelay").value, "0");
assert.strictEqual(window.document.getElementById("creditsDelay").value, "0");
assert.strictEqual(window.document.getElementById("introDelayValue").textContent, "0s");
assert.strictEqual(window.document.getElementById("creditsDelayValue").textContent, "0s");
});
test("loads a previously saved delay value onto the sliders", async () => {
const { window } = loadPopupScript({
initialSettings: { introDelaySeconds: 3, creditsDelaySeconds: 12 }
});
await wait(20);
assert.strictEqual(window.document.getElementById("introDelay").value, "3");
assert.strictEqual(window.document.getElementById("introDelayValue").textContent, "3s");
assert.strictEqual(window.document.getElementById("creditsDelay").value, "12");
assert.strictEqual(window.document.getElementById("creditsDelayValue").textContent, "12s");
});
test("disables a delay slider when its skip toggle is off", async () => {
const { window } = loadPopupScript({
initialSettings: { skipCredits: false }
});
await wait(20);
assert.strictEqual(window.document.getElementById("introDelay").disabled, false);
assert.strictEqual(window.document.getElementById("creditsDelay").disabled, true);
});
test("saving persists the configured delay values", async () => {
const { window, savedCalls } = loadPopupScript();
await wait(20);
window.document.getElementById("introDelay").value = "5";
window.document.getElementById("creditsDelay").value = "20";
window.document.getElementById("saveBtn").click();
await wait(20);
assert.strictEqual(savedCalls.length, 1);
assert.strictEqual(savedCalls[0].introDelaySeconds, 5);
assert.strictEqual(savedCalls[0].creditsDelaySeconds, 20);
});
test("shows custom URL field pre-filled when a custom URL is already saved", async () => {
const { window } = loadPopupScript({
initialSettings: { plexUrl: "http://192.168.1.50:32400/web" }
});
await wait(20);
assert.strictEqual(window.document.getElementById("urlPreset").value, "custom");
assert.strictEqual(window.document.getElementById("customUrl").value, "192.168.1.50:32400/web");
});
test("saving the default preset persists the default Plex URL", async () => {
const { window, savedCalls } = loadPopupScript();
await wait(20);
window.document.getElementById("saveBtn").click();
await wait(20);
assert.strictEqual(savedCalls.length, 1);
assert.strictEqual(savedCalls[0].plexUrl, "https://app.plex.tv");
});
test("saving a custom URL normalizes and persists it", async () => {
const { window, savedCalls } = loadPopupScript();
await wait(20);
const urlPreset = window.document.getElementById("urlPreset");
urlPreset.value = "custom";
urlPreset.dispatchEvent(new window.Event("change"));
window.document.getElementById("customUrl").value = "192.168.1.50:32400/web";
window.document.getElementById("saveBtn").click();
await wait(20);
assert.strictEqual(savedCalls.length, 1);
assert.strictEqual(savedCalls[0].plexUrl, "http://192.168.1.50:32400/web");
});
test("saving Custom URL with a blank field does not silently fall back to the default", async () => {
const { window, savedCalls } = loadPopupScript();
await wait(20);
const urlPreset = window.document.getElementById("urlPreset");
urlPreset.value = "custom";
urlPreset.dispatchEvent(new window.Event("change"));
window.document.getElementById("customUrl").value = " ";
window.document.getElementById("saveBtn").click();
await wait(20);
assert.strictEqual(savedCalls.length, 0, "should not save when the custom URL field is blank");
assert.match(window.document.getElementById("status").textContent, /enter|url/i);
});
test("saving an unparseable custom URL is rejected with an error, not saved", async () => {
const { window, savedCalls } = loadPopupScript();
await wait(20);
const urlPreset = window.document.getElementById("urlPreset");
urlPreset.value = "custom";
urlPreset.dispatchEvent(new window.Event("change"));
window.document.getElementById("customUrl").value = "http://";
window.document.getElementById("saveBtn").click();
await wait(20);
assert.strictEqual(savedCalls.length, 0, "should not save an invalid URL");
});
test("unchecking a toggle and saving persists it as false", async () => {
const { window, savedCalls } = loadPopupScript();
await wait(20);
window.document.getElementById("skipCredits").checked = false;
window.document.getElementById("saveBtn").click();
await wait(20);
assert.strictEqual(savedCalls.length, 1);
assert.strictEqual(savedCalls[0].skipCredits, false);
assert.strictEqual(savedCalls[0].skipIntro, true);
});