diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 4c68fb783..6ec678f5a 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -24225,6 +24225,11 @@ function hold(h) { if (Math.abs(d) >= 1) { let want = v.scrollTop + d; const max = v.scrollHeight - v.clientHeight; + // a view at its top when clicked stays at its top: what comes in above + // what was clicked moves it down rather than scrolling the view to follow + // it. Turning automatic updates off grew the Version row above the + // switch once the save answered, and the view slid 2px off its top (#2134) + if (h.top && want > 0) want = 0; // a view at its top when clicked stays there rather than be given room // to scroll down: a chip saved in the panel's Profiles came in above the // button held, and room made for the button slid the chip up under the diff --git a/internal/gui/tests/update-auto.test.cjs b/internal/gui/tests/update-auto.test.cjs index bd8050a27..f3c0eb3b8 100644 --- a/internal/gui/tests/update-auto.test.cjs +++ b/internal/gui/tests/update-auto.test.cjs @@ -164,6 +164,35 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await scrolls(page), before, "the click must not scroll the page"); assert.deepEqual(errors, []); }); + + // A view at its top stays at its top (#2134): at 420 wide Settings + // scrolls, and turning updates off gives the Version row above the + // switch its "are off" line once the save answers. That moves the + // switch down; it must not scroll the view, then or after the redraw. + await t.test(lang + ": 420 wide at the top, Off moves the switch down, not the page", async () => { + const ctl = { off: false, every: 0, state: "", checks: 0, saves: [] }; + const errors = []; + const page = await (await browser.newContext({ viewport: { width: 420, height: 640 } })).newPage(); + page.setDefaultTimeout(5000); + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", server(lang, ctl)); + await watchSettingsReads(page); + await page.goto("http://magpie.test/?view=settings"); + await settingsDrawn(page); + await page.locator(":is(#setTab-about, .nav-s[data-of=setTab-about]):visible").click(); + await page.locator("#setPage-about").waitFor({ state: "visible" }); + const auto = page.locator("#about .row.pref", { has: page.locator(".name", { hasText: new RegExp("^" + w.auto + "$") }) }); + await auto.waitFor(); + await page.waitForTimeout(300); + const view = page.locator("#view-settings"); + assert.equal(await view.evaluate((v) => v.scrollTop), 0); + assert.ok(await view.evaluate((v) => v.scrollHeight > v.clientHeight + 10), "Settings must be able to scroll at 420"); + await auto.locator(".opt", { hasText: w.off }).click(); + await page.locator("#about .sub", { hasText: w.isOff }).waitFor(); + await page.waitForTimeout(600); // past the save's redraw and the switch's play + assert.equal(await view.evaluate((v) => v.scrollTop), 0, "a view at its top stays at its top"); + assert.deepEqual(errors, []); + }); } }); } diff --git a/internal/gui/tests/update-restart.test.cjs b/internal/gui/tests/update-restart.test.cjs index 00b4254ad..6e26fb721 100644 --- a/internal/gui/tests/update-restart.test.cjs +++ b/internal/gui/tests/update-restart.test.cjs @@ -148,9 +148,12 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // automatic updates off: kept, dimmed, says when it works // (the version row above then says automatic updates are off, a // line that can grow it by a pixel or two: what is held is the - // control clicked, where it is on the screen; at the view's top - // WebKit scrolls it by those pixels, #2134) + // control clicked, where it is on the screen, unless the view is at + // its top, which stays at its top and lets the switch move down by + // those pixels, #2134) await showRow(page, auto); + const settings = page.locator("#view-settings"); + const atTop = await settings.evaluate((v) => v.scrollTop < 1); const y0 = (await auto.locator(".opt").nth(0).boundingBox()).y; await auto.locator(".opt").nth(0).click(); await restart.locator(".sub", { hasText: w.whileOn }).waitFor(); @@ -159,7 +162,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(ctl.saves.at(-1).autoRestart, true); await page.waitForTimeout(400); const y1 = (await auto.locator(".opt").nth(0).boundingBox()).y; - assert.ok(Math.abs(y1 - y0) <= 1, `the clicked switch moved ${y1 - y0}px`); + if (atTop) { + assert.equal(await settings.evaluate((v) => v.scrollTop), 0, "a view at its top stays at its top"); + assert.ok(y1 - y0 >= -1 && y1 - y0 <= 4, `the clicked switch moved ${y1 - y0}px`); + } else assert.ok(Math.abs(y1 - y0) <= 1, `the clicked switch moved ${y1 - y0}px`); // and off again await showRow(page, restart);