Файли
openidea/src/platform/splash.test.ts
T
LU XIANGRUIтаwildcatDownstairs 7709897dbb fix(project): ask about trust before opening the project window (#3663)
Opening an untrusted project in a new window created the window first and asked inside it, where the splash gave way after its 4 s limit to the Welcome screen under the question.

Entry points that may create a window (Open…, Open in New Window, recent projects, dropped folders, clone, plugin requests) now ask in the current window first and create the window only after Trust or Preview; Don't Open creates none. A launch without an originating window (openidea <path>, Dock drop) keeps the splash up under the dialog until the answer. WSL folders are still asked about by their remote window.

Closes #3648

Co-authored-by: wildcatDownstairs <[email protected]>
2026-11-16 12:26:51 +08:00

40 рядки
1.4 KiB
TypeScript

import { afterEach, beforeEach, expect, it, vi } from "vitest";
beforeEach(() => {
vi.useFakeTimers({ toFake: ["setTimeout", "requestAnimationFrame"] });
vi.resetModules();
document.body.innerHTML = '<div id="splash" class="splash"></div>';
});
afterEach(() => vi.useRealTimers());
const splash = () => document.getElementById("splash");
it("gives up on a slow launch after its time limit", async () => {
const { holdSplash, hideSplash } = await import("./splash");
holdSplash(new Promise(() => {}));
hideSplash();
await vi.advanceTimersByTimeAsync(5000);
expect(splash()).toBeNull();
});
it("stays up, under dialogs, until a question asked while the window opens is answered", async () => {
const { askOverSplash, holdSplash, hideSplash } = await import("./splash");
let answer!: (open: boolean) => void;
const question = new Promise<boolean>((resolve) => (answer = resolve));
holdSplash(question);
hideSplash();
askOverSplash(question);
expect(splash()?.classList.contains("splash-under-dialogs")).toBe(true);
await vi.advanceTimersByTimeAsync(60_000);
expect(splash()).not.toBeNull();
answer(false);
await vi.advanceTimersByTimeAsync(1000);
expect(splash()).toBeNull();
});
it("leaves a page without a splash alone", async () => {
document.body.innerHTML = "";
const { askOverSplash } = await import("./splash");
expect(() => askOverSplash(Promise.resolve(true))).not.toThrow();
});