Skip to content

Commit

Permalink
Fix pan tests for Chromium & Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
csouchet committed Apr 30, 2021
1 parent d37a421 commit 10aad55
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
3 changes: 1 addition & 2 deletions test/e2e/bpmn.navigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
import 'jest-playwright-preset';
import { join } from 'path';
import { ImageSnapshotConfigurator, ImageSnapshotThresholdConfig, MultiBrowserImageSnapshotThresholds } from './helpers/visu/image-snapshot-config';
import { chromiumZoom, getContainerCenter, itMouseWheel, Point } from './helpers/test-utils';
import { chromiumZoom, getContainerCenter, itMouseWheel, mousePanning, Point } from './helpers/test-utils';
import { PageTester } from './helpers/visu/PageTester';
import { ElementHandle } from 'playwright';
import { mousePanning } from './helpers/visu/playwright-utils';

class ImageSnapshotThresholds extends MultiBrowserImageSnapshotThresholds {
constructor() {
Expand Down
16 changes: 9 additions & 7 deletions test/e2e/helpers/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import debugLogger from 'debug';
import { findFiles } from '../../helpers/file-helper';
import { join } from 'path';
import 'jest-playwright-preset';
import { chromiumMouseWheel } from './visu/playwright-utils';
import { chromiumMouseWheel, PanningOptions, webkitMousePanning } from './visu/playwright-utils';
import { ElementHandle } from 'playwright';

export interface Point {
Expand Down Expand Up @@ -73,16 +73,18 @@ export async function clickOnButton(buttonId: string): Promise<void> {
await page.mouse.click(0, 0);
}

/*
TODO To uncomment when https://github.com/microsoft/playwright/issues/1094 is fixed
export async function mousePanning(panningOptions: PanningOptions): Promise<void> {
const testedBrowserFamily = getTestedBrowserFamily();
testedBrowserFamily === 'webkit' ? await webkitMousePanning(panningOptions) : await chromiumAndFirefoxMousePanning(panningOptions);
}

export async function mousePanning(containerCenterX: number, containerCenterY: number): Promise<void> {
async function chromiumAndFirefoxMousePanning({ originPoint, destinationPoint }: PanningOptions): Promise<void> {
// simulate mouse panning
await page.mouse.move(containerCenterX, containerCenterY);
await page.mouse.move(originPoint.x, originPoint.y);
await page.mouse.down();
await page.mouse.move(containerCenterX + 150, containerCenterY + 40);
await page.mouse.move(destinationPoint.x, destinationPoint.y);
await page.mouse.up();
}*/
}

export async function chromiumZoom(xTimes: number, point: Point, deltaX: number): Promise<void> {
for (let i = 0; i < xTimes; i++) {
Expand Down
10 changes: 6 additions & 4 deletions test/e2e/helpers/visu/playwright-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'jest-playwright-preset';
import { ChromiumBrowserContext, ElementHandle } from 'playwright';
import { Point } from '../test-utils';

interface PanningOptions {
export interface PanningOptions {
containerElement: ElementHandle<SVGElement | HTMLElement>;
originPoint: Point;
destinationPoint: Point;
Expand Down Expand Up @@ -49,8 +49,8 @@ export async function chromiumMouseWheel(x: number, y: number, deltaX: number):
await client.detach();
}

// workaround for https://github.com/microsoft/playwright/issues/1094
export async function mousePanning(panningOptions: PanningOptions): Promise<void> {
// TODO To remove when https://github.com/microsoft/playwright/issues/1094 is fixed
export async function webkitMousePanning(panningOptions: PanningOptions): Promise<void> {
await page.evaluate(panningOptions => {
function getMouseEventInit(point: Point): MouseEventInit {
return {
Expand All @@ -72,7 +72,9 @@ export async function mousePanning(panningOptions: PanningOptions): Promise<void
const containerElement: SVGElement | HTMLElement = panningOptions.containerElement;
containerElement.dispatchEvent(new MouseEvent('mousemove', originMouseEventInit));
containerElement.dispatchEvent(new MouseEvent('mousedown', originMouseEventInit));
new Promise(resolve => setTimeout(resolve, 2000));
setTimeout(() => {
// Nothing to do
}, 2000);
containerElement.dispatchEvent(new MouseEvent('mousemove', destinationMouseEventInit));
containerElement.dispatchEvent(new MouseEvent('mouseup', destinationMouseEventInit));

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/overlays.rendering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import { ImageSnapshotConfigurator, ImageSnapshotThresholdConfig, MultiBrowserIm
import { PageTester } from './helpers/visu/PageTester';
import { join } from 'path';
import { OverlayEdgePosition, OverlayPosition, OverlayShapePosition } from '../../src/component/registry';
import { chromiumZoom, clickOnButton, getContainerCenter, itMouseWheel, Point } from './helpers/test-utils';
import { chromiumZoom, clickOnButton, getContainerCenter, itMouseWheel, mousePanning, Point } from './helpers/test-utils';
import { overlayEdgePositionValues, overlayShapePositionValues } from '../helpers/overlays';
import { ensureIsArray } from '../../src/component/helpers/array-utils';
import { ElementHandle } from 'playwright';
import { mousePanning } from './helpers/visu/playwright-utils';

class ImageSnapshotThresholds extends MultiBrowserImageSnapshotThresholds {
constructor() {
Expand Down

0 comments on commit 10aad55

Please sign in to comment.