|
1 | | -import { _electron as electron, expect, test } from '@playwright/test'; |
2 | | -import { stubAllDialogs } from 'electron-playwright-helpers'; |
3 | | -import { mkdtempSync, rmSync } from 'fs'; |
4 | | -import { join } from 'path'; |
5 | | -import { tmpdir } from 'os'; |
6 | | - |
7 | | -let tempUserData: string; |
8 | | - |
9 | | -test.beforeEach(() => { |
10 | | - tempUserData = mkdtempSync(join(tmpdir(), 'jlab-e2e-')); |
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { cleanup, launchApp, pageByTitle } from './helpers'; |
| 3 | + |
| 4 | +test('app launches and opens at least one window', async () => { |
| 5 | + const { app, userDataDir } = await launchApp(); |
| 6 | + try { |
| 7 | + await app.firstWindow(); |
| 8 | + expect(app.windows().length).toBeGreaterThan(0); |
| 9 | + } finally { |
| 10 | + await app.close(); |
| 11 | + cleanup(userDataDir); |
| 12 | + } |
11 | 13 | }); |
12 | 14 |
|
13 | | -test.afterEach(async () => { |
14 | | - rmSync(tempUserData, { recursive: true, force: true }); |
| 15 | +test('on first run the Welcome window renders', async () => { |
| 16 | + const { app, userDataDir } = await launchApp(); |
| 17 | + try { |
| 18 | + // Selecting by title rather than firstWindow(): the app opens several |
| 19 | + // windows and only this one is the welcome view. |
| 20 | + const welcome = await pageByTitle(app, /welcome/i); |
| 21 | + await welcome.waitForLoadState('domcontentloaded'); |
| 22 | + // Assert a Welcome-specific element, not just body, so a blank or error |
| 23 | + // page would fail rather than pass. |
| 24 | + await expect(welcome.locator('#new-notebook-link')).toBeVisible(); |
| 25 | + } finally { |
| 26 | + await app.close(); |
| 27 | + cleanup(userDataDir); |
| 28 | + } |
15 | 29 | }); |
16 | 30 |
|
17 | | -test('app launches and shows a window', async () => { |
18 | | - const app = await electron.launch({ |
19 | | - args: ['.'], |
20 | | - env: { |
21 | | - ...process.env, |
22 | | - JLAB_DESKTOP_HOME: tempUserData, |
23 | | - ELECTRON_IS_TEST: '1' |
24 | | - } |
25 | | - }); |
26 | | - |
27 | | - await stubAllDialogs(app); |
28 | | - const window = await app.firstWindow(); |
29 | | - await window.waitForLoadState('domcontentloaded'); |
30 | | - |
31 | | - expect(app.windows().length).toBeGreaterThan(0); |
32 | | - await app.close(); |
| 31 | +test('the session window composes multiple views (titlebar + welcome + content)', async () => { |
| 32 | + const { app, userDataDir } = await launchApp(); |
| 33 | + try { |
| 34 | + // Once the welcome view has settled, the BrowserView/WebContentsView |
| 35 | + // composition should expose several views (titlebar, welcome, content area) |
| 36 | + // as separate pages. A dropped view after the Phase 3 WebContentsView |
| 37 | + // migration would lower this count. |
| 38 | + await pageByTitle(app, /welcome/i); |
| 39 | + await expect |
| 40 | + .poll(() => app.windows().length, { timeout: 10000 }) |
| 41 | + .toBeGreaterThanOrEqual(3); |
| 42 | + } finally { |
| 43 | + await app.close(); |
| 44 | + cleanup(userDataDir); |
| 45 | + } |
33 | 46 | }); |
34 | 47 |
|
35 | | -test('app exits with code 0', async () => { |
36 | | - const app = await electron.launch({ |
37 | | - args: ['.'], |
38 | | - env: { |
39 | | - ...process.env, |
40 | | - JLAB_DESKTOP_HOME: tempUserData, |
41 | | - ELECTRON_IS_TEST: '1' |
42 | | - } |
43 | | - }); |
44 | | - |
45 | | - await stubAllDialogs(app); |
46 | | - await app.firstWindow(); |
47 | | - |
48 | | - const exitCode = await app.close(); |
49 | | - expect(exitCode).toBe(0); |
50 | | -}); |
51 | | - |
52 | | -test('first-run shows env selection when no env configured', async () => { |
53 | | - const app = await electron.launch({ |
54 | | - args: ['.'], |
55 | | - env: { |
56 | | - ...process.env, |
57 | | - JLAB_DESKTOP_HOME: tempUserData, |
58 | | - ELECTRON_IS_TEST: '1', |
59 | | - // empty userData = no prior config = first run |
60 | | - APPDATA: tempUserData |
61 | | - } |
62 | | - }); |
63 | | - |
64 | | - await stubAllDialogs(app); |
65 | | - const window = await app.firstWindow(); |
66 | | - |
67 | | - // welcome view or env select should appear within 15s |
68 | | - await expect( |
69 | | - window.locator( |
70 | | - '#welcome-view, #env-select-dialog, [data-testid="env-select"]' |
71 | | - ) |
72 | | - ).toBeVisible({ timeout: 15000 }); |
73 | | - |
74 | | - await app.close(); |
| 48 | +test('app shuts down cleanly without hanging', async () => { |
| 49 | + const { app, userDataDir } = await launchApp(); |
| 50 | + try { |
| 51 | + await app.firstWindow(); |
| 52 | + } finally { |
| 53 | + // Close in finally so the Electron process is always terminated, even if |
| 54 | + // an earlier step throws. A hang here surfaces via the job timeout. |
| 55 | + await app.close(); |
| 56 | + cleanup(userDataDir); |
| 57 | + } |
| 58 | + // close() has resolved, so the process exited and the windows are gone. |
| 59 | + expect(app.windows().length).toBe(0); |
75 | 60 | }); |
0 commit comments