From a70cf99230e9f38318006942e53d43bc0e7f5d75 Mon Sep 17 00:00:00 2001 From: Olaf Lessenich Date: Thu, 30 Mar 2023 11:02:27 +0200 Subject: [PATCH] Add electron playwright test case that opens a file Contributed on behalf of STMicroelectronics Signed-off-by: Olaf Lessenich --- .../src/tests/theia-electron-app.test.ts | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/examples/playwright/src/tests/theia-electron-app.test.ts b/examples/playwright/src/tests/theia-electron-app.test.ts index 3f25c78573934..03cab35ea55c0 100644 --- a/examples/playwright/src/tests/theia-electron-app.test.ts +++ b/examples/playwright/src/tests/theia-electron-app.test.ts @@ -21,16 +21,20 @@ import { ElectronLaunchOptions, TheiaElectronAppLoader } from '../theia-app-load import { TheiaWorkspace } from '../theia-workspace'; import { TheiaApp } from '../theia-app'; +test.describe.configure({ mode: 'serial' }); test.describe('Theia Electron Application', () => { - let ws: TheiaWorkspace; let app: TheiaApp; test.beforeAll(async () => { - ws = new TheiaWorkspace(['src/tests/resources/sample-files1']); + const ws = new TheiaWorkspace(['src/tests/resources/sample-files1']); app = await TheiaElectronAppLoader.load(new ElectronLaunchOptions('../electron', '../../plugins'), ws); }); + test.afterAll(async () => { + await app.page.close(); + }); + test('should load and show main content panel', async () => { expect(await app.isMainContentPanelVisible()).toBe(true); }); @@ -44,6 +48,27 @@ test.describe('Theia Electron Application', () => { expect(await aboutDialog.isVisible()).toBe(false); }); + test('open file via file menu and cancel', async () => { + await (await app.menuBar.openMenu('File')).clickMenuItem('Open File...'); + const fileDialog = await app.page.waitForSelector('div[class="dialogBlock"]'); + expect(await fileDialog.isVisible()).toBe(true); + await app.page.getByRole('button', { name: 'Cancel' }).click(); + expect(await fileDialog.isVisible()).toBe(false); + }); + + test('open sample.txt via file menu', async () => { + await (await app.menuBar.openMenu('File')).clickMenuItem('Open File...'); + const fileDialog = await app.page.waitForSelector('div[class="dialogBlock"]'); + expect(await fileDialog.isVisible()).toBe(true); + + const fileEntry = app.page.getByText('sample.txt'); + await fileEntry.click(); + await app.page.getByRole('button', { name: 'Open' }).click(); + + const span = await app.page.waitForSelector('span:has-text("contentĀ lineĀ 2")'); + expect(await span.isVisible()).toBe(true); + }); + test('toggle explorer view using menu', async () => { await (await app.menuBar.openMenu('View')).clickMenuItem('Explorer'); const explorerView = new TheiaExplorerView(app);