Files
Recordly/electron/appActivation.test.ts
T
webadderall eaf87be95b Recordly 2.0 local review stack 2/6
Dependency-ordered review preparation. Not pushed or remotely reviewed.
2026-11-06 05:24:21 +11:00

69 lines
2.3 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { activateFromDesktopIcon } from "./appActivation";
function windowState(
overrides: { destroyed?: boolean; visible?: boolean; minimized?: boolean } = {},
) {
return {
isDestroyed: () => overrides.destroyed ?? false,
isVisible: () => overrides.visible ?? true,
isMinimized: () => overrides.minimized ?? false,
};
}
function setup(hud = windowState(), priority: ReturnType<typeof windowState> | null = null) {
return {
stopRecording: vi.fn(() => false),
getPriorityWindow: () => priority,
getHudWindow: () => hud,
showHud: vi.fn(),
showMain: vi.fn(),
};
}
describe("desktop icon activation", () => {
it("keeps a visible HUD in front without raising Home beside it", () => {
const options = setup();
activateFromDesktopIcon(options);
expect(options.showHud).toHaveBeenCalledOnce();
expect(options.showMain).not.toHaveBeenCalled();
});
it("preserves recording stop clicks without opening any window", () => {
const options = setup();
options.stopRecording.mockReturnValue(true);
activateFromDesktopIcon(options);
expect(options.showHud).not.toHaveBeenCalled();
expect(options.showMain).not.toHaveBeenCalled();
});
for (const state of [{ visible: false }, { minimized: true }, { destroyed: true }]) {
it(`restores the main window when the HUD is unavailable: ${JSON.stringify(state)}`, () => {
const options = setup(windowState(state));
activateFromDesktopIcon(options);
expect(options.showMain).toHaveBeenCalledOnce();
expect(options.showHud).not.toHaveBeenCalled();
});
}
it("preserves onboarding and update dialog priority", () => {
const options = setup(windowState(), windowState());
activateFromDesktopIcon(options);
expect(options.showMain).toHaveBeenCalledOnce();
expect(options.showHud).not.toHaveBeenCalled();
});
it("does not let a destroyed priority window prevent access to the HUD", () => {
const options = setup(windowState(), windowState({ destroyed: true }));
activateFromDesktopIcon(options);
expect(options.showHud).toHaveBeenCalledOnce();
expect(options.showMain).not.toHaveBeenCalled();
});
it("reopens the main window when no HUD remains", () => {
const options = { ...setup(), getHudWindow: () => null };
activateFromDesktopIcon(options);
expect(options.showMain).toHaveBeenCalledOnce();
});
});