mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 04:45:33 -08:00
Show the Activities picker as a two-column Score ledger ordered by recently played or A to Z
AI Assisted
This commit is contained in:
1 parent
ba19f79f1c
commit
fde92ef4d2
11 files changed
+453
-99
No files matched your search
@@ -11,7 +11,7 @@ import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { ACTIVITIES, bestKey, bestKeys, memoKey, musicKey, musicLevel } from "../src/web-console/public/activities.js";
|
||||
import { ACTIVITIES, bestKey, bestKeys, memoKey, musicKey, musicLevel, orderGames, playedKey } from "../src/web-console/public/activities.js";
|
||||
import { BOSS_BITES, COMBO_MS, MAX_LEVEL, MUSIC_TRACKS, dealMusic, heat, trackFor, DISCOVERIES, FOOD_PER_LEVEL, FRUITS, GRID, ICE_STEPS, LEVELS, MAX_COMBO, MIN_CELL, MIN_STEP_MS, POWERS, STEP_MS, SURPRISES, age, applyPower, applySurprise, fruitFor, tallyBit, newRound, onFood, SPECIALS, pace, placeFood, step, stepMs, turn } from "../src/web-console/public/activities/snake.js";
|
||||
import golf, * as golfRules from "../src/web-console/public/activities/golf.js";
|
||||
import { COURSE_W, COURSE_H, COURSES, FRONT_NINE, HOLE_COUNT, courseById } from "../src/web-console/public/activities/golf-holes.js";
|
||||
@@ -307,6 +307,62 @@ test("memoKey builds a flat looks.json key from a list id", () => {
|
||||
assert.equal(memoKey("golf"), "activityMemoGolf");
|
||||
});
|
||||
|
||||
test("playedKey builds a flat looks.json key from a list id, distinct for every game", () => {
|
||||
assert.equal(playedKey("snake"), "activityPlayedSnake");
|
||||
assert.equal(playedKey("golf"), "activityPlayedGolf");
|
||||
const keys = ACTIVITIES.map((a) => playedKey(a.id));
|
||||
assert.equal(new Set(keys).size, ACTIVITIES.length, "every listed game has its own key");
|
||||
});
|
||||
|
||||
test("orderGames splits played from not played yet and orders each group", () => {
|
||||
const ids = (entries) => entries.map((e) => e.id);
|
||||
const byId = (id) => ACTIVITIES.find((a) => a.id === id);
|
||||
const az = [...ACTIVITIES].sort((a, b) => a.title.localeCompare(b.title));
|
||||
|
||||
// Nothing saved: every game is unplayed, A to Z, and `list`'s own entries come back.
|
||||
let out = orderGames(ACTIVITIES, {}, "recent");
|
||||
assert.deepEqual(out.played, []);
|
||||
assert.deepEqual(ids(out.unplayed), ids(az));
|
||||
assert.ok(out.unplayed.every((e) => ACTIVITIES.includes(e)), "entries, never copies");
|
||||
|
||||
// The last pick alone makes that game played.
|
||||
out = orderGames(ACTIVITIES, { lastActivity: "bugs" }, "recent");
|
||||
assert.deepEqual(ids(out.played), ["bugs"]);
|
||||
assert.equal(out.unplayed.length, ACTIVITIES.length - 1);
|
||||
assert.ok(!ids(out.unplayed).includes("bugs"));
|
||||
|
||||
// A best counts as played, Mini golf's on any one course too.
|
||||
out = orderGames(ACTIVITIES, { activityBestSnake: 40, activityBestGolfFrost: 61 }, "recent");
|
||||
assert.deepEqual(ids(out.played).sort(), ["golf", "snake"]);
|
||||
|
||||
// Mixed times: newest first, then the last pick (no time), then A to Z.
|
||||
const looks = { activityPlayedStack: 300, activityPlayedSnake: 100, activityPlayedBugs: 200, lastActivity: "golf", activityBestFlock: 5, activityBestBounce: 9 };
|
||||
out = orderGames(ACTIVITIES, looks, "recent");
|
||||
assert.deepEqual(ids(out.played), ["stack", "bugs", "snake", "golf", "bounce", "flock"]);
|
||||
assert.ok(!ids(out.unplayed).some((id) => ids(out.played).includes(id)), "no game in both groups");
|
||||
assert.equal(out.played.length + out.unplayed.length, ACTIVITIES.length);
|
||||
|
||||
// Equal times sort A to Z.
|
||||
out = orderGames(ACTIVITIES, { activityPlayedSnake: 50, activityPlayedBugs: 50, activityPlayedStack: 50 }, "recent");
|
||||
assert.deepEqual(ids(out.played), ["bugs", "snake", "stack"]);
|
||||
|
||||
// "az" sorts the played group A to Z; unplayed stays A to Z.
|
||||
out = orderGames(ACTIVITIES, looks, "az");
|
||||
assert.deepEqual(ids(out.played), ids(out.played.slice().sort((a, b) => a.title.localeCompare(b.title))));
|
||||
assert.deepEqual(ids(out.played).sort(), ["bounce", "bugs", "flock", "golf", "snake", "stack"]);
|
||||
assert.deepEqual(ids(out.unplayed), ids(az.filter((e) => !out.played.includes(e))));
|
||||
|
||||
// An unknown or missing order reads as "recent".
|
||||
assert.deepEqual(ids(orderGames(ACTIVITIES, looks, "nope").played), ids(orderGames(ACTIVITIES, looks, "recent").played));
|
||||
assert.deepEqual(ids(orderGames(ACTIVITIES, looks).played), ids(orderGames(ACTIVITIES, looks, "recent").played));
|
||||
|
||||
// A time for an id not in the list is ignored, and nothing outside `list` is returned.
|
||||
const some = [byId("snake"), byId("golf"), byId("stack")];
|
||||
out = orderGames(some, { activityPlayedBugs: 999, activityPlayedStack: 10, lastActivity: "bugs" }, "recent");
|
||||
assert.deepEqual(ids(out.played), ["stack"]);
|
||||
assert.deepEqual(ids(out.unplayed), ["golf", "snake"]);
|
||||
});
|
||||
|
||||
/* ----------------------------------------------------------- contract */
|
||||
|
||||
test("musicKey builds a flat looks.json key, and a game with music has a default volume a saved one replaces", () => {
|
||||
|
||||
@@ -361,7 +361,7 @@ test("framed, an Activities game in full screen asks the app for the whole scree
|
||||
t.after(() => fs.rmSync(looksFile, { force: true }));
|
||||
const s = await openSession(await pages.browser(), { t, workflow: "plan", payload: { agent: { status: "working", activity: "Reading" } }, env: { PLAN2CODE_IN_APP: "1" }, init: FAKE_APP_FRAME });
|
||||
await s.page.click("#btn-activities");
|
||||
await s.page.locator('.activities-card[data-activity="snake"]').click();
|
||||
await s.page.locator('.activities-row[data-activity="snake"]').click();
|
||||
await s.page.locator("#activities-board").waitFor();
|
||||
const told = async () => (await toApp(s, "activities-full")).map((m) => m.on);
|
||||
// Each key asks the browser for its own full screen too, and the browser answers a moment
|
||||
|
||||
@@ -108,7 +108,7 @@ async function openActivities(s, id = "snake", course = "pirate") {
|
||||
const board = s.page.locator("#activities-board");
|
||||
await until(async () => (await picker.isVisible()) || (await board.isVisible()), 5000);
|
||||
if (await picker.isVisible()) {
|
||||
await picker.locator(`.activities-card[data-activity="${id}"]`).click();
|
||||
await picker.locator(`.activities-row[data-activity="${id}"]`).click();
|
||||
if (id === "golf") await courseCard(s, course).click();
|
||||
}
|
||||
await until(async () => (await board.isVisible()) && (await overlay(s)) !== "", 5000);
|
||||
@@ -158,13 +158,13 @@ async function iconUsable(s, where) {
|
||||
assert.ok(await btn.isEnabled(), `the die is usable on ${where}`);
|
||||
}
|
||||
|
||||
const cardTitles = (s) => s.page.locator("#activities-picker .activities-card-title").allInnerTexts();
|
||||
const card = (s, id) => s.page.locator(`#activities-picker .activities-card[data-activity="${id}"]`);
|
||||
const cardTitles = (s) => s.page.locator("#activities-picker .activities-row-title").allInnerTexts();
|
||||
const card = (s, id) => s.page.locator(`#activities-picker .activities-row[data-activity="${id}"]`);
|
||||
const focusedCard = (s) => s.page.evaluate(() => document.activeElement?.dataset?.activity || null);
|
||||
const courseCard = (s, id) => s.page.locator(`#activities-picker .activities-course[data-course="${id}"]`);
|
||||
const focusedCourse = (s) => s.page.evaluate(() => document.activeElement?.dataset?.course || null);
|
||||
|
||||
test("the die sits right of the megaphone and opens on the picker, a card per game with its best, and a card opens its game", async (t) => {
|
||||
test("the die sits right of the megaphone and opens on the picker, a ledger row per game with its best, and a row opens its game", async (t) => {
|
||||
savedLooks(t, { welcomeSeen: true, activityBestSnake: 12 });
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "dashboard" });
|
||||
await pastTheIntro(s);
|
||||
@@ -172,11 +172,20 @@ test("the die sits right of the megaphone and opens on the picker, a card per ga
|
||||
const next = await s.page.evaluate(() => document.getElementById("btn-feedback").nextElementSibling?.id);
|
||||
assert.equal(next, "btn-activities");
|
||||
await openPicker(s);
|
||||
assert.deepEqual(await cardTitles(s), ["Snake", "Mini golf", "Light Trails", "Bug Hunt", "Sunset Drive", "Stack Deploy", "Bumper Ring", "Rapids Run", "Hot Potato", "Crossing Rush", "Bounce Road", "Ghoul Rush", "Flock Dash"]);
|
||||
// Snake's seeded best makes it the one played row; the rest sit under Not played yet, A to Z.
|
||||
assert.deepEqual(await cardTitles(s), ["Snake", "Bounce Road", "Bug Hunt", "Bumper Ring", "Crossing Rush", "Flock Dash", "Ghoul Rush", "Hot Potato", "Light Trails", "Mini golf", "Rapids Run", "Stack Deploy", "Sunset Drive"]);
|
||||
assert.equal(await s.page.locator("#activities-picker .activities-count").innerText(), "13 games");
|
||||
assert.equal((await s.page.locator("#activities-picker .activities-group").innerText()).replace(/\s+/g, " "), "Not played yet 12");
|
||||
assert.equal(await s.page.locator("#activities-picker .activities-order-pill[aria-pressed=true]").innerText(), "Recently played");
|
||||
const rowTop = (id) => card(s, id).evaluate((n) => n.offsetTop);
|
||||
assert.equal(await rowTop("bounce"), await rowTop("bugs"), "two rows to a line on a wide dialog");
|
||||
await s.page.setViewportSize({ width: 560, height: 800 });
|
||||
assert.ok(await until(async () => (await rowTop("bounce")) !== (await rowTop("bugs")), 5000), "one column when the dialog is narrow");
|
||||
await s.page.setViewportSize({ width: 1280, height: 800 });
|
||||
assert.ok(await s.page.locator("#activities-board").isHidden(), "no board behind the picker");
|
||||
assert.ok(await s.page.locator("#activities-back").isHidden(), "nothing to go back to");
|
||||
assert.equal(await s.page.locator("#activities-title").innerText(), "Activities", "the header names no game");
|
||||
assert.match(await card(s, "snake").innerText(), /Best: 12/);
|
||||
assert.match(await card(s, "snake").innerText(), /Best 12/);
|
||||
assert.match(await card(s, "golf").innerText(), /6 courses to play/);
|
||||
assert.equal(await s.page.locator("#activities-picker svg").count(), (await cardTitles(s)).length, "each card has its cover");
|
||||
assert.equal(await focusedCard(s), "snake", "with no last pick, focus is on the first card");
|
||||
@@ -187,23 +196,42 @@ test("the die sits right of the megaphone and opens on the picker, a card per ga
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.id), "activities-board", "keys reach the game with no extra click");
|
||||
});
|
||||
|
||||
test("the arrows walk the picker's cards, and space or Enter opens the one in focus", async (t) => {
|
||||
savedLooks(t, { welcomeSeen: true });
|
||||
test("the arrows walk the picker's rows by position across the Not played yet heading, and space or Enter opens the one in focus", async (t) => {
|
||||
savedLooks(t, { welcomeSeen: true, activityBestSnake: 12 });
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_WORKING });
|
||||
await openPicker(s);
|
||||
const press = async (key, n = 1) => {
|
||||
for (let i = 0; i < n; i++) await s.page.keyboard.press(key);
|
||||
};
|
||||
// Rows: snake (played), then A to Z under the heading, two to a line:
|
||||
// bounce bugs / bumper hop / flock ghoul / fuse trails / golf rapids / stack drive.
|
||||
assert.equal(await focusedCard(s), "snake", "the last played, here the one played row, has focus");
|
||||
await press("ArrowDown");
|
||||
assert.equal(await focusedCard(s), "bounce", "down from the last played row lands on the nearest unplayed row");
|
||||
await press("ArrowUp");
|
||||
assert.equal(await focusedCard(s), "snake");
|
||||
await s.page.keyboard.press("ArrowRight");
|
||||
await press("ArrowUp");
|
||||
assert.equal(await focusedCard(s), "snake", "the first line stays put");
|
||||
await press("ArrowRight", 2);
|
||||
assert.equal(await focusedCard(s), "bugs", "right steps through the list, across the heading");
|
||||
await press("ArrowDown");
|
||||
assert.equal(await focusedCard(s), "hop", "down keeps the column");
|
||||
await press("ArrowLeft");
|
||||
assert.equal(await focusedCard(s), "bumper");
|
||||
await press("ArrowRight", 12);
|
||||
assert.equal(await focusedCard(s), "drive", "the last row stays put");
|
||||
await press("ArrowDown");
|
||||
assert.equal(await focusedCard(s), "drive", "the last line stays put");
|
||||
await press("ArrowUp");
|
||||
assert.equal(await focusedCard(s), "rapids");
|
||||
await press("ArrowLeft");
|
||||
assert.equal(await focusedCard(s), "golf");
|
||||
for (let i = 0; i < 12; i++) await s.page.keyboard.press("ArrowRight");
|
||||
assert.equal(await focusedCard(s), "flock", "the last card stays put");
|
||||
for (let i = 0; i < 11; i++) await s.page.keyboard.press("ArrowLeft");
|
||||
assert.equal(await focusedCard(s), "golf");
|
||||
await s.page.keyboard.press("Enter");
|
||||
await press("Enter");
|
||||
// Mini golf opens on its course dashboard, walked the same way.
|
||||
await until(async () => (await focusedCourse(s)) === "pirate", 5000);
|
||||
await s.page.keyboard.press("ArrowRight");
|
||||
await press("ArrowRight");
|
||||
assert.equal(await focusedCourse(s), "cave");
|
||||
await s.page.keyboard.press("Enter");
|
||||
await press("Enter");
|
||||
await until(async () => (await overlay(s)) === "Press space or click to start", 5000);
|
||||
assert.equal(await s.page.locator("#activities-title").innerText(), "Activities · Mini golf, Caves of Doom: no best yet");
|
||||
assert.equal(await s.page.locator("#activities-back").innerText(), "All courses");
|
||||
@@ -211,11 +239,30 @@ test("the arrows walk the picker's cards, and space or Enter opens the one in fo
|
||||
await until(async () => (await focusedCourse(s)) === "cave", 5000);
|
||||
assert.equal(await s.page.locator("#activities-back").innerText(), "All games");
|
||||
await s.page.click("#activities-back");
|
||||
await s.page.locator("#activities-picker .activities-card[data-activity]").first().waitFor();
|
||||
await s.page.locator("#activities-picker .activities-row[data-activity]").first().waitFor();
|
||||
assert.equal(await focusedCard(s), "golf", "back on the picker, the game just left is in focus");
|
||||
// Mini golf was just picked, so it leads Recently played; right steps to Snake.
|
||||
await press("ArrowRight");
|
||||
assert.equal(await focusedCard(s), "snake");
|
||||
await press(" ");
|
||||
assert.ok(await until(async () => (await s.page.locator("#activities-title").innerText()) .startsWith("Activities · Snake"), 5000), "space opens the row in focus");
|
||||
});
|
||||
|
||||
test("the Order buttons keep their arrows, and a press redraws the picker and keeps focus on the button", async (t) => {
|
||||
savedLooks(t, { welcomeSeen: true, activityBestSnake: 12 });
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_WORKING });
|
||||
await openPicker(s);
|
||||
const az = s.page.locator('#activities-picker .activities-order-pill[data-order="az"]');
|
||||
const focusedOrder = () => s.page.evaluate(() => document.activeElement?.dataset?.order || null);
|
||||
await az.focus();
|
||||
await s.page.keyboard.press("ArrowRight");
|
||||
await s.page.keyboard.press(" ");
|
||||
await until(async () => (await s.page.locator("#activities-title").innerText()) === "Activities · Light Trails: no best yet", 5000);
|
||||
await s.page.keyboard.press("ArrowDown");
|
||||
assert.equal(await focusedOrder(), "az", "the arrows leave an Order button where it is");
|
||||
await az.press("Enter");
|
||||
assert.equal(await focusedOrder(), "az", "focus is back on the pressed button after the redraw");
|
||||
assert.equal(await az.getAttribute("aria-pressed"), "true");
|
||||
await az.press("Enter");
|
||||
assert.equal(await az.getAttribute("aria-pressed"), "true", "a press on the pressed button does nothing");
|
||||
});
|
||||
|
||||
test("picking Mini golf shows it, saves it as the last played, and keys reach it with no extra click", async (t) => {
|
||||
@@ -254,7 +301,7 @@ test("one game at a time: All games keeps the round paused for its own card, and
|
||||
await s.page.locator("#activities-picker").waitFor();
|
||||
await step(s, 1);
|
||||
assert.equal(await framesWaiting(s), 0, "the picker does not tick the game");
|
||||
assert.match(await card(s, "snake").innerText(), /Round paused, score 0/);
|
||||
assert.match(await card(s, "snake").innerText(), /Paused at 0/);
|
||||
assert.match(await s.page.locator("#activities-picker").innerText(), /Picking a different game ends the paused round/);
|
||||
// Closed and reopened with a round waiting: straight back into it.
|
||||
await s.page.keyboard.press("Escape");
|
||||
@@ -270,12 +317,12 @@ test("one game at a time: All games keeps the round paused for its own card, and
|
||||
await card(s, "trails").click();
|
||||
await until(async () => (await overlay(s)) === "Press space to start", 5000);
|
||||
await s.page.click("#activities-back");
|
||||
assert.doesNotMatch(await s.page.locator("#activities-picker").innerText(), /Round paused/);
|
||||
assert.doesNotMatch(await s.page.locator("#activities-picker").innerText(), /Paused at/);
|
||||
await card(s, "snake").click();
|
||||
await until(async () => (await overlay(s)) === "Press space to start", 5000);
|
||||
});
|
||||
|
||||
test("a new session's picker marks the last played and puts focus on it, and a last pick no longer listed falls back to the first card", async (t) => {
|
||||
test("a new session's picker marks the last played and puts focus on it, and a last pick no longer listed falls back to the first row", async (t) => {
|
||||
savedLooks(t, { welcomeSeen: true, lastActivity: "golf" });
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_WORKING });
|
||||
await openPicker(s);
|
||||
@@ -286,8 +333,45 @@ test("a new session's picker marks the last played and puts focus on it, and a l
|
||||
fs.writeFileSync(LOOKS_FILE, JSON.stringify({ looks: { welcomeSeen: true, hideActivities: false, lastActivity: "chess" } }));
|
||||
const again = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_WORKING });
|
||||
await openPicker(again);
|
||||
assert.equal(await focusedCard(again), "snake", "an unknown pick puts focus on the first card");
|
||||
assert.equal(await again.page.locator("#activities-picker .activities-card-tag").count(), 0);
|
||||
assert.equal(await focusedCard(again), "bounce", "an unknown pick puts focus on the first row drawn, the first of A to Z");
|
||||
assert.equal(await again.page.locator("#activities-picker .activities-row-tag").count(), 0);
|
||||
});
|
||||
|
||||
test("picking a game moves it to the top of Recently played and stamps its played time, and A to Z reorders the played rows and is still chosen after closing and reopening, and after a reload", async (t) => {
|
||||
savedLooks(t, { welcomeSeen: true, activityBestSnake: 12 });
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_WORKING });
|
||||
await openPicker(s);
|
||||
const playedTitles = async (page = s) => (await cardTitles(page)).slice(0, 2);
|
||||
assert.deepEqual(await playedTitles(), ["Snake", "Bounce Road"]);
|
||||
await card(s, "stack").click();
|
||||
await until(async () => (await overlay(s)) === "Press space to start", 5000);
|
||||
await until(async () => (await serverLooks(s)).activityPlayedStack > 0, 5000);
|
||||
await s.page.click("#activities-back");
|
||||
assert.deepEqual(await playedTitles(), ["Stack Deploy", "Snake"], "the new pick leads Recently played");
|
||||
assert.match(await card(s, "stack").innerText(), /Last played/);
|
||||
const az = s.page.locator('#activities-picker .activities-order-pill[data-order="az"]');
|
||||
const recent = s.page.locator('#activities-picker .activities-order-pill[data-order="recent"]');
|
||||
await az.click();
|
||||
assert.equal(await az.getAttribute("aria-pressed"), "true");
|
||||
assert.equal(await recent.getAttribute("aria-pressed"), "false");
|
||||
assert.deepEqual(await playedTitles(), ["Snake", "Stack Deploy"], "A to Z reorders the played rows");
|
||||
await until(async () => (await serverLooks(s)).activityOrder === "az", 5000);
|
||||
await s.page.keyboard.press("Escape");
|
||||
await s.page.waitForFunction(() => !document.getElementById("activities-modal").open);
|
||||
await openPicker(s);
|
||||
assert.equal(await az.getAttribute("aria-pressed"), "true", "still chosen after closing and reopening");
|
||||
assert.deepEqual(await playedTitles(), ["Snake", "Stack Deploy"]);
|
||||
const again = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_WORKING });
|
||||
await openPicker(again);
|
||||
assert.equal(await again.page.locator('#activities-picker .activities-order-pill[data-order="az"]').getAttribute("aria-pressed"), "true", "read from looks in a new page");
|
||||
assert.deepEqual(await playedTitles(again), ["Snake", "Stack Deploy"]);
|
||||
});
|
||||
|
||||
test("a best score reads with thousands separators on its row", async (t) => {
|
||||
savedLooks(t, { welcomeSeen: true, activityBestSnake: 51900 });
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_WORKING });
|
||||
await openPicker(s);
|
||||
assert.match(await card(s, "snake").innerText(), /Best 51,900/);
|
||||
});
|
||||
|
||||
test("Light Trails plays in the real window: a wide board, the rivals ride, and an arrow steers you", async (t) => {
|
||||
@@ -1100,7 +1184,7 @@ test("Full screen gives the board the whole screen with a panel holding the scor
|
||||
await openPicker(s);
|
||||
const btn = s.page.locator("#activities-full");
|
||||
assert.ok(await btn.isHidden(), "no Full screen on the picker");
|
||||
await s.page.locator('.activities-card[data-activity="snake"]').click();
|
||||
await s.page.locator('.activities-row[data-activity="snake"]').click();
|
||||
await until(async () => (await overlay(s)) !== "", 5000);
|
||||
const before = await fullParts(s);
|
||||
assert.ok(!before.full && !before.rail && !before.scoreInRail, "the window opens at its own size, with no panel");
|
||||
@@ -2055,7 +2139,7 @@ test("Mini golf: a full round saves its total as its course's best, a lower one
|
||||
await s.page.click("#activities-back");
|
||||
await courseCard(s, "pirate").waitFor();
|
||||
await s.page.click("#activities-back");
|
||||
assert.match(await card(s, "golf").innerText(), /Best on 2 of 6 courses/);
|
||||
assert.match(await card(s, "golf").innerText(), /2 of 6 courses/);
|
||||
|
||||
const reset = s.page.locator("#activities-reset");
|
||||
await reset.click();
|
||||
@@ -2088,10 +2172,14 @@ test("Mini golf running breaks no content-security rule and logs no error", asyn
|
||||
});
|
||||
|
||||
test("saved Activities values that do not hold up fall back to their defaults", async (t) => {
|
||||
savedLooks(t, { welcomeSeen: true, activityBestSnake: -5, hideActivities: "yes", lastActivity: 5 });
|
||||
savedLooks(t, { welcomeSeen: true, activityBestSnake: -5, hideActivities: "yes", lastActivity: 5, activityPlayedSnake: -5, activityPlayedGolf: 1.9, activityPlayedBugs: "soon", activityOrder: "bogus" });
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_WORKING });
|
||||
const looks = await pageLooks(s);
|
||||
assert.equal(looks.activityBestSnake, 0, "a negative best is none");
|
||||
assert.equal(looks.activityPlayedSnake, 0, "a negative played time is never");
|
||||
assert.equal(looks.activityPlayedGolf, 1, "a played time is a whole number");
|
||||
assert.equal(looks.activityPlayedBugs, 0, "a played time that is not a number is never");
|
||||
assert.equal(looks.activityOrder, "recent", "an order that is not recent or az is recent, the default");
|
||||
assert.equal(looks.hideActivities, true, "a switch that is not a boolean is off, the default");
|
||||
assert.equal(looks.lastActivity, "", "a last pick that is not a string is none");
|
||||
assert.ok(await s.page.locator("#btn-activities").isHidden(), "and the die stays hidden");
|
||||
@@ -2118,7 +2206,7 @@ test("Back to default turns Show Activities back off and keeps the best scores",
|
||||
});
|
||||
|
||||
test("Reset best scores asks once inside the window, then writes 0", async (t) => {
|
||||
savedLooks(t, { welcomeSeen: true, activityBestSnake: 12 });
|
||||
savedLooks(t, { welcomeSeen: true, activityBestSnake: 12, activityPlayedBugs: 1700000000000, activityOrder: "az" });
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_WORKING });
|
||||
await handTicks(s);
|
||||
await listScoringSnake(s, 3);
|
||||
@@ -2132,6 +2220,9 @@ test("Reset best scores asks once inside the window, then writes 0", async (t) =
|
||||
await reset.click();
|
||||
assert.equal(await reset.innerText(), "Reset best scores");
|
||||
await until(async () => (await serverLooks(s)).activityBestSnake === 0, 5000);
|
||||
const kept = await serverLooks(s);
|
||||
assert.equal(kept.activityPlayedBugs, 1700000000000, "played times stay");
|
||||
assert.equal(kept.activityOrder, "az", "the picker's order stays");
|
||||
await s.page.locator("#activities-board").focus();
|
||||
await s.page.keyboard.press(" ");
|
||||
assert.equal(await s.page.locator("#activities-score").innerText(), "Score: 3 · Best: 0", "the window shows the cleared best");
|
||||
|
||||
@@ -878,7 +878,7 @@ test("prefs: Back to default resets Appearance or Sounds & activities only, and
|
||||
test("looks: resetLooks(keys) changes only those keys, and the role is marked as asked", () => {
|
||||
const before = { ...looks };
|
||||
try {
|
||||
Object.assign(looks, { theme: "dark", width: "wide", accent: "violet", role: "pm", sound: false, soundQuestion: false, hideActivities: false, activityBestSnake: 7, lastActivity: "snake", skipIntro: true });
|
||||
Object.assign(looks, { theme: "dark", width: "wide", accent: "violet", role: "pm", sound: false, soundQuestion: false, hideActivities: false, activityBestSnake: 7, lastActivity: "snake", activityPlayedSnake: 1700000000000, activityOrder: "az", skipIntro: true });
|
||||
resetLooks(prefsResetScope("appearance"));
|
||||
assert.equal(looks.theme, DEFAULT_LOOKS.theme);
|
||||
assert.equal(looks.width, DEFAULT_LOOKS.width);
|
||||
@@ -893,6 +893,8 @@ test("looks: resetLooks(keys) changes only those keys, and the role is marked as
|
||||
assert.equal(looks.hideActivities, DEFAULT_LOOKS.hideActivities);
|
||||
assert.equal(looks.activityBestSnake, 7, "best scores stay");
|
||||
assert.equal(looks.lastActivity, "snake", "the last pick stays");
|
||||
assert.equal(looks.activityPlayedSnake, 1700000000000, "played times stay");
|
||||
assert.equal(looks.activityOrder, "az", "the picker's order stays");
|
||||
} finally {
|
||||
for (const key of Object.keys(looks)) delete looks[key];
|
||||
Object.assign(looks, before);
|
||||
|
||||
Reference in new issue
Block a user