Skip to content

Commit

Permalink
Reduce complexity (#21)
Browse files Browse the repository at this point in the history
* Remove by selector/locator methods

* Use getNodeByLabel where possible

* Allow to query by selectorOrLocator for edges and between nodes
  • Loading branch information
haydar-metin authored Aug 8, 2024
1 parent c3db6e0 commit dac91d5
Show file tree
Hide file tree
Showing 22 changed files with 257 additions and 162 deletions.
18 changes: 16 additions & 2 deletions examples/workflow-test/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
import 'reflect-metadata';

import type { GLSPPlaywrightOptions } from '@eclipse-glsp/glsp-playwright';
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices, type PlaywrightTestConfig } from '@playwright/test';
import * as dotenv from 'dotenv';
import { createStandaloneProject, createTheiaProject, createVSCodeProject } from './configs/project.config';
import { getEnv } from './configs/utils';
import { createWebserver, hasRunningServer } from './configs/webserver.config';

dotenv.config();
Expand All @@ -40,7 +41,20 @@ const config: PlaywrightTestConfig<GLSPPlaywrightOptions> = {
trace: 'on-first-retry'
},
webServer: createWebserver(),
projects: []
projects: [
// Required for VSCode Extension tests
{
name: 'standalone',
testMatch: ['**/*.spec.js'],
use: {
...devices['Desktop Chrome'],
integrationOptions: {
type: 'Standalone',
url: getEnv('STANDALONE_URL')!
}
}
}
]
};

if (hasRunningServer(config)) {
Expand Down
18 changes: 11 additions & 7 deletions examples/workflow-test/src/graph/workflow.graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { GLSPSemanticGraph, PNode, PNodeConstructor, waitForFunction } from '@eclipse-glsp/glsp-playwright/';
import { GLSPSemanticGraph, waitForFunction } from '@eclipse-glsp/glsp-playwright/';
import { isPNodeConstructor, PModelElement, PModelElementConstructor } from '@eclipse-glsp/glsp-playwright/src/glsp';

export class WorkflowGraph extends GLSPSemanticGraph {
override async waitForCreationOfNodeType<TElement extends PNode>(
constructor: PNodeConstructor<TElement>,
override async waitForCreationOfType<TElement extends PModelElement>(
constructor: PModelElementConstructor<TElement>,
creator: () => Promise<void>
): Promise<TElement[]> {
const elements = await super.waitForCreationOfNodeType(constructor, creator);
const elements = await super.waitForCreationOfType(constructor, creator);

if (isPNodeConstructor(constructor)) {
await waitForFunction(async () =>
elements.every(element => element.locate().evaluate(node => node?.classList.contains('selected')))
);
}

await waitForFunction(async () =>
elements.every(element => element.locate().evaluate(node => node?.classList.contains('selected')))
);
return elements;
}
}
8 changes: 5 additions & 3 deletions examples/workflow-test/tests/core/connectable-element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { Edge } from '../../src/graph/elements/edge.po';
import { TaskManual } from '../../src/graph/elements/task-manual.po';
import { WorkflowGraph } from '../../src/graph/workflow.graph';

const elementLabel = 'Push';

test.describe('The edge accessor of a connectable element', () => {
let app: WorkflowApp;
let graph: WorkflowGraph;
Expand All @@ -33,7 +35,7 @@ test.describe('The edge accessor of a connectable element', () => {
});

test('should allow accessing all edges of a type', async () => {
const task = await graph.getNodeBySelector('[id$="task_Push"]', TaskManual);
const task = await graph.getNodeByLabel(elementLabel, TaskManual);
const edges = await task.edges().outgoingEdgesOfType(Edge);

const ids = await Promise.all(edges.map(async e => e.idAttr()));
Expand All @@ -48,7 +50,7 @@ test.describe('The edge accessor of a connectable element', () => {
});

test('should return typed sources on access', async () => {
const task = await graph.getNodeBySelector('[id$="task_Push"]', TaskManual);
const task = await graph.getNodeByLabel(elementLabel, TaskManual);
const edges = await task.edges().outgoingEdgesOfType(Edge);
expect(edges.length).toBe(1);

Expand All @@ -58,7 +60,7 @@ test.describe('The edge accessor of a connectable element', () => {
});

test('should allow accessing all edges of a type against a target type', async () => {
const task = await graph.getNodeBySelector('[id$="task_Push"]', TaskManual);
const task = await graph.getNodeByLabel(elementLabel, TaskManual);
const edges = await task.edges().outgoingEdgesOfType(Edge, { targetConstructor: ActivityNodeFork });
expect(edges.length).toBe(1);

Expand Down
4 changes: 2 additions & 2 deletions examples/workflow-test/tests/core/debug.standalone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test.describe('The debug functions', () => {
* It is possible to extract all the accessible SVG metadata of a locator as a tree structure.
*/
test('should allow to extract the metadata of a locator', async () => {
const node = await graph.getNodeBySelector(taskSelector, TaskManual);
const node = await graph.getNode(taskSelector, TaskManual);

const metadata = await extractMetaTree(node.locate());
expect(metadata).toMatchObject(expectedElementMetadata);
Expand All @@ -84,7 +84,7 @@ test.describe('The debug functions', () => {
* It is possible to retrieve all the located HTML elements of a GLSPLocator and it's ascendants.
*/
test('should allow to extract debug information of a GLSPLocator', async () => {
const node = await graph.getNodeBySelector(taskSelector, TaskManual);
const node = await graph.getNode(taskSelector, TaskManual);

const extracted = await extractDebugInformationOfGLSPLocator(node.locator);
expect(extracted).toMatchObject(expectedGLSPLocatorData);
Expand Down
8 changes: 5 additions & 3 deletions examples/workflow-test/tests/core/edge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { Edge } from '../../src/graph/elements/edge.po';
import { TaskManual } from '../../src/graph/elements/task-manual.po';
import { WorkflowGraph } from '../../src/graph/workflow.graph';

const elementLabel = 'Push';

test.describe('Edges', () => {
let app: WorkflowApp;
let graph: WorkflowGraph;
Expand All @@ -33,9 +35,9 @@ test.describe('Edges', () => {
});

test('should have source and target nodes', async () => {
const source = await graph.getNodeBySelector('[id$="task_Push"]', TaskManual);
const target = await graph.getNodeBySelector('[id$="fork_1"]', ActivityNodeFork);
const edge = await graph.getEdgeBySelector('[id$="edge_task_Push_fork_1"]', Edge);
const source = await graph.getNodeByLabel(elementLabel, TaskManual);
const target = await graph.getNode('[id$="fork_1"]', ActivityNodeFork);
const edge = await graph.getEdgeBetween(Edge, { sourceNode: source, targetNode: target });

const sourceId = await edge.sourceId();
expect(sourceId).toBe(await source.idAttr());
Expand Down
4 changes: 3 additions & 1 deletion examples/workflow-test/tests/core/flows/deletable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { WorkflowApp } from '../../../src/app/workflow-app';
import { TaskManual } from '../../../src/graph/elements/task-manual.po';
import { WorkflowGraph } from '../../../src/graph/workflow.graph';

const elementLabel = 'Push';

test.describe('Deletable flow', () => {
let app: WorkflowApp;
let graph: WorkflowGraph;
Expand All @@ -31,7 +33,7 @@ test.describe('Deletable flow', () => {
});

test('should delete element', async () => {
const task = await graph.getNodeBySelector('[id$="task_Push"]', TaskManual);
const task = await graph.getNodeByLabel(elementLabel, TaskManual);

expect(await task.locate().count()).toBe(1);
await task.delete();
Expand Down
7 changes: 4 additions & 3 deletions examples/workflow-test/tests/core/graph.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test.describe('The graph', () => {

test.describe('should allow accessing the edge', () => {
test('by using a selector', async () => {
const edge = await graph.getEdgeBySelector('[id$="edge_task_Push_fork_1"]', Edge);
const edge = await graph.getEdge('[id$="edge_task_Push_fork_1"]', Edge);
const task = await edge.sourceOfType(TaskManual);

expect(await (await task.children.label()).textContent()).toBe('Push');
Expand All @@ -55,11 +55,12 @@ test.describe('The graph', () => {
});

test('by using a source selector', async () => {
const edges = await graph.getEdgesOfType(Edge, { sourceSelector: '[id$="task_Push"]' });
const sourceNode = await graph.getNodeByLabel('Push', TaskManual);
const edges = await graph.getEdgesOfType(Edge, { sourceSelectorOrLocator: sourceNode.locate() });
expect(edges.length).toBe(1);

const source = await edges[0].sourceOfType(TaskManual);
expect(await source.idAttr()).toContain('task_Push');
expect(await source.idAttr()).toContain(await sourceNode.idAttr());
});

test('by using the source type with multiple elements', async () => {
Expand Down
10 changes: 6 additions & 4 deletions examples/workflow-test/tests/core/parent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { LabelHeading } from '../../src/graph/elements/label-heading.po';
import { TaskManual } from '../../src/graph/elements/task-manual.po';
import { WorkflowGraph } from '../../src/graph/workflow.graph';

const elementLabel = 'Push';

test.describe('The children accessor of a parent element', () => {
let app: WorkflowApp;
let graph: WorkflowGraph;
Expand All @@ -32,7 +34,7 @@ test.describe('The children accessor of a parent element', () => {
});

test('should allow to access all elements by using a type', async () => {
const task = await graph.getNodeBySelector('[id$="task_Push"]', TaskManual);
const task = await graph.getNodeByLabel(elementLabel, TaskManual);
const children = task.children;

const labels = await children.allOfType(LabelHeading);
Expand All @@ -43,23 +45,23 @@ test.describe('The children accessor of a parent element', () => {
});

test('should allow to access the element by using a type', async () => {
const task = await graph.getNodeBySelector('[id$="task_Push"]', TaskManual);
const task = await graph.getNodeByLabel(elementLabel, TaskManual);
const children = task.children;

const label = await children.ofType(LabelHeading);
expect(await label.textContent()).toBe('Push');
});

test('should allow to access the element by using a type and a selector', async () => {
const task = await graph.getNodeBySelector('[id$="task_Push"]', TaskManual);
const task = await graph.getNodeByLabel(elementLabel, TaskManual);
const children = task.children;

const label = await children.ofType(LabelHeading, { selector: '[id$="task_Push_label"]' });
expect(await label.textContent()).toBe('Push');
});

test('should allow to use typed elements', async () => {
const task = await graph.getNodeBySelector('[id$="task_Push"]', TaskManual);
const task = await graph.getNodeByLabel(elementLabel, TaskManual);
const children = task.children;

const label = await children.label();
Expand Down
4 changes: 3 additions & 1 deletion examples/workflow-test/tests/core/shortcuts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { WorkflowApp } from '../../src/app/workflow-app';
import { TaskManual } from '../../src/graph/elements/task-manual.po';
import { WorkflowGraph } from '../../src/graph/workflow.graph';

const elementLabel = 'Push';

test.describe('Shortcuts', () => {
let app: WorkflowApp;
let graph: WorkflowGraph;
Expand All @@ -31,7 +33,7 @@ test.describe('Shortcuts', () => {
});

test('should allow deleting the element in the graph', async ({ integration }) => {
const task = await graph.getNodeBySelector('[id$="task_Push"]', TaskManual);
const task = await graph.getNodeByLabel(elementLabel, TaskManual);
expect(await task.isVisible()).toBeTruthy();

await task.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { WorkflowApp } from '../../../src/app/workflow-app';
import { TaskManual } from '../../../src/graph/elements/task-manual.po';
import { WorkflowGraph } from '../../../src/graph/workflow.graph';

const elementLabel = 'Push';

test.describe('The resizing handle', () => {
let app: WorkflowApp;
let graph: WorkflowGraph;
Expand All @@ -31,7 +33,7 @@ test.describe('The resizing handle', () => {
});

test('should allow resizing', async () => {
const task = await graph.getNodeBySelector('[id$="task_Push"]', TaskManual);
const task = await graph.getNodeByLabel(elementLabel, TaskManual);

const oldBounds = await task.bounds();
const oldTopLeft = oldBounds.position('top_left');
Expand All @@ -50,9 +52,9 @@ test.describe('The resizing handle', () => {
});

test('should show 4 handles', async () => {
const task = await graph.getNodeBySelector('[id$="task_Push"]', TaskManual);
const task = await graph.getNodeByLabel(elementLabel, TaskManual);

await graph.waitForCreationOfType(PMetadata.getType(ResizeHandle), async () => {
await graph.waitForCreation(PMetadata.getType(ResizeHandle), async () => {
await task.click();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { TaskAutomated } from '../../../src/graph/elements/task-automated.po';
import { TaskManual } from '../../../src/graph/elements/task-manual.po';
import { WorkflowGraph } from '../../../src/graph/workflow.graph';

const element1Label = 'Push';
const element2Label = 'ChkWt';

test.describe('The command palette', () => {
let app: WorkflowApp;
let graph: WorkflowGraph;
Expand Down Expand Up @@ -75,7 +78,7 @@ test.describe('The command palette', () => {
test('should allow to confirm suggestions', async () => {
const before = await graph.getNodesOfType(TaskManual);

await graph.waitForCreationOfNodeType(TaskManual, async () => {
await graph.waitForCreationOfType(TaskManual, async () => {
await globalCommandPalette.open();
await globalCommandPalette.search('Create');
await globalCommandPalette.confirm('Create Manual Task');
Expand All @@ -94,7 +97,7 @@ test.describe('The command palette', () => {
});

test('should allow creating new elements in the diagram', async () => {
const nodes = await graph.waitForCreationOfNodeType(TaskManual, async () => {
const nodes = await graph.waitForCreationOfType(TaskManual, async () => {
const command = await app.globalCommandPalette;
await command.open();
await command.search('Create Manual Task', { confirm: true });
Expand All @@ -111,7 +114,7 @@ test.describe('The command palette', () => {

test.describe('in the element context', () => {
test('should allow to search suggestions', async () => {
const task = await graph.getNodeBySelector('[id$="task_Push"]', TaskManual);
const task = await graph.getNodeByLabel(element1Label, TaskManual);

const elementCommandPalette = await task.commandPalette();
await elementCommandPalette.open();
Expand Down Expand Up @@ -179,9 +182,9 @@ test.describe('The command palette', () => {
});

test('should allow creating new elements in the diagram', async () => {
const task = await graph.getNodeBySelector('[id$="task_Push"]', TaskManual);
const task = await graph.getNodeByLabel(element1Label, TaskManual);

const nodes = await graph.waitForCreationOfNodeType(TaskManual, async () => {
const nodes = await graph.waitForCreationOfType(TaskManual, async () => {
const command = task.commandPalette();
await command.open();
await command.search('Create Manual Task', { confirm: true });
Expand All @@ -196,10 +199,10 @@ test.describe('The command palette', () => {
});

test('should allow creating edges in the graph', async () => {
const source = await graph.getNodeBySelector('[id$="task_Push"]', TaskManual);
const target = await graph.getNodeBySelector('[id$="task_ChkWt"]', TaskAutomated);
const source = await graph.getNodeByLabel(element1Label, TaskManual);
const target = await graph.getNodeByLabel(element2Label, TaskAutomated);

const edges = await graph.waitForCreationOfEdgeType(Edge, async () => {
const edges = await graph.waitForCreationOfType(Edge, async () => {
const command = source.commandPalette();
await command.open();

Expand Down
Loading

0 comments on commit dac91d5

Please sign in to comment.