diff --git a/packages/g6/package.json b/packages/g6/package.json index 699062c1517..0cc3149590a 100644 --- a/packages/g6/package.json +++ b/packages/g6/package.json @@ -46,7 +46,7 @@ "fix": "eslint ./src ./tests --fix && prettier ./src ./tests --write ", "test": "jest", "test:integration": "node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest tests/integration/ --config jest.node.config.js --coverage -i --logHeapUsage --detectOpenHandles", - "test:integration_one": "node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest tests/integration/items-edge-loop.spec.ts --config jest.node.config.js --coverage -i --logHeapUsage --detectOpenHandles", + "test:integration_one": "node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest tests/integration/plugins-edgeFilterLens.spec.ts --config jest.node.config.js --coverage -i --logHeapUsage --detectOpenHandles", "size": "limit-size", "test-live": "DEBUG_MODE=1 jest --watch ./tests/unit/item-animate-spec.ts", "test-behavior": "DEBUG_MODE=1 jest --watch ./tests/unit/item-3d-spec.ts" diff --git a/packages/g6/tests/demo/plugins/edgeFilterLens.ts b/packages/g6/tests/demo/plugins/edgeFilterLens.ts index fafd7cf4b85..7ddd105232a 100644 --- a/packages/g6/tests/demo/plugins/edgeFilterLens.ts +++ b/packages/g6/tests/demo/plugins/edgeFilterLens.ts @@ -1,6 +1,7 @@ import { Graph, Extensions, extend } from '../../../src/index'; +import { TestCaseContext } from '../interface'; -export default async () => { +export default async (context: TestCaseContext) => { let trigger = 'mousemove'; let filterLens = { type: 'filterLens', @@ -100,6 +101,7 @@ export default async () => { }, }); const graph = new ExtGraph({ + ...context, container: 'container', width, height: height, @@ -188,7 +190,7 @@ export default async () => { graph.updatePlugin(filterLens); }); - fetch('https://gw.alipayobjects.com/os/bmw-prod/afe8b2a6-f691-4070-aa73-46fc07fd1171.json') + await fetch('https://gw.alipayobjects.com/os/bmw-prod/afe8b2a6-f691-4070-aa73-46fc07fd1171.json') .then((res) => res.json()) .then((data) => { data.edges.forEach((edge) => { @@ -201,4 +203,6 @@ export default async () => { graph.read(data); graph.zoom(0.6); }); + + return graph; } diff --git a/packages/g6/tests/integration/plugins-edgeFilterLens.spec.ts b/packages/g6/tests/integration/plugins-edgeFilterLens.spec.ts new file mode 100644 index 00000000000..56910ede606 --- /dev/null +++ b/packages/g6/tests/integration/plugins-edgeFilterLens.spec.ts @@ -0,0 +1,38 @@ +import { resetEntityCounter } from '@antv/g'; +import EdgeFilterLens from '../demo/plugins/edgeFilterLens'; +import { createContext, sleep } from './utils'; +import { triggerEvent } from './utils/event'; +import './utils/useSnapshotMatchers'; + +describe('Default EdgeFilterLens', () => { + beforeEach(() => { + resetEntityCounter(); + }); + + it('should be rendered correctly with Canvas2D', async () => { + const dir = `${__dirname}/snapshots/canvas/plugins/edgeFilterLens`; + const { backgroundCanvas, canvas, transientCanvas, container } = + createContext('canvas', 500, 500); + const graph = await EdgeFilterLens({ + backgroundCanvas, + canvas, + transientCanvas, + width: 500, + height: 500, + container, + }); + + const process = new Promise((reslove) => { + graph.on('afterlayout', reslove); + }) + + await process; + await sleep(300); + triggerEvent(graph, 'mousedown', 100, 100); + await expect(canvas).toMatchCanvasSnapshot( + dir, + 'plugins-edge-filter-lens', + ); + graph.destroy(); + }); +}); diff --git a/packages/g6/tests/integration/snapshots/canvas/plugins/edgeFilterLens/plugins-edge-filter-lens.png b/packages/g6/tests/integration/snapshots/canvas/plugins/edgeFilterLens/plugins-edge-filter-lens.png new file mode 100644 index 00000000000..02b95c85ef7 Binary files /dev/null and b/packages/g6/tests/integration/snapshots/canvas/plugins/edgeFilterLens/plugins-edge-filter-lens.png differ