Skip to content

Commit

Permalink
Fix unit test case by adapting to new Theia behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-fleck-at committed Jul 5, 2024
1 parent f58d931 commit 44f81a3
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 20 deletions.
33 changes: 26 additions & 7 deletions e2e-tests/src/tests/crossmodel-explorer-view.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
/********************************************************************************
* Copyright (c) 2023 CrossBreeze.
********************************************************************************/
import { expect } from '@playwright/test';
import { expect, Page } from '@playwright/test';
import test, { app } from '../fixtures/crossmodel-fixture';
import { CrossModelExplorerView } from '../page-objects/crossmodel-explorer-view';

let explorer: CrossModelExplorerView;

async function checkOpenWithItem(page: Page, text: string): Promise<boolean> {
// Locate all elements matching the selector
const elements = await page.$$('.quick-input-list .monaco-highlighted-label');

// Iterate over elements to check for visibility and text content
for (const element of elements) {
if (await element.isVisible()) {
const textContent = await element.textContent();
if (textContent?.includes(text)) {
return true;
}
}
}
return false;
}

test.describe('CrossModel Explorer View', () => {
test.beforeAll(async ({ browser }) => {
explorer = await app.openView(CrossModelExplorerView);
Expand All @@ -20,8 +36,9 @@ test.describe('CrossModel Explorer View', () => {
const menu = await file.openContextMenu();
expect(await menu.isOpen()).toBe(true);
// Expect the Code and Form editor to be in the Open With menu option.
expect(await menu.menuItemByNamePath('Open With', 'Code Editor')).toBeDefined();
expect(await menu.menuItemByNamePath('Open With', 'Form Editor')).toBeDefined();
await menu.clickMenuItem('Open With...');
expect(await checkOpenWithItem(explorer.page, 'Text Editor')).toBeTruthy();
expect(await checkOpenWithItem(explorer.page, 'Form Editor')).toBeTruthy();
await menu.close();
});

Expand All @@ -32,8 +49,9 @@ test.describe('CrossModel Explorer View', () => {
const menu = await file.openContextMenu();
expect(await menu.isOpen()).toBe(true);
// Expect the Code and Form editor to be in the Open With menu option.
expect(await menu.menuItemByNamePath('Open With', 'Code Editor')).toBeDefined();
expect(await menu.menuItemByNamePath('Open With', 'Form Editor')).toBeDefined();
await menu.clickMenuItem('Open With...');
expect(await checkOpenWithItem(explorer.page, 'Text Editor')).toBeTruthy();
expect(await checkOpenWithItem(explorer.page, 'Form Editor')).toBeTruthy();
await menu.close();
});

Expand All @@ -44,8 +62,9 @@ test.describe('CrossModel Explorer View', () => {
const menu = await file.openContextMenu();
expect(await menu.isOpen()).toBe(true);
// Expect the Code and Form editor to be in the Open With menu option.
expect(await menu.menuItemByNamePath('Open With', 'Code Editor')).toBeDefined();
expect(await menu.menuItemByNamePath('Open With', 'System Diagram')).toBeDefined();
await menu.clickMenuItem('Open With...');
expect(await checkOpenWithItem(explorer.page, 'Text Editor')).toBeTruthy();
expect(await checkOpenWithItem(explorer.page, 'System Diagram')).toBeTruthy();
await menu.close();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
* Copyright (c) 2023 CrossBreeze.
********************************************************************************/

import { NavigatableWidgetOptions, OpenHandler, WidgetFactory } from '@theia/core/lib/browser';
import { CrossModelWidgetOptions } from '@crossbreeze/core/lib/browser';
import { FrontendApplicationContribution, NavigatableWidgetOptions, OpenHandler, WidgetFactory } from '@theia/core/lib/browser';
import { ContainerModule } from '@theia/core/shared/inversify';
import { FormEditorOpenHandler, createFormEditorId } from './form-editor-open-handler';
import { FormEditorWidget, FormEditorWidgetOptions } from './form-editor-widget';
import { CrossModelWidgetOptions } from '@crossbreeze/core/lib/browser';

export default new ContainerModule(bind => {
bind(OpenHandler).to(FormEditorOpenHandler).inSingletonScope();
bind(FormEditorOpenHandler).toSelf().inSingletonScope();
bind(OpenHandler).toService(FormEditorOpenHandler);
bind(FrontendApplicationContribution).toService(FormEditorOpenHandler);
bind<WidgetFactory>(WidgetFactory).toDynamicValue(context => ({
id: FormEditorOpenHandler.ID, // must match the id in the open handler
createWidget: (navigatableOptions: NavigatableWidgetOptions) => {
Expand Down
25 changes: 20 additions & 5 deletions packages/form-client/src/browser/form-editor-open-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,35 @@
* Copyright (c) 2023 CrossBreeze.
********************************************************************************/

import { MaybePromise, nls } from '@theia/core';
import { NavigatableWidgetOpenHandler } from '@theia/core/lib/browser';
import { nls } from '@theia/core';
import { FrontendApplicationContribution, NavigatableWidgetOpenHandler, OpenWithHandler, OpenWithService } from '@theia/core/lib/browser';
import URI from '@theia/core/lib/common/uri';
import { injectable } from '@theia/core/shared/inversify';
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
import { FormEditorWidget } from './form-editor-widget';

@injectable()
export class FormEditorOpenHandler extends NavigatableWidgetOpenHandler<FormEditorWidget> {
export class FormEditorOpenHandler
extends NavigatableWidgetOpenHandler<FormEditorWidget>
implements OpenWithHandler, FrontendApplicationContribution
{
static ID = 'form-editor-opener';

readonly id = FormEditorOpenHandler.ID; // must match the id of the widget factory
readonly label = nls.localize('form-client/form-editor', 'Form Editor');

canHandle(uri: URI): MaybePromise<number> {
@inject(OpenWithService) protected readonly openWithService: OpenWithService;

initialize(): void {
// ensure this class is instantiated early
}

@postConstruct()
protected override init(): void {
this.openWithService.registerHandler(this);
super.init();
}

canHandle(uri: URI): number {
return uri.path.ext === '.cm' ? 1 : -1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@
* Copyright (c) 2024 CrossBreeze.
********************************************************************************/

import { codiconCSSString } from '@eclipse-glsp/client';
import { GLSPDiagramManager } from '@eclipse-glsp/theia-integration';
import { URI } from '@theia/core';
import { WidgetOpenerOptions } from '@theia/core/lib/browser';
import { injectable } from '@theia/core/shared/inversify';
import { OpenWithHandler, OpenWithService, WidgetOpenerOptions } from '@theia/core/lib/browser';
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
import { MappingDiagramLanguage } from '../../common/crossmodel-diagram-language';
import { codiconCSSString } from '@eclipse-glsp/client';

export interface ProblemMarkerOpenerOptions extends WidgetOpenerOptions {
selection?: Range;
}

@injectable()
export class MappingDiagramManager extends GLSPDiagramManager {
export class MappingDiagramManager extends GLSPDiagramManager implements OpenWithHandler {
@inject(OpenWithService) protected readonly openWithService: OpenWithService;

@postConstruct()
protected override init(): void {
this.openWithService.registerHandler(this);
super.init();
}

get label(): string {
return MappingDiagramLanguage.label;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
DiagramConfiguration,
GLSPClientContribution,
GLSPDiagramWidget,
GLSPTheiaFrontendModule
GLSPTheiaFrontendModule,
registerDiagramManager
} from '@eclipse-glsp/theia-integration';

import { SystemDiagramLanguage } from '../../common/crossmodel-diagram-language';
import { CrossModelClientContribution } from '../crossmodel-client-contribution';
import { SystemDiagramConfiguration } from './system-diagram-configuration';
import { SystemDiagramManager } from './system-diagram-manager';
import { SystemDiagramWidget } from './system-diagram-widget';

export class SystemDiagramModule extends GLSPTheiaFrontendModule {
Expand All @@ -32,6 +34,11 @@ export class SystemDiagramModule extends GLSPTheiaFrontendModule {
super.bindDiagramWidgetFactory(context);
context.rebind(GLSPDiagramWidget).to(SystemDiagramWidget);
}

override configureDiagramManager(context: ContainerContext): void {
context.bind(SystemDiagramManager).toSelf().inSingletonScope();
registerDiagramManager(context.bind, SystemDiagramManager, false);
}
}

export default new SystemDiagramModule();
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/********************************************************************************
* Copyright (c) 2024 CrossBreeze.
********************************************************************************/

import { codiconCSSString } from '@eclipse-glsp/client';
import { GLSPDiagramManager } from '@eclipse-glsp/theia-integration';
import { OpenWithHandler, OpenWithService } from '@theia/core/lib/browser';
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
import { SystemDiagramLanguage } from '../../common/crossmodel-diagram-language';

@injectable()
export class SystemDiagramManager extends GLSPDiagramManager implements OpenWithHandler {
@inject(OpenWithService) protected readonly openWithService: OpenWithService;

@postConstruct()
protected override init(): void {
this.openWithService.registerHandler(this);
super.init();
}

get label(): string {
return SystemDiagramLanguage.label;
}

override get iconClass(): string {
return SystemDiagramLanguage.iconClass ?? codiconCSSString('type-hierarchy-sub');
}

override get fileExtensions(): string[] {
return SystemDiagramLanguage.fileExtensions;
}

override get diagramType(): string {
return SystemDiagramLanguage.diagramType;
}

override get contributionId(): string {
return SystemDiagramLanguage.contributionId;
}
}

0 comments on commit 44f81a3

Please sign in to comment.