fix: simplify trainer controls
This commit is contained in:
1 parent
cc6bcb23c8
commit
9be0bb48c8
9 files changed
+191
-78
No files matched your search
+124
-32
@@ -37,8 +37,9 @@ async function run() {
|
||||
const captures = [];
|
||||
try {
|
||||
if (shotDir) await mkdir(shotDir,{recursive:true});
|
||||
for (const [width,height] of [[1920,1080],[1366,768],[768,1024],[390,844]]) {
|
||||
const context = await browser.newContext({viewport:{width,height}, reducedMotion:'reduce', locale:'ru-RU', ...(width === 390 ? {hasTouch:true,isMobile:true} : {})});
|
||||
for (const [width,height,touch = false] of [[1920,1080],[1366,768],[768,1024],[390,844,true],[1024,768,true]]) {
|
||||
const mobile = width <= 700, compact = mobile || touch;
|
||||
const context = await browser.newContext({viewport:{width,height}, reducedMotion:'reduce', locale:'ru-RU', hasTouch:touch, isMobile:mobile});
|
||||
try {
|
||||
await context.addInitScript(() => {
|
||||
let seed = 19;
|
||||
@@ -56,7 +57,13 @@ async function run() {
|
||||
const scene = id => page.locator(`#scene-grid button[data-id="${id}"]`);
|
||||
const map = id => page.locator(`#map-grid button[data-id="${id}"]`);
|
||||
const noOverflow = async () => assert(await page.evaluate(()=>document.documentElement.scrollWidth <= innerWidth),`overflow at ${width}`);
|
||||
const select = async id => { await scene(id).click(); if (width === 390) await page.locator('#jump').click(); };
|
||||
const jump = page.locator('#jump'), mark = page.locator('#mark');
|
||||
const selection = page.locator('#selection'), status = page.locator('#status');
|
||||
const history = page.locator('#history li');
|
||||
const assertPosition = async id => assert.deepEqual(await cellIds(page.locator('#scene-grid .current button')),[id]);
|
||||
const assertSelection = async (id, reason = '') => {
|
||||
assert.equal(await selection.textContent(),`Клетка ${coordinate(id)}${reason ? ` — ${reason}` : ''}`);
|
||||
};
|
||||
const assertAvailable = async ids => {
|
||||
for (const grid of ['scene-grid','map-grid']) {
|
||||
assert.deepEqual(await cellIds(page.locator(`#${grid} .available button`)),ids,`${grid} jump targets`);
|
||||
@@ -65,8 +72,23 @@ async function run() {
|
||||
await noOverflow();
|
||||
assert.match(await scene(0).getAttribute('aria-label'), /^x1 y1: вход, персонаж здесь$/);
|
||||
await checkTransitions(page,field.exit);
|
||||
assert(await page.locator('#jump').isDisabled());
|
||||
assert(await page.locator('#mark').isDisabled());
|
||||
assert.equal(await page.locator('input[name="mode"], input[type="radio"], [role="radio"]').count(),0);
|
||||
assert.equal(await page.locator('#touch-actions').isVisible(),compact);
|
||||
assert.equal(await jump.isVisible(),compact);
|
||||
assert.equal(await mark.isVisible(),compact);
|
||||
if (compact) {
|
||||
assert(await jump.isDisabled());
|
||||
assert(await mark.isDisabled());
|
||||
for (const control of [jump,mark]) {
|
||||
const box = await control.boundingBox();
|
||||
assert(box.height >= 44 && box.width >= 44,'touch controls meet the minimum target size');
|
||||
}
|
||||
} else {
|
||||
assert.equal(await page.getByRole('button',{name:'Прыгнуть',exact:true}).count(),0);
|
||||
const noteButtons = page.getByRole('button',{name:'Отметить опасной',exact:true});
|
||||
assert.equal(await noteButtons.count(),1,'only the map keeps its note button on desktop');
|
||||
assert.equal(await noteButtons.getAttribute('id'),'map-mark');
|
||||
}
|
||||
assert.match(await page.locator('#transition-coordinates').textContent(), /Вход: x1 y1/);
|
||||
assert((await page.locator('#transition-coordinates').textContent()).includes(`Выход: ${coordinate(field.exit)}`));
|
||||
assert.equal(await page.locator('#scene-grid .hazard').count(),0);
|
||||
@@ -78,23 +100,44 @@ async function run() {
|
||||
await page.keyboard.press('Escape');
|
||||
assert(await page.locator('#help-open').evaluate(n=>n===document.activeElement));
|
||||
// Even a safe upper-row cell is out of reach two columns from the entrance.
|
||||
await select(second);
|
||||
assert(await page.locator('#jump').isEnabled());
|
||||
assert.match(await page.locator('#status').textContent(),/соседнюю клетку/);
|
||||
assert.deepEqual(await cellIds(page.locator('#scene-grid .current button')),[0]);
|
||||
assert.equal(await page.locator('#history li').count(),0);
|
||||
if (compact) {
|
||||
const beforeSelection = await status.textContent();
|
||||
for (const [id,reason] of [[field.exit,'выход'],[0,'вы здесь']]) {
|
||||
await scene(id).tap();
|
||||
await assertSelection(id,reason);
|
||||
assert(await jump.isDisabled(),reason);
|
||||
assert(await mark.isDisabled(),reason);
|
||||
}
|
||||
await scene(second).tap();
|
||||
await assertSelection(second,'вне досягаемости');
|
||||
assert(await jump.isDisabled());
|
||||
assert(await mark.isEnabled(),'distant cells can still be marked');
|
||||
assert.equal(await status.textContent(),beforeSelection);
|
||||
} else {
|
||||
await scene(second).click();
|
||||
assert.equal(await status.textContent(),'Выберите соседнюю клетку для прыжка.');
|
||||
}
|
||||
await assertPosition(0);
|
||||
assert.equal(await history.count(),0);
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),0);
|
||||
if (width === 390) {
|
||||
if (compact) {
|
||||
await scene(first).click();
|
||||
await scene(first).tap();
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),0,'touch overview must only select');
|
||||
const box = await page.locator('#jump').boundingBox(); assert(box.height >= 44 && box.width >= 44);
|
||||
await page.locator('#jump').tap();
|
||||
} else await select(first);
|
||||
await assertSelection(first);
|
||||
assert(await jump.isEnabled());
|
||||
await assertPosition(0);
|
||||
assert.equal(await history.count(),0,'compact overview must only select');
|
||||
await jump.tap();
|
||||
await assertSelection(first,'вы здесь');
|
||||
assert(await jump.isDisabled());
|
||||
} else await scene(first).click();
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),1);
|
||||
assert.equal(await page.locator('#map-grid .opened').count(),1);
|
||||
assert.equal(await page.locator('#history li').count(),1);
|
||||
assert.equal(await history.count(),1);
|
||||
assert.match(await scene(first).getAttribute('aria-label'),/персонаж здесь/);
|
||||
assert.match(await page.locator('#messages').textContent(),/Опасностей рядом/);
|
||||
const proximity = `Опасностей рядом: ${field.values[first]}.`;
|
||||
assert.equal(await status.textContent(),proximity);
|
||||
assert.equal(await page.locator('#messages li').last().textContent(),`${coordinate(first)} · Звуков нет. ${proximity}`);
|
||||
await assertAvailable([2,10,11,12]);
|
||||
// Native button keyboard actions and spatial focus; focus is not character position.
|
||||
await scene(first).focus(); await page.keyboard.press('ArrowRight');
|
||||
@@ -104,13 +147,20 @@ async function run() {
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),2);
|
||||
assert.equal(await page.locator('#history li').count(),2);
|
||||
await assertAvailable([1,3,11,12,13]);
|
||||
await page.keyboard.press(' ');
|
||||
assert.equal(await page.locator('#history li').count(),2,'cannot jump to the current cell');
|
||||
// Cell 10 still touches opened cell 1, but not the current position (cell 2).
|
||||
await select(10);
|
||||
assert.match(await page.locator('#status').textContent(),/соседнюю клетку/);
|
||||
assert.deepEqual(await cellIds(page.locator('#scene-grid .current button')),[second]);
|
||||
assert.equal(await page.locator('#history li').count(),2);
|
||||
const beforeDistant = await history.allTextContents();
|
||||
if (compact) {
|
||||
await scene(10).tap();
|
||||
await assertSelection(10,'вне досягаемости');
|
||||
assert(await jump.isDisabled());
|
||||
} else {
|
||||
await scene(10).press('Enter');
|
||||
assert.equal(await status.textContent(),'Выберите соседнюю клетку для прыжка.');
|
||||
}
|
||||
await assertPosition(second);
|
||||
assert.deepEqual(await history.allTextContents(),beforeDistant);
|
||||
await scene(second).press(' ');
|
||||
assert.equal(await history.count(),2,'cannot jump to the current cell');
|
||||
await scene(second).focus(); await page.keyboard.press('ArrowLeft');
|
||||
await page.keyboard.press(' ');
|
||||
assert.equal(await page.locator('#history li').count(),3,'one keyboard revisit, one history item');
|
||||
@@ -121,7 +171,7 @@ async function run() {
|
||||
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.
|
||||
if (width === 390) await page.locator('#map-open').click();
|
||||
if (mobile) await page.locator('#map-open').click();
|
||||
await map(note).click();
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),2);
|
||||
await page.locator('#map-mark').click();
|
||||
@@ -140,7 +190,7 @@ async function run() {
|
||||
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);
|
||||
if (width === 390) {
|
||||
if (mobile) {
|
||||
await page.keyboard.press('Escape');
|
||||
assert(await page.locator('#map-open').evaluate(n=>n===document.activeElement));
|
||||
await page.locator('#history-open').click();
|
||||
@@ -153,7 +203,12 @@ async function run() {
|
||||
await page.keyboard.press('Escape'); assert(await page.locator('#map-body').isHidden());
|
||||
await page.locator('#map-toggle').click();
|
||||
}
|
||||
if (shotDir) { const file = `${shotDir}/lu-${width}.png`; await page.screenshot({path:file,fullPage:true}); captures.push(file); }
|
||||
if (shotDir) {
|
||||
const file = `${shotDir}/lu-${width}.png`;
|
||||
// Full-page capture temporarily resizes emulation and can reset the wide coarse-pointer mode.
|
||||
await page.screenshot({path:file,fullPage:!touch || mobile});
|
||||
captures.push(file);
|
||||
}
|
||||
// Restart confirmations preserve/cancel the existing state; settings are staged until submit.
|
||||
await page.locator('#new-game').click(); await page.keyboard.press('Escape');
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),2);
|
||||
@@ -170,8 +225,31 @@ async function run() {
|
||||
assert.match(await scene(0).getAttribute('aria-label'), /вход, персонаж здесь/);
|
||||
await checkTransitions(page);
|
||||
await assertAvailable([1,10,11]);
|
||||
// Mark and unmark with compact buttons or Shift+Enter without moving the character.
|
||||
const toggleMark = async () => {
|
||||
if (compact) await mark.tap();
|
||||
else await scene(first).press('Shift+Enter');
|
||||
};
|
||||
if (compact) await scene(first).tap();
|
||||
await toggleMark();
|
||||
for (const grid of ['scene-grid','map-grid']) {
|
||||
assert.deepEqual(await cellIds(page.locator(`#${grid} .marked button`)),[first]);
|
||||
}
|
||||
assert.equal(await history.count(),1,'one mark, no extra jump');
|
||||
assert.match(await history.last().textContent(),/Поставлена отметка/);
|
||||
if (compact) {
|
||||
await assertSelection(first,'есть отметка');
|
||||
assert(await jump.isDisabled(),'a marked neighbor cannot be jumped to');
|
||||
assert.equal(await mark.textContent(),'Снять отметку');
|
||||
}
|
||||
await toggleMark();
|
||||
assert.equal(await page.locator('#scene-grid .marked, #map-grid .marked').count(),0);
|
||||
assert.equal(await history.count(),2,'one unmark, no extra jump');
|
||||
assert.match(await history.last().textContent(),/Снята отметка/);
|
||||
await assertPosition(0);
|
||||
if (compact) assert(await jump.isEnabled());
|
||||
assert.deepEqual(errors,[]);
|
||||
console.log(`PASS ${width}x${height}: render, adjacent jumps, keyboard/touch, synchronized map, notes, dialogs, settings, console`);
|
||||
console.log(`PASS ${width}x${height} (${compact ? 'compact' : 'desktop'}): render, adjacent jumps, keyboard/touch controls, synchronized map, notes, dialogs, settings, console`);
|
||||
} finally { await context.close(); }
|
||||
}
|
||||
// Sample all exit buckets without coupling this test to their internal order.
|
||||
@@ -187,7 +265,9 @@ async function run() {
|
||||
const exit = await checkTransitions(page);
|
||||
exits.add(exit);
|
||||
await page.locator('#map-grid .exit button').click();
|
||||
assert(await page.locator('#jump').isDisabled());
|
||||
assert((await page.locator('#map-selection').textContent()).includes(`${coordinate(exit)} · выход`));
|
||||
await page.locator('#scene-grid .exit button').click();
|
||||
assert.match(await page.locator('#status').textContent(),/Это переход/);
|
||||
assert(await page.locator('#map-mark').isDisabled());
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),0);
|
||||
assert.equal(await page.locator('#history li').count(),0);
|
||||
@@ -217,18 +297,27 @@ async function run() {
|
||||
assert((await page.locator('#result').textContent()).includes(`Падение на ${coordinate(hazard)}`));
|
||||
assert.equal(await page.locator('#scene-grid .hazard').count(),field.hazards.size);
|
||||
const count = await page.locator('#history li').count();
|
||||
await cell(1).click(); assert.equal(await page.locator('#history li').count(),count);
|
||||
assert(await page.locator('#jump').isDisabled()); assert(await page.locator('#mark').isDisabled());
|
||||
await cell(11).click(); // Previously opened, adjacent to the current cell: blocked only by the result lock.
|
||||
await cell(30).click({button:'right'});
|
||||
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();
|
||||
await page.waitForTimeout(1100); assert.equal(await page.locator('#timer').textContent(),frozen);
|
||||
await cell(2).click(); assert.equal(await page.locator('#timer').textContent(),frozen,'result inspection must not advance the stopped clock');
|
||||
// The narrow, fine-pointer layout exposes the controls without lifting the result lock.
|
||||
await page.setViewportSize({width:683,height:384});
|
||||
const jump = page.locator('#jump'), mark = page.locator('#mark');
|
||||
await jump.waitFor({state:'visible'});
|
||||
assert(await mark.isVisible());
|
||||
await cell(30).click();
|
||||
assert(await jump.isDisabled());
|
||||
assert(await mark.isDisabled());
|
||||
// Restart must cancel old hints, facts and the clock.
|
||||
await page.locator('#new-game').click(); await page.locator('#confirm-action').click();
|
||||
await page.waitForTimeout(2100);
|
||||
assert.equal(await page.locator('#timer').textContent(),'00:00');
|
||||
assert.equal(await page.locator('#scene-grid .hint').count(),0);
|
||||
// Equivalent layout viewport at 200% browser zoom; then explicit CSS magnification.
|
||||
await page.setViewportSize({width:683,height:384});
|
||||
assert(await page.evaluate(()=>document.documentElement.scrollWidth <= innerWidth));
|
||||
await page.evaluate(()=>document.documentElement.style.zoom='2');
|
||||
assert(await page.evaluate(()=>document.documentElement.scrollWidth <= innerWidth));
|
||||
@@ -236,12 +325,14 @@ async function run() {
|
||||
console.log('PASS terminal state, frozen clock, restart timer cleanup, 200% layout/magnification');
|
||||
await page.evaluate(()=>document.documentElement.style.zoom='1');
|
||||
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.evaluate(()=>Math.random=()=>0);
|
||||
for (const id of hintRoute) await cell(id).click();
|
||||
assert.equal(await page.locator('#scene-grid .hint').count(),1);
|
||||
assert.equal(await page.locator('#map-grid .hint').count(),1);
|
||||
assert((await page.locator('#messages').textContent()).includes(hintText));
|
||||
assert.equal(await page.locator('#status').textContent(),`Опасностей рядом: ${field.values[hintCell]}. ${hintText} — опасная клетка.`);
|
||||
const revisitHint = async () => { await cell(beforeHint).click(); await cell(hintCell).click(); };
|
||||
await page.waitForTimeout(1100); await revisitHint();
|
||||
await page.waitForTimeout(1100);
|
||||
@@ -262,7 +353,8 @@ async function run() {
|
||||
assert.match(await page.locator('#result').textContent(),/Карта готова/);
|
||||
assert(await page.locator('#clear-marks').isDisabled());
|
||||
const wonHistory = await page.locator('#history li').count();
|
||||
await cell(0).click({button:'right'});
|
||||
await cell(first).click({button:'right'}); // A safe, unopened cell would normally accept a note.
|
||||
await cell(first).press('Enter');
|
||||
assert.equal(await page.locator('#history li').count(),wonHistory);
|
||||
console.log('PASS hint duration/log persistence, restart cancels active hint, exact-note victory and terminal locks');
|
||||
|
||||
|
||||
Reference in new issue
Block a user