Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/e2e-vault-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (/(?<!plugins\.)\b(setConfig|saveConfig|requestSaveConfig)\s*\(/.test(line) ? [`${relative(ROOT, join(E2E, file))}:${i + 1}`] : [])),
);
expect(
hits,
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/choice-builder-pages-phone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ let size: number[] = [];
async function emulateMobile(on: boolean) {
const { obsidian } = getContext();
const enabled = await obsidian.dev.evalJson<string[]>("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)");
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
await obsidian.execText("dev:mobile", on ? { on: true } : { off: true });
await obsidian.waitFor(() => obsidian.dev.evalJson<boolean>(
`document.body.classList.contains("is-mobile") === ${on} && Boolean(app.plugins.plugins.quickadd?.api)`,
Expand Down
22 changes: 18 additions & 4 deletions tests/e2e/uiHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading