Skip to content

Commit

Permalink
Add electron playwright test case that opens a file
Browse files Browse the repository at this point in the history
Contributed on behalf of STMicroelectronics

Signed-off-by: Olaf Lessenich <[email protected]>
  • Loading branch information
xai committed Mar 30, 2023
1 parent 17c3a58 commit a70cf99
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions examples/playwright/src/tests/theia-electron-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
Expand Down

0 comments on commit a70cf99

Please sign in to comment.