189 lines
7.0 KiB
JavaScript
189 lines
7.0 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("marks the status message as an error (for themed error styling) on a rejected save", async () => {
|
|
const { window } = 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(window.document.getElementById("status").classList.contains("error"), true);
|
|
});
|
|
|
|
test("does not mark the status message as an error on a successful save", async () => {
|
|
const { window } = loadPopupScript();
|
|
await wait(20);
|
|
|
|
window.document.getElementById("saveBtn").click();
|
|
await wait(20);
|
|
|
|
assert.strictEqual(window.document.getElementById("status").classList.contains("error"), false);
|
|
});
|
|
|
|
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);
|
|
});
|
|
|
|
test("closes the popup shortly after a successful save", async () => {
|
|
const { window } = loadPopupScript();
|
|
await wait(20);
|
|
|
|
window.document.getElementById("saveBtn").click();
|
|
|
|
await wait(50);
|
|
assert.strictEqual(window.__closeCalled, false, "should not close instantly, so the Saved message is visible");
|
|
|
|
await wait(700);
|
|
assert.strictEqual(window.__closeCalled, true, "should close shortly after saving");
|
|
});
|
|
|
|
test("does not close the popup when the save is rejected for a blank custom URL", async () => {
|
|
const { window } = 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(700);
|
|
|
|
assert.strictEqual(window.__closeCalled, false);
|
|
});
|