72 lines
3.0 KiB
JavaScript
72 lines
3.0 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import test from "node:test";
|
|
|
|
import { createLatchedDraftState } from "../app/static/wifi-draft-state.js";
|
|
|
|
const root = path.resolve(import.meta.dirname, "..");
|
|
|
|
test("latched WiFi draft state remains dirty until explicitly cleared", () => {
|
|
const state = createLatchedDraftState(["ssid", "password"]);
|
|
|
|
assert.equal(state.dirty, false);
|
|
assert.equal(state.mark("ssid"), true);
|
|
assert.equal(state.dirty, true);
|
|
assert.equal(state.mark("ssid"), false);
|
|
assert.deepEqual(state.keys(), ["ssid"]);
|
|
state.mark("password");
|
|
assert.deepEqual(state.keys(), ["ssid", "password"]);
|
|
state.clear();
|
|
assert.equal(state.dirty, false);
|
|
assert.throws(() => state.mark("unknown"), /Unknown draft field/);
|
|
});
|
|
|
|
test("WiFi settings expose independent network and prompt-delay controls", () => {
|
|
const html = fs.readFileSync(path.join(root, "app/static/index.html"), "utf8");
|
|
const source = fs.readFileSync(path.join(root, "app/static/views/wifi-settings.js"), "utf8");
|
|
const settingsSource = fs.readFileSync(path.join(root, "app/static/views/settings.js"), "utf8");
|
|
const css = fs.readFileSync(path.join(root, "app/static/style.css"), "utf8");
|
|
|
|
for (const id of [
|
|
"wifi-ssid",
|
|
"wifi-password",
|
|
"wifi-dhcp-enabled",
|
|
"wifi-address",
|
|
"wifi-gateway",
|
|
"wifi-prefix",
|
|
"wifi-dns",
|
|
"wifi-apply-immediate",
|
|
"wifi-apply-next-boot",
|
|
"wifi-prompt-delay",
|
|
"wifi-prompt-delay-save",
|
|
"wifi-prompt-feedback",
|
|
]) assert.match(html, new RegExp(`id="${id}"`));
|
|
|
|
for (const id of ["ssid", "password", "dhcp", "address", "gateway", "prefix", "dns"]) {
|
|
assert.match(html, new RegExp(`id="wifi-${id}-modified"`));
|
|
}
|
|
assert.equal((html.match(/对应内容已经修改/g) || []).length, 7);
|
|
assert.match(html, /id="wifi-password"[^>]*type="text"/);
|
|
assert.ok(html.indexOf("WiFi设置") < html.indexOf("网络提示显示"));
|
|
|
|
assert.match(source, /applyWifi\("immediate"\)/);
|
|
assert.match(source, /applyWifi\("next_boot"\)/);
|
|
assert.match(source, /manualFields\.hidden = enabled/);
|
|
assert.match(source, /passwordInput\.value = state\.password/);
|
|
assert.match(source, /field\.control\.addEventListener\("input"/);
|
|
assert.match(source, /dhcpToggle\.addEventListener\("change"/);
|
|
assert.match(source, /apiJson\("\/api\/network\/wifi\/prompt-delay"/);
|
|
assert.match(source, /setControlUnavailable\(immediateButton/);
|
|
assert.match(source, /clearNetworkDraft\(\)/);
|
|
assert.match(source, /clearDelayDraft\(\)/);
|
|
assert.match(settingsSource, /onLeave:\s*\(\) => \{[\s\S]*discardWifiSettingsDrafts\(\)[\s\S]*discardFrpDrafts\(\)[\s\S]*\}/);
|
|
|
|
const buildRequest = source.slice(source.indexOf("function buildRequest"), source.indexOf("function captureNetworkBaseline"));
|
|
assert.doesNotMatch(buildRequest, /prompt_delay_seconds/);
|
|
assert.match(css, /\.wifi-field-modified/);
|
|
assert.match(css, /\.wifi-action-ready/);
|
|
assert.match(css, /\.wifi-prompt-delay-row/);
|
|
assert.match(css, /grid-template-columns: 1fr/);
|
|
});
|