diff --git a/tests/e2e-vault-config.test.ts b/tests/e2e-vault-config.test.ts index b50349952..5bbf866b2 100644 --- a/tests/e2e-vault-config.test.ts +++ b/tests/e2e-vault-config.test.ts @@ -5,13 +5,14 @@ import { expect, it } from "vitest"; const ROOT = resolve(__dirname, ".."); const E2E = join(ROOT, "tests/e2e"); +// `app.plugins.saveConfig()` writes community-plugins.json, not app.json. it("sets vault options in e2e specs without writing app.json", () => { const hits = readdirSync(E2E, { recursive: true, encoding: "utf8" }) .filter((file) => file.endsWith(".ts")) .flatMap((file) => readFileSync(join(E2E, file), "utf8") .split("\n") - .flatMap((line, i) => (/\b(setConfig|saveConfig|requestSaveConfig)\s*\(/.test(line) ? [`${relative(ROOT, join(E2E, file))}:${i + 1}`] : [])), + .flatMap((line, i) => (/(?("Object.keys(app.plugins.plugins)"); + // Obsidian saves the enabled plugins a second after a plugin is turned on + // or off, as the harness does around every spec, and a reload drops that + // save. A reload inside that second would come back without QuickAdd. + await obsidian.dev.evalJsonAsync("app.plugins.saveConfig().then(() => true)"); await obsidian.execText("dev:mobile", on ? { on: true } : { off: true }); await obsidian.waitFor(() => obsidian.dev.evalJson( `document.body.classList.contains("is-mobile") === ${on} && Boolean(app.plugins.plugins.quickadd?.api)`, diff --git a/tests/e2e/uiHelpers.ts b/tests/e2e/uiHelpers.ts index 4c09e320f..76e0948e7 100644 --- a/tests/e2e/uiHelpers.ts +++ b/tests/e2e/uiHelpers.ts @@ -162,21 +162,35 @@ export async function closeOpenPrompts(obsidian: ObsidianClient) { /** * A real click in the middle of the visible element matching `selector`, once - * it stops moving: a settings page slides in when it opens or is returned to. + * it is still, no animation moves it, and it is what a click there hits: a + * settings page slides in when it opens or is returned to, and a phone menu + * slides up from below the screen. Under load an animation can stall between + * two samples, so holding still alone does not mean it is done. */ export async function clickWhenStill(obsidian: ObsidianClient, selector: string) { // The last two samples go into the timeout, so a failure says whether the - // element was missing, hidden, or still moving. + // element was missing, hidden, animating, covered, or still moving. let previous = ""; let last = ""; const point = await obsidian.waitFor(async () => { - const sample = await obsidian.dev.evalJson<{ x: number; y: number } | "absent" | "hidden">(`(() => { + const sample = await obsidian.dev.evalJson<{ x: number; y: number } | string>(`(() => { + ${DESCRIBE_ELEMENT} const all = [...document.querySelectorAll(${jsLiteral(selector)})]; const el = all.find((el) => el.getClientRects().length > 0); if (!el) return all.length > 0 ? "hidden" : "absent"; + // Scroll-driven and endless animations never finish, so they cannot be waited out. + const moving = document.getAnimations().find((animation) => + animation.playState === "running" && animation.timeline instanceof DocumentTimeline + && animation.effect?.getComputedTiming().endTime !== Infinity + && animation.effect.target?.contains(el)); + if (moving) return "animating " + describe(moving.effect.target); el.scrollIntoView({ block: "nearest" }); const rect = el.getBoundingClientRect(); - return { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 }; + const x = rect.left + rect.width / 2; + const y = rect.top + rect.height / 2; + const hit = document.elementFromPoint(x, y); + if (!el.contains(hit)) return "covered by " + describe(hit); + return { x, y }; })()`); const key = JSON.stringify(sample); const settled = typeof sample === "object" && key === last;