d3ro-voice/apps/desktop/tests/e2e/settings.spec.ts
2026-08-29 18:33:45 +09:00

94 lines
3.1 KiB
TypeScript

import { test, expect, _electron as electron } from '@playwright/test';
test.describe('Settings Modal E2E', () => {
test.describe.configure({ mode: 'serial' });
let electronApp: any;
let window: any;
test.beforeAll(async () => {
electronApp = await electron.launch({
args: ['out/main/index.js', '--user-data-dir=C:/Users/encep/AppData/Local/Temp/playwright-d3ro-test-settings'],
env: {
...process.env,
NODE_ENV: 'test',
},
});
let found = false;
for (const w of electronApp.windows()) {
await w.waitForLoadState('domcontentloaded');
const t = await w.title();
if (t === 'D3RO Voice' || t === 'd3ro-voice') {
window = w;
found = true;
break;
}
}
if (!found) {
window = await electronApp.waitForEvent('window', {
predicate: async (page) => {
await page.waitForLoadState('domcontentloaded');
const t = await page.title();
return t === 'D3RO Voice' || t === 'd3ro-voice';
}
});
}
// Bypass onboarding via IPC config set
await window.evaluate(async () => {
if (window.electronAPI && window.electronAPI.config) {
await window.electronAPI.config.set({ key: 'onboardingCompleted', value: true });
await window.electronAPI.config.set({ key: 'appUsageMode', value: 'online' });
await window.electronAPI.config.set({ key: 'llmBackend', value: 'online' });
}
});
// Wait for the config to propagate then reload the page
await window.waitForTimeout(500);
await window.reload();
await window.waitForLoadState('domcontentloaded');
// Wait for React to mount AppLayout
await window.waitForTimeout(1000);
});
test.afterAll(async () => {
if (electronApp) {
await electronApp.close();
}
});
test('should open Settings Modal and navigate through tabs', async () => {
// Open Settings via IPC event instead of clicking the UI
await window.evaluate(() => {
window.dispatchEvent(new CustomEvent('d3ro:open-settings'));
});
// Wait for the Settings modal to appear by checking for a known tab or title
const tabs = window.locator('.MuiTab-root');
await expect(tabs.first()).toBeVisible({ timeout: 5000 });
// Since MuiDialog might have transition, wait a bit
await window.waitForTimeout(1000);
// Verify there are tabs available
const tabCount = await tabs.count();
expect(tabCount).toBeGreaterThan(0);
// Click through each tab (use force to bypass potential transition overlays)
for (let i = 0; i < tabCount; i++) {
await tabs.nth(i).click({ force: true });
await window.waitForTimeout(300); // Allow content to switch
const isSelected = await tabs.nth(i).getAttribute('aria-selected');
expect(isSelected).toBe('true');
}
// Close the settings modal using the Close button if it exists, or via Escape key
await window.keyboard.press('Escape');
// Wait for the modal to disappear
await expect(tabs.first()).toBeHidden({ timeout: 5000 });
});
});