feat: add trainer sound mode and manual danger ratings
This commit is contained in:
1 parent
9be0bb48c8
commit
ad8e2d1438
13 files changed
+466
-58
No files matched your search
+211
-10
@@ -10,6 +10,19 @@ const shotDir = process.env.BELKI_SCREENSHOT_DIR;
|
||||
const allowedExits = [19,29,39,49,55,56,57,58,59];
|
||||
function seeded(seed = 19) { return () => { seed = (Math.imul(seed,1664525)+1013904223) >>> 0; return seed / 2 ** 32; }; }
|
||||
const cellIds = locator => locator.evaluateAll(nodes=>nodes.map(n=>Number(n.dataset.id)));
|
||||
const levelButtons = page => page.locator('#map-levels button[data-level]');
|
||||
const levelButton = (page,level) => page.locator(`#map-levels button[data-level="${level}"]`);
|
||||
const valueText = async (cell,selector) => (await cell.locator(selector).allTextContents()).join('').trim();
|
||||
async function assertRatingControls(page,{disabled = false, active = null} = {}) {
|
||||
const buttons = levelButtons(page);
|
||||
assert.deepEqual(await buttons.evaluateAll(nodes=>nodes.map(n=>Number(n.dataset.level))),[0,1,2,3,4,5,6,7]);
|
||||
for (const button of await buttons.all()) {
|
||||
assert(await button.isVisible(),'the rating menu stays under the map');
|
||||
assert.equal(await button.isDisabled(),disabled);
|
||||
assert.equal(await button.getAttribute('aria-pressed'),String(Number(await button.getAttribute('data-level')) === active));
|
||||
}
|
||||
assert.equal(await page.locator('#map-clear-level').isDisabled(),disabled || active === null);
|
||||
}
|
||||
async function checkTransitions(page, expectedExit) {
|
||||
const sceneExit = await cellIds(page.locator('#scene-grid .exit button'));
|
||||
assert.equal(sceneExit.length,1);
|
||||
@@ -120,6 +133,7 @@ async function run() {
|
||||
await assertPosition(0);
|
||||
assert.equal(await history.count(),0);
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),0);
|
||||
await page.locator('#simple-mode').check(); // Exercise the existing diagnostics in simplified mode.
|
||||
if (compact) {
|
||||
await scene(first).click();
|
||||
await scene(first).tap();
|
||||
@@ -170,26 +184,110 @@ async function run() {
|
||||
await page.keyboard.press('End');
|
||||
assert(await scene(9).evaluate(n=>n===document.activeElement));
|
||||
await page.keyboard.press('Home'); assert(await scene(0).evaluate(n=>n===document.activeElement));
|
||||
// Notes select on the map without jumping. One DOM map is moved into the modal on phone.
|
||||
// Click/tap an eligible neighbor on the map: selection and rating must never jump.
|
||||
if (mobile) await page.locator('#map-open').click();
|
||||
await map(note).click();
|
||||
const ratingCell = 11;
|
||||
const mapSelection = page.locator('#map-selection');
|
||||
const mapMark = page.locator('#map-mark');
|
||||
const project = page.locator('#project-marks');
|
||||
const chooseOnMap = async cell => touch ? cell.tap() : cell.click();
|
||||
for (const id of [0,field.exit]) {
|
||||
await chooseOnMap(map(id));
|
||||
await assertRatingControls(page,{disabled:true});
|
||||
await map(id).press('4');
|
||||
assert.equal(await valueText(map(id),'.cell-rating'),'','cannot rate a transition');
|
||||
}
|
||||
await chooseOnMap(map(ratingCell));
|
||||
assert((await mapSelection.textContent()).includes(coordinate(ratingCell)));
|
||||
await assertRatingControls(page);
|
||||
await assertPosition(first);
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),2);
|
||||
await page.locator('#map-mark').click();
|
||||
assert.equal(await history.count(),3,'map selection has not changed jump history');
|
||||
|
||||
const assertRating = async level => {
|
||||
assert.equal(await valueText(map(ratingCell),'.cell-rating'),String(level));
|
||||
assert.equal(await valueText(scene(ratingCell),'.cell-rating'),String(level));
|
||||
assert.doesNotMatch(await valueText(map(ratingCell),'.cell-value'),/\d/,'an estimate is not the field value');
|
||||
assert.match(await mapSelection.textContent(),new RegExp(`оценк[^\\d]*${level}\\b`,'i'));
|
||||
await assertRatingControls(page,{active:level});
|
||||
};
|
||||
if (touch) {
|
||||
await levelButton(page,1).tap();
|
||||
await assertRating(1);
|
||||
await levelButton(page,7).tap();
|
||||
} else {
|
||||
await map(ratingCell).press('1');
|
||||
await assertRating(1);
|
||||
await map(ratingCell).press('7');
|
||||
await assertRating(7);
|
||||
for (const outside of ['8','9']) await map(ratingCell).press(outside);
|
||||
}
|
||||
await assertRating(7);
|
||||
assert.deepEqual(await cellIds(page.locator('#map-grid .rated button')),[ratingCell]);
|
||||
assert.deepEqual(await cellIds(page.locator('#scene-grid .rated button')),[ratingCell]);
|
||||
assert.equal(await page.locator('#mark-count').textContent(),'0');
|
||||
assert.equal(await page.locator('#map-grid .marked').count(),0);
|
||||
await assertAvailable([2,10,11,12]);
|
||||
await assertPosition(first);
|
||||
await project.uncheck();
|
||||
assert.equal(await valueText(scene(ratingCell),'.cell-rating'),'');
|
||||
assert.equal(await page.locator('#scene-grid .rated').count(),0);
|
||||
assert.equal(await valueText(map(ratingCell),'.cell-rating'),'7');
|
||||
await project.check();
|
||||
await assertRating(7);
|
||||
if (shotDir && (width === 1366 || mobile)) {
|
||||
const file = `${shotDir}/lu-ratings-${width}.png`;
|
||||
await page.screenshot({path:file});
|
||||
captures.push(file);
|
||||
}
|
||||
|
||||
// Old flags and ratings coexist; clearing either one must leave the other intact.
|
||||
await chooseOnMap(mapMark);
|
||||
assert.equal(await page.locator('#mark-count').textContent(),'1');
|
||||
assert.deepEqual(await cellIds(page.locator('#map-grid .marked button')),[ratingCell]);
|
||||
await assertRating(7);
|
||||
if (touch) await page.locator('#map-clear-level').tap();
|
||||
else await map(ratingCell).press('Delete');
|
||||
assert.equal(await valueText(map(ratingCell),'.cell-rating'),'');
|
||||
assert.deepEqual(await cellIds(page.locator('#map-grid .marked button')),[ratingCell]);
|
||||
await assertRatingControls(page);
|
||||
if (touch) await levelButton(page,0).tap();
|
||||
else await map(ratingCell).press('0');
|
||||
await assertRating(0);
|
||||
await chooseOnMap(mapMark);
|
||||
await assertRating(0);
|
||||
assert.equal(await page.locator('#mark-count').textContent(),'0');
|
||||
if (!touch) {
|
||||
await levelButton(page,4).click();
|
||||
await assertRating(4);
|
||||
await map(ratingCell).press('0');
|
||||
await assertRating(0);
|
||||
}
|
||||
if (touch) await page.locator('#map-clear-level').tap();
|
||||
else await map(ratingCell).press('Backspace');
|
||||
assert.equal(await page.locator('#map-grid .rated, #scene-grid .rated').count(),0);
|
||||
await assertRatingControls(page);
|
||||
await assertPosition(first);
|
||||
|
||||
await map(note).click();
|
||||
const beforeFlag = await history.count();
|
||||
await mapMark.click();
|
||||
assert.deepEqual(await cellIds(page.locator('#map-grid .marked button')),[note]);
|
||||
assert.deepEqual(await cellIds(page.locator('#scene-grid .marked button')),[note]);
|
||||
assert.deepEqual(await cellIds(page.locator('#scene-grid .current button')),[first]);
|
||||
await page.locator('#project-marks').uncheck();
|
||||
assert.equal(await valueText(map(note),'.cell-rating'),'','an ordinary flag has no rating');
|
||||
await assertPosition(first);
|
||||
await project.uncheck();
|
||||
assert.equal(await page.locator('#scene-grid .marked').count(),0);
|
||||
assert.equal(await page.locator('#map-grid .marked').count(),1);
|
||||
assert.equal(await page.locator('#history li').count(),4);
|
||||
await page.locator('#project-marks').check();
|
||||
assert.equal(await history.count(),beforeFlag + 1);
|
||||
await project.check();
|
||||
// Clearing first cancels, then confirms; facts and history remain.
|
||||
await page.locator('#clear-marks').click(); await page.keyboard.press('Escape');
|
||||
assert.equal(await page.locator('#map-grid .marked').count(),1);
|
||||
await page.locator('#clear-marks').click(); await page.locator('#confirm-action').click();
|
||||
await page.locator('#map-grid .marked').waitFor({state:'detached'});
|
||||
assert.equal(await page.locator('#map-grid .opened').count(),2);
|
||||
assert.equal(await page.locator('#history li').count(),5);
|
||||
assert.equal(await history.count(),beforeFlag + 2);
|
||||
if (mobile) {
|
||||
await page.keyboard.press('Escape');
|
||||
assert(await page.locator('#map-open').evaluate(n=>n===document.activeElement));
|
||||
@@ -249,7 +347,7 @@ async function run() {
|
||||
await assertPosition(0);
|
||||
if (compact) assert(await jump.isEnabled());
|
||||
assert.deepEqual(errors,[]);
|
||||
console.log(`PASS ${width}x${height} (${compact ? 'compact' : 'desktop'}): render, adjacent jumps, keyboard/touch controls, synchronized map, notes, dialogs, settings, console`);
|
||||
console.log(`PASS ${width}x${height} (${compact ? 'compact' : 'desktop'}): render, adjacent jumps, keyboard/touch controls, map ratings and flags, projection, dialogs, settings, console`);
|
||||
} finally { await context.close(); }
|
||||
}
|
||||
// Sample all exit buckets without coupling this test to their internal order.
|
||||
@@ -276,6 +374,89 @@ async function run() {
|
||||
assert.deepEqual([...exits].sort((a,b)=>a-b),allowedExits);
|
||||
console.log('PASS all permitted exit cells, synchronized transitions, exit cannot be jumped to or marked');
|
||||
} finally { await boundary.close(); }
|
||||
// The same opened cell can display both the player's rating and the model's actual value.
|
||||
const audio = await browser.newContext({viewport:{width:1366,height:768}});
|
||||
try {
|
||||
const page = await audio.newPage();
|
||||
await page.addInitScript(() => {
|
||||
let seed = 19;
|
||||
Math.random = () => { seed = (Math.imul(seed,1664525)+1013904223) >>> 0; return seed / 2 ** 32; };
|
||||
});
|
||||
await page.goto(`${origin}/trainer`);
|
||||
const scene = id => page.locator(`#scene-grid button[data-id="${id}"]`);
|
||||
const map = id => page.locator(`#map-grid button[data-id="${id}"]`);
|
||||
const simple = page.locator('#simple-mode');
|
||||
const status = page.locator('#status');
|
||||
const informative = 20, real = field.values[informative];
|
||||
assert(real > 0 && real !== 7 && real !== 6 && field.values[11] === 0,'sound fixture must contrast zero, positive and guessed values');
|
||||
await scene(0).waitFor();
|
||||
assert.equal(await simple.isChecked(),false,'sound mode is the default');
|
||||
await page.evaluate(()=>Math.random=()=>0); // A positive jump could draw a hint in simplified mode.
|
||||
await scene(11).click();
|
||||
assert.equal(await status.textContent(),'Звуков нет.');
|
||||
const replay = page.locator('#replay-sound');
|
||||
assert(await replay.isDisabled(),'there is no signal to replay at level zero');
|
||||
assert.equal(await valueText(map(11),'.cell-value'),'·');
|
||||
await map(informative).press('7');
|
||||
assert.equal(await valueText(map(informative),'.cell-rating'),'7');
|
||||
await scene(informative).click();
|
||||
assert.deepEqual(await cellIds(page.locator('#scene-grid .current button')),[informative],'ratings cannot block a jump');
|
||||
assert.equal(await status.textContent(),'Прислушайтесь к звуку.');
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),2);
|
||||
const journal = page.locator('#messages');
|
||||
const history = page.locator('#history');
|
||||
const noFactInLogs = async () => {
|
||||
for (const log of [history,journal]) {
|
||||
assert.doesNotMatch(await log.textContent(),/(?:рядом:?\s*\d|подсказка:)/i);
|
||||
}
|
||||
assert.equal(await page.locator('#scene-grid .hint, #map-grid .hint').count(),0);
|
||||
};
|
||||
const assertCellNumbers = async (fact,rating) => {
|
||||
for (const cell of [scene(informative),map(informative)]) {
|
||||
const displayedFact = await valueText(cell,'.cell-value');
|
||||
if (fact === null) assert.doesNotMatch(displayedFact,/\d/);
|
||||
else assert.equal(displayedFact,fact);
|
||||
assert.equal(await valueText(cell,'.cell-rating'),rating);
|
||||
}
|
||||
};
|
||||
await noFactInLogs();
|
||||
await assertCellNumbers(null,'7');
|
||||
assert.doesNotMatch(await scene(informative).getAttribute('aria-label'),/рядом:?\s*\d/);
|
||||
const beforeReplay = await history.locator('li').count();
|
||||
await replay.click();
|
||||
assert.equal(await history.locator('li').count(),beforeReplay,'replaying sound does not jump');
|
||||
await noFactInLogs();
|
||||
const beforeModeSwitch = await history.locator('li').count();
|
||||
await simple.check();
|
||||
await assertCellNumbers(String(real),'7');
|
||||
assert.equal(await valueText(map(11),'.cell-value'),'0','simplified mode shows a real zero');
|
||||
const project = page.locator('#project-marks');
|
||||
await project.uncheck();
|
||||
assert.equal(await valueText(scene(informative),'.cell-value'),String(real),'projection does not hide the model value');
|
||||
assert.equal(await valueText(scene(informative),'.cell-rating'),'');
|
||||
assert.equal(await valueText(map(informative),'.cell-rating'),'7');
|
||||
await project.check();
|
||||
await map(informative).click();
|
||||
await assertRatingControls(page,{active:7});
|
||||
assert(await page.locator('#map-mark').isDisabled(),'opened cells can be rated but not flagged');
|
||||
assert.match(await history.textContent(),new RegExp(`рядом:?\\s*${real}\\b`));
|
||||
assert.match(await journal.textContent(),new RegExp(`рядом:?\\s*${real}\\b`));
|
||||
await simple.uncheck();
|
||||
await assertCellNumbers(null,'7');
|
||||
await noFactInLogs();
|
||||
assert.equal(await history.locator('li').count(),beforeModeSwitch,'switching modes does not append a game action');
|
||||
await map(informative).press('6');
|
||||
await assertCellNumbers(null,'6');
|
||||
await assertRatingControls(page,{active:6});
|
||||
await map(informative).press('Backspace');
|
||||
await assertCellNumbers(null,'');
|
||||
await assertRatingControls(page);
|
||||
await simple.check();
|
||||
await assertCellNumbers(String(real),'');
|
||||
assert.deepEqual(await cellIds(page.locator('#scene-grid .current button')),[informative]);
|
||||
assert.equal(await page.locator('#map-grid .opened').count(),2);
|
||||
console.log('PASS default sound mode, zero/positive jumps and replay, fact/log disclosure, independent ratings on opened cells, no restart');
|
||||
} finally { await audio.close(); }
|
||||
// Deterministic result/clock/hint lifetime checks at desktop size.
|
||||
const context = await browser.newContext({viewport:{width:1366,height:768}});
|
||||
try {
|
||||
@@ -299,6 +480,11 @@ async function run() {
|
||||
const count = await page.locator('#history li').count();
|
||||
await cell(11).click(); // Previously opened, adjacent to the current cell: blocked only by the result lock.
|
||||
await cell(30).click({button:'right'});
|
||||
const postResult = page.locator('#map-grid button[data-id="30"]');
|
||||
await postResult.click();
|
||||
await assertRatingControls(page,{disabled:true});
|
||||
await postResult.press('7');
|
||||
assert.equal(await valueText(postResult,'.cell-rating'),'','keyboard ratings also respect the result lock');
|
||||
assert.equal(await page.locator('#history li').count(),count);
|
||||
assert.deepEqual(await cellIds(page.locator('#scene-grid .current button')),[20]);
|
||||
const frozen = await page.locator('#timer').textContent();
|
||||
@@ -327,6 +513,7 @@ async function run() {
|
||||
await page.setViewportSize({width:1366,height:768});
|
||||
await jump.waitFor({state:'hidden'});
|
||||
await page.reload(); await page.locator('#scene-grid button').last().waitFor();
|
||||
await page.locator('#simple-mode').check();
|
||||
await page.evaluate(()=>Math.random=()=>0);
|
||||
for (const id of hintRoute) await cell(id).click();
|
||||
assert.equal(await page.locator('#scene-grid .hint').count(),1);
|
||||
@@ -342,16 +529,30 @@ async function run() {
|
||||
assert((await page.locator('#messages').textContent()).includes(hintText));
|
||||
await revisitHint();
|
||||
assert.equal(await page.locator('#scene-grid .hint').count(),1);
|
||||
await page.locator('#simple-mode').uncheck();
|
||||
assert.equal(await page.locator('#scene-grid .hint, #map-grid .hint').count(),0);
|
||||
assert.doesNotMatch(await page.locator('#messages').textContent(),/Подсказка:/);
|
||||
await page.locator('#simple-mode').check();
|
||||
await revisitHint();
|
||||
assert.equal(await page.locator('#scene-grid .hint').count(),1);
|
||||
await page.locator('#new-game').click(); await page.locator('#confirm-action').click();
|
||||
await page.waitForTimeout(2100);
|
||||
assert.equal(await page.locator('#scene-grid .hint').count(),0);
|
||||
assert.equal(await page.locator('#history li').count(),0);
|
||||
assert.equal(await page.locator('#timer').textContent(),'00:00');
|
||||
// Marking is available anywhere; only the exact hazard set wins.
|
||||
// Ratings neither satisfy nor obstruct the exact-flag victory condition.
|
||||
await page.reload(); await page.locator('#scene-grid button').last().waitFor();
|
||||
for (const id of field.hazards) await page.locator(`#map-grid button[data-id="${id}"]`).press('7');
|
||||
assert.equal(await page.locator('#mark-count').textContent(),'0');
|
||||
assert(await page.locator('#result').isHidden(),'rating every hazard does not win without flags');
|
||||
const ratedSafe = page.locator(`#map-grid button[data-id="${first}"]`);
|
||||
await ratedSafe.press('1');
|
||||
assert.equal(await valueText(ratedSafe,'.cell-rating'),'1');
|
||||
for (const id of field.hazards) await cell(id).click({button:'right'});
|
||||
assert.match(await page.locator('#result').textContent(),/Карта готова/);
|
||||
assert(await page.locator('#clear-marks').isDisabled());
|
||||
await page.locator(`#map-grid button[data-id="${second}"]`).click();
|
||||
await assertRatingControls(page,{disabled:true});
|
||||
const wonHistory = await page.locator('#history li').count();
|
||||
await cell(first).click({button:'right'}); // A safe, unopened cell would normally accept a note.
|
||||
await cell(first).press('Enter');
|
||||
|
||||
Reference in new issue
Block a user