mirror of
https://github.com/hanzoai/studio-desktop.git
synced 2026-10-30 18:21:16 +00:00
## Runtime change - Fixes window state not saved on launch ## Test changes - Updates integration test locators for frontend v1.27.x - Removes obsolete migrate step from install flow ### Migration step changes Migration is now combined with the install location step as an accordion section. ### Test locators updated - GPU selection: "Select GPU" → "Choose your hardware setup" - Install location: Updated input selector to use placeholder - Server status: "Finishing..." → "Loading Human Interface" - CPU toggle: Updated to role-based selector ### Window state fix Window bounds now captured on launch. Previously only saved on resize/move events. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-1369-Update-integration-tests-for-v0-5-compatibility-2876d73d3650811c88f1c81e55994f6b) by [Unito](https://www.unito.io) --------- Co-authored-by: github-actions <[email protected]>
112 lines
3.3 KiB
TypeScript
112 lines
3.3 KiB
TypeScript
import { BrowserWindow, type Tray } from 'electron';
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import { AppWindow } from '@/main-process/appWindow';
|
|
|
|
import { type PartialMock, electronMock } from '../setup';
|
|
|
|
const additionalMocks: PartialMock<typeof Electron> = {
|
|
BrowserWindow: vi.fn() as PartialMock<BrowserWindow>,
|
|
nativeTheme: {
|
|
shouldUseDarkColors: true,
|
|
},
|
|
Menu: {
|
|
buildFromTemplate: vi.fn(),
|
|
getApplicationMenu: vi.fn(() => null),
|
|
},
|
|
Tray: vi.fn(() => ({
|
|
setContextMenu: vi.fn(),
|
|
setPressedImage: vi.fn(),
|
|
setToolTip: vi.fn(),
|
|
on: vi.fn(),
|
|
})) as PartialMock<Tray>,
|
|
screen: {
|
|
getPrimaryDisplay: vi.fn(() => ({
|
|
workAreaSize: { width: 1024, height: 768 },
|
|
})),
|
|
},
|
|
};
|
|
|
|
Object.assign(electronMock, additionalMocks);
|
|
|
|
vi.mock('electron-store', () => ({
|
|
default: vi.fn(() => ({
|
|
get: vi.fn(),
|
|
set: vi.fn(),
|
|
})),
|
|
}));
|
|
|
|
vi.mock('@/store/desktopConfig', () => ({
|
|
useDesktopConfig: vi.fn(() => ({
|
|
get: vi.fn((key: string) => {
|
|
if (key === 'installState') return 'installed';
|
|
}),
|
|
set: vi.fn(),
|
|
})),
|
|
}));
|
|
|
|
describe('AppWindow.isOnPage', () => {
|
|
let appWindow: AppWindow;
|
|
let mockWebContents: Pick<Electron.WebContents, 'getURL' | 'setWindowOpenHandler'>;
|
|
|
|
beforeEach(() => {
|
|
mockWebContents = {
|
|
getURL: vi.fn(),
|
|
setWindowOpenHandler: vi.fn(),
|
|
};
|
|
|
|
vi.stubGlobal('process', {
|
|
...process,
|
|
resourcesPath: '/mock/app/path/assets',
|
|
});
|
|
|
|
vi.mocked(BrowserWindow).mockImplementation(
|
|
() =>
|
|
({
|
|
webContents: mockWebContents,
|
|
on: vi.fn(),
|
|
once: vi.fn(),
|
|
isMaximized: vi.fn(() => false),
|
|
getBounds: vi.fn(() => ({ x: 0, y: 0, width: 1024, height: 768 })),
|
|
}) as unknown as BrowserWindow
|
|
);
|
|
|
|
appWindow = new AppWindow(undefined, undefined, false);
|
|
});
|
|
|
|
it('should handle file protocol URLs with hash correctly', () => {
|
|
vi.mocked(mockWebContents.getURL).mockReturnValue('file:///path/to/index.html#welcome');
|
|
expect(appWindow.isOnPage('welcome')).toBe(true);
|
|
});
|
|
|
|
it('should handle http protocol URLs correctly', () => {
|
|
vi.mocked(mockWebContents.getURL).mockReturnValue('http://localhost:3000/welcome');
|
|
expect(appWindow.isOnPage('welcome')).toBe(true);
|
|
});
|
|
|
|
it('should handle empty pages correctly', () => {
|
|
vi.mocked(mockWebContents.getURL).mockReturnValue('file:///path/to/index.html');
|
|
expect(appWindow.isOnPage('')).toBe(true);
|
|
});
|
|
|
|
it('should return false for non-matching pages', () => {
|
|
vi.mocked(mockWebContents.getURL).mockReturnValue('file:///path/to/index.html#welcome');
|
|
expect(appWindow.isOnPage('desktop-start')).toBe(false);
|
|
});
|
|
|
|
it('should handle URLs with no hash or path', () => {
|
|
vi.mocked(mockWebContents.getURL).mockReturnValue('http://localhost:3000');
|
|
expect(appWindow.isOnPage('')).toBe(true);
|
|
});
|
|
|
|
it('should handle URLs with query parameters', () => {
|
|
vi.mocked(mockWebContents.getURL).mockReturnValue('http://localhost:3000/server-start?param=value');
|
|
expect(appWindow.isOnPage('server-start')).toBe(true);
|
|
});
|
|
|
|
it('should handle file URLs with both hash and query parameters', () => {
|
|
vi.mocked(mockWebContents.getURL).mockReturnValue('file:///path/to/index.html?param=value#welcome');
|
|
expect(appWindow.isOnPage('welcome')).toBe(true);
|
|
});
|
|
});
|