mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 20:45:33 -08:00
Let each sound cue pick from 19 sounds in Preferences
AI Assisted
This commit is contained in:
1 parent
459b840db9
commit
02380fa6fe
33 files changed
+402
-41
No files matched your search
@@ -166,7 +166,8 @@ test("no built skill holds the large console files; the shared copy keeps every
|
||||
assert.ok(fs.readFileSync(built).equals(fs.readFileSync(path.join(src, ...rel.split("/")))), `${rel} differs from src/`);
|
||||
}
|
||||
assert.ok(fs.existsSync(path.join(shared, "public", "vendor", "codemirror.esm.js")), "codemirror ships");
|
||||
assert.ok(fs.readdirSync(path.join(shared, "public")).filter((f) => f.endsWith(".mp3")).length >= 3, "every sound ships");
|
||||
assert.equal(fs.readdirSync(path.join(shared, "public", "sounds")).filter((f) => /^sound-\d\d\.mp3$/.test(f)).length, 19, "every pickable sound ships");
|
||||
assert.equal(fs.readdirSync(path.join(shared, "public")).filter((f) => f.endsWith(".mp3")).length, 2, "the boot and snore sounds ship");
|
||||
});
|
||||
|
||||
test("the shared copy ships a module for every game listed in public/activities.js", async () => {
|
||||
|
||||
@@ -942,3 +942,163 @@ test("the Subagents dialog looks as it did before Preferences moved to tabs", as
|
||||
if (process.env.P2C_PRINT_SUBAGENTS) console.log("SUBAGENTS " + JSON.stringify(got));
|
||||
assert.deepEqual(got, SUBAGENTS_BEFORE);
|
||||
});
|
||||
|
||||
// The sound picker: a select of the 19 files and a play button for each of the
|
||||
// seven pickable cues, Planny's snoring and waking keeping plain boxes.
|
||||
const PICK_EVENTS = ["startSkill", "sessionStart", "skillReady", "sessionEnd", "question", "chatReply", "newTab"];
|
||||
const PICK_DEFAULTS = {
|
||||
startSkill: "sound-01",
|
||||
sessionStart: "sound-02",
|
||||
skillReady: "sound-03",
|
||||
sessionEnd: "sound-02",
|
||||
question: "sound-03",
|
||||
chatReply: "sound-03",
|
||||
newTab: "sound-04",
|
||||
};
|
||||
const pickSelect = (s, event) => s.page.locator(`select[data-sound-file="${event}"]`);
|
||||
|
||||
async function openSoundsTab(s) {
|
||||
await s.page.click("#btn-looks");
|
||||
await s.page.click("#prefs-tab-sounds");
|
||||
// Wait for the dialog to hold every row before acting on one.
|
||||
await s.page.waitForFunction((n) => document.querySelectorAll("select[data-sound-file]").length === n, PICK_EVENTS.length);
|
||||
}
|
||||
|
||||
// Counts the files the page asks to play, without making a sound. Installed
|
||||
// before the page loads (then reloaded), so a cue the session itself plays
|
||||
// never really plays: a preview is dropped while a higher-ranked cue is
|
||||
// audible, and an audible one would hide the click under test.
|
||||
async function stubPlay(s) {
|
||||
await s.page.addInitScript(() => {
|
||||
window.__played = [];
|
||||
HTMLMediaElement.prototype.play = function () {
|
||||
window.__played.push(this.src);
|
||||
return Promise.resolve();
|
||||
};
|
||||
});
|
||||
await s.page.reload({ waitUntil: "domcontentloaded" });
|
||||
await drawn(s.page);
|
||||
}
|
||||
const played = (s) => s.page.evaluate(() => window.__played);
|
||||
|
||||
test("the sound picker: seven cues have a select of 19 sounds on their default, snoring and waking have none", async (t) => {
|
||||
noSavedLooks(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openSoundsTab(s);
|
||||
for (const event of PICK_EVENTS) {
|
||||
assert.equal(await pickSelect(s, event).locator("option").count(), 19, `${event} lists 19 sounds`);
|
||||
assert.equal(await pickSelect(s, event).inputValue(), PICK_DEFAULTS[event], `${event} starts on its default`);
|
||||
assert.equal(await s.page.locator(`[data-sound-play="${event}"]`).count(), 1, `${event} has a play button`);
|
||||
}
|
||||
for (const event of ["snore", "bootup"]) {
|
||||
assert.equal(await s.page.locator(`[data-sound="${event}"]`).count(), 1, `${event} keeps its box`);
|
||||
assert.equal(await s.page.locator(`[data-sound-file="${event}"], [data-sound-play="${event}"]`).count(), 0, `${event} has no picker`);
|
||||
}
|
||||
});
|
||||
|
||||
test("the sound picker: a pick plays once and persists across a reload, and Play replays it even with the cue unticked", async (t) => {
|
||||
noSavedLooks(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await stubPlay(s);
|
||||
await openSoundsTab(s);
|
||||
await s.page.evaluate(() => (window.__played.length = 0));
|
||||
await pickSelect(s, "question").selectOption("sound-07");
|
||||
await s.page.waitForFunction(() => window.__played.length === 1);
|
||||
assert.match((await played(s))[0], /\/sounds\/sound-07\.mp3$/, "the pick played");
|
||||
await s.page.waitForFunction(async () => ((await (await fetch("/looks")).json()).looks || {}).soundFileQuestion === "sound-07");
|
||||
|
||||
await s.page.locator('[data-sound="question"]').uncheck();
|
||||
await s.page.locator('[data-sound-play="question"]').click();
|
||||
await s.page.waitForFunction(() => window.__played.length === 2);
|
||||
assert.match((await played(s))[1], /\/sounds\/sound-07\.mp3$/, "Play replays the pick with the cue unticked");
|
||||
|
||||
await s.page.click("#looks-done");
|
||||
await s.page.reload({ waitUntil: "domcontentloaded" });
|
||||
await drawn(s.page);
|
||||
await openSoundsTab(s);
|
||||
assert.equal(await pickSelect(s, "question").inputValue(), "sound-07", "the pick did not survive a reload");
|
||||
assert.equal(await pickSelect(s, "newTab").inputValue(), "sound-04", "an untouched cue kept its default");
|
||||
});
|
||||
|
||||
test("the sound picker: Play sounds off disables the selects and play buttons, and Back to default restores the defaults", async (t) => {
|
||||
noSavedLooks(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openSoundsTab(s);
|
||||
await pickSelect(s, "newTab").selectOption("sound-15");
|
||||
await s.page.waitForFunction(async () => ((await (await fetch("/looks")).json()).looks || {}).soundFileNewTab === "sound-15");
|
||||
|
||||
await s.page.locator("#looks-sound").uncheck();
|
||||
for (const event of PICK_EVENTS) {
|
||||
assert.equal(await pickSelect(s, event).isDisabled(), true, `${event}'s select is disabled`);
|
||||
assert.equal(await s.page.locator(`[data-sound-play="${event}"]`).isDisabled(), true, `${event}'s play button is disabled`);
|
||||
}
|
||||
assert.equal(await pickSelect(s, "newTab").inputValue(), "sound-15", "the pick is kept while sounds are off");
|
||||
assert.equal(Number(await styleOf(s.page.locator("#looks-sound-events"), "opacity")) < 1, true, "the rows are dimmed");
|
||||
|
||||
await s.page.locator("#looks-sound").check();
|
||||
assert.equal(await pickSelect(s, "newTab").isDisabled(), false, "switching sounds on enables the select again");
|
||||
|
||||
await s.page.click("#looks-reset");
|
||||
await s.page.waitForFunction(() => document.querySelector('select[data-sound-file="newTab"]').value === "sound-04");
|
||||
for (const event of PICK_EVENTS) {
|
||||
assert.equal(await pickSelect(s, event).inputValue(), PICK_DEFAULTS[event], `${event} is back on its default`);
|
||||
}
|
||||
await s.page.waitForFunction(async () => ((await (await fetch("/looks")).json()).looks || {}).soundFileNewTab !== "sound-15");
|
||||
});
|
||||
|
||||
test("the sound picker: a preview is dropped behind a ranked cue that is still playing, and plays once it has stopped", async (t) => {
|
||||
noSavedLooks(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
// A stub whose Audio reports itself playing until the test says otherwise.
|
||||
await s.page.addInitScript(() => {
|
||||
window.__played = [];
|
||||
window.__audible = true;
|
||||
HTMLMediaElement.prototype.play = function () {
|
||||
window.__played.push(this.src);
|
||||
Object.defineProperty(this, "paused", { configurable: true, get: () => !window.__audible });
|
||||
return Promise.resolve();
|
||||
};
|
||||
});
|
||||
await s.page.reload({ waitUntil: "domcontentloaded" });
|
||||
await drawn(s.page);
|
||||
await openSoundsTab(s);
|
||||
// Let the cues the session itself played settle, then start a ranked one.
|
||||
await s.page.evaluate(async () => {
|
||||
window.__audible = false;
|
||||
const { sound } = await import("/sound.js");
|
||||
window.__played.length = 0;
|
||||
sound("question");
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
window.__audible = true;
|
||||
});
|
||||
await s.page.waitForFunction(() => window.__played.length === 1);
|
||||
await s.page.locator('[data-sound-play="newTab"]').click();
|
||||
assert.equal((await played(s)).length, 1, "the preview was dropped behind the audible cue");
|
||||
|
||||
await s.page.evaluate(() => (window.__audible = false));
|
||||
await s.page.locator('[data-sound-play="newTab"]').click();
|
||||
await s.page.waitForFunction(() => window.__played.length === 2);
|
||||
assert.match((await played(s))[1], /\/sounds\/sound-04\.mp3$/, "the preview played once the cue had stopped");
|
||||
});
|
||||
|
||||
test("the sound picker: Tab reaches Play from the select, and a row stacks inside the dialog at a narrow width", async (t) => {
|
||||
noSavedLooks(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await s.page.setViewportSize({ width: 600, height: 900 });
|
||||
await openSoundsTab(s);
|
||||
await pickSelect(s, "question").focus();
|
||||
await s.page.keyboard.press("Tab");
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.dataset.soundPlay), "question", "Tab from the select lands on its Play button");
|
||||
|
||||
const fits = await s.page.evaluate(() => {
|
||||
const box = document.getElementById("looks-modal").getBoundingClientRect();
|
||||
return [...document.querySelectorAll(".sound-row")].map((row) =>
|
||||
[...row.querySelectorAll("label, select, button")].every((n) => {
|
||||
const r = n.getBoundingClientRect();
|
||||
return r.left >= box.left - 1 && r.right <= box.right + 1;
|
||||
})
|
||||
);
|
||||
});
|
||||
assert.equal(fits.length, PICK_EVENTS.length, "every row is drawn");
|
||||
assert.equal(fits.every(Boolean), true, "no control spills out of the dialog at 600px");
|
||||
});
|
||||
@@ -31,7 +31,7 @@ import {
|
||||
turnGate,
|
||||
} from "../src/web-console/public/answers.js";
|
||||
import { CHAT_LIMIT, CHAT_MAX_CHARS } from "../src/web-console/public/chat.js";
|
||||
import { ACCENTS, CARD_WIDTHS, SOUND_EVENTS, soundKey, soundPrefs } from "../src/web-console/public/palette.js";
|
||||
import { ACCENTS, CARD_WIDTHS, SOUND_EVENTS, soundKey, soundPrefs, SOUND_FILES, PICKABLE_SOUNDS, DEFAULT_SOUND_FILE, soundFileKey, soundFilePrefs } from "../src/web-console/public/palette.js";
|
||||
import { HELP_TABS, helpTabFor, helpKeyTarget } from "../src/web-console/public/help.js";
|
||||
import { tabKeyTarget } from "../src/web-console/public/tabs.js";
|
||||
import { PREFS_TABS, prefsOpenTab, prefsResetScope } from "../src/web-console/public/prefs.js";
|
||||
@@ -602,7 +602,8 @@ test("boot.js is served as JavaScript and imports without a DOM", async () => {
|
||||
// nobody adds serves 404 and the sound just never plays, so assert every file
|
||||
// the page asks for comes back as audio.
|
||||
test("the chime files are served as audio", async () => {
|
||||
for (const f of ["start-stop.mp3", "next.mp3", "insert.mp3", "sleeping.mp3", "bootup.mp3", "start-skill.mp3"]) {
|
||||
const sounds = Array.from({ length: 19 }, (_, i) => `sounds/sound-${String(i + 1).padStart(2, "0")}.mp3`);
|
||||
for (const f of [...sounds, "sleeping.mp3", "bootup.mp3"]) {
|
||||
const res = await fetch(`${baseUrl}/${f}`, { headers: { cookie: cookieFor(baseUrl, token) } });
|
||||
assert.equal(res.status, 200, `${f} is played but the server will not serve it`);
|
||||
assert.match(res.headers.get("content-type"), /^audio\//);
|
||||
@@ -613,7 +614,7 @@ test("the chime files are served as audio", async () => {
|
||||
// names a real event, and every event's file is served. A box with no event
|
||||
// saves a setting nothing reads; an event with no box can never be muted.
|
||||
test("every sound event has a preference box and a served file", async () => {
|
||||
assert.equal(SOUND_EVENTS.startSkill.file, "start-skill", "starting a skill has its own sound");
|
||||
assert.equal(SOUND_EVENTS.startSkill.file, "sounds/sound-01", "starting a skill has its own sound");
|
||||
const html = fs.readFileSync(path.join(ROOT, "src", "web-console", "public", "index.html"), "utf8");
|
||||
const boxes = [...html.matchAll(/data-sound="(\w+)"/g)].map((m) => m[1]);
|
||||
assert.deepEqual([...boxes].sort(), Object.keys(SOUND_EVENTS).sort());
|
||||
@@ -642,6 +643,31 @@ test("soundPrefs: missing switches are on, saved booleans hold, anything else is
|
||||
assert.ok(!("extra" in prefs), "only the sound switches come back");
|
||||
});
|
||||
|
||||
// The picked file per cue: a looks.json from before the picker, an unknown
|
||||
// name or a non-string gets the cue's default; a valid name holds.
|
||||
test("soundFilePrefs: defaults for anything not a known file, a valid pick holds", () => {
|
||||
assert.equal(soundFileKey("startSkill"), "soundFileStartSkill");
|
||||
assert.equal(SOUND_FILES.length, 19);
|
||||
const keys = PICKABLE_SOUNDS.map(soundFileKey).sort();
|
||||
const defaults = Object.fromEntries(PICKABLE_SOUNDS.map((e) => [soundFileKey(e), DEFAULT_SOUND_FILE[e]]));
|
||||
for (const saved of [null, undefined, {}, { soundFileQuestion: "sound-99" }, { soundFileQuestion: 7 }, { soundFileQuestion: null }]) {
|
||||
const prefs = soundFilePrefs(saved);
|
||||
assert.deepEqual(Object.keys(prefs).sort(), keys);
|
||||
assert.deepEqual(prefs, defaults, `defaults for ${JSON.stringify(saved)}`);
|
||||
}
|
||||
const prefs = soundFilePrefs({ soundFileQuestion: "sound-07", soundFileNewTab: "bootup", extra: "sound-01" });
|
||||
assert.equal(prefs.soundFileQuestion, "sound-07");
|
||||
assert.equal(prefs.soundFileNewTab, DEFAULT_SOUND_FILE.newTab);
|
||||
assert.ok(!("extra" in prefs));
|
||||
});
|
||||
|
||||
test("every default sound file is a known file, and the pickable cues are the seven", () => {
|
||||
for (const file of Object.values(DEFAULT_SOUND_FILE)) assert.ok(SOUND_FILES.includes(file), file);
|
||||
assert.deepEqual(PICKABLE_SOUNDS, ["startSkill", "sessionStart", "skillReady", "sessionEnd", "question", "chatReply", "newTab"]);
|
||||
assert.ok(!PICKABLE_SOUNDS.includes("snore") && !PICKABLE_SOUNDS.includes("bootup"));
|
||||
for (const event of PICKABLE_SOUNDS) assert.equal(SOUND_EVENTS[event].file, `sounds/${DEFAULT_SOUND_FILE[event]}`);
|
||||
});
|
||||
|
||||
// The favicon rides the same allow-list, so a missing entry is a silent 404
|
||||
// and the tab falls back to a blank icon.
|
||||
test("the favicon is served as an SVG with a PNG fallback and the page points at both", async () => {
|
||||
@@ -838,7 +864,7 @@ test("prefs: the dialog opens on the tab asked for, else Appearance", () => {
|
||||
test("prefs: Back to default resets Appearance or Sounds & activities only, and nothing on the other two", () => {
|
||||
assert.deepEqual(prefsResetScope("appearance"), ["theme", "width", "accent", "role", "skipIntro"]);
|
||||
const sounds = prefsResetScope("sounds");
|
||||
assert.deepEqual(sounds, ["sound", ...Object.keys(SOUND_EVENTS).map(soundKey), "hideActivities", "activitySounds", "gameMusic"]);
|
||||
assert.deepEqual(sounds, ["sound", ...Object.keys(SOUND_EVENTS).map(soundKey), ...PICKABLE_SOUNDS.map(soundFileKey), "hideActivities", "activitySounds", "gameMusic"]);
|
||||
for (const key of [...prefsResetScope("appearance"), ...sounds]) {
|
||||
if (key !== "role") assert.ok(Object.hasOwn(DEFAULT_LOOKS, key), `${key} has a default`);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user