-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix issue about contextmenu (#5913)
* fix: fix issue about contextmenu * test: update test case
- Loading branch information
Showing
3 changed files
with
58 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,53 @@ | ||
import { pluginContextmenu } from '@/__tests__/demos'; | ||
import { createDemoGraph } from '@@/utils'; | ||
import type { Contextmenu } from '@/src'; | ||
import { NodeEvent } from '@/src'; | ||
import { createDemoGraph, sleep } from '@@/utils'; | ||
|
||
describe('plugin contextmenu', () => { | ||
it('contextmenu', async () => { | ||
const graph = await createDemoGraph(pluginContextmenu); | ||
const onClick = jest.fn(); | ||
graph.updatePlugin({ key: 'contextmenu', onClick }); | ||
|
||
const container = graph.getCanvas().getContainer()!; | ||
|
||
const el = container.querySelector('.g6-contextmenu') as HTMLDivElement; | ||
|
||
expect(graph.getPlugins().length).toBe(1); | ||
// @ts-expect-error ignore | ||
expect(graph.getPlugins()[0].trigger).toBe('contextmenu'); | ||
const $dom = container.querySelector('.g6-contextmenu'); | ||
expect($dom).toBeTruthy(); | ||
expect($dom?.classList.contains('custom-class-name')).toBeTruthy(); | ||
|
||
expect(el.querySelector('.g6-contextmenu-li')).toBeFalsy(); | ||
|
||
await graph.destroy(); | ||
expect(container.querySelector('.g6-contextmenu')).toBeFalsy(); | ||
const emit = () => { | ||
graph.emit(NodeEvent.CONTEXT_MENU, { | ||
target: { id: '1' }, | ||
targetType: 'node', | ||
client: { | ||
x: 100, | ||
y: 100, | ||
}, | ||
}); | ||
}; | ||
|
||
emit(); | ||
|
||
await sleep(100); | ||
expect(el.querySelector('.g6-contextmenu-ul')).toBeTruthy(); | ||
expect(el.querySelectorAll('.g6-contextmenu-li').length).toBe(2); | ||
|
||
const instance = graph.getPluginInstance<Contextmenu>('contextmenu'); | ||
|
||
// @ts-expect-error private method | ||
instance.onMenuItemClick({ target: el.querySelector('.g6-contextmenu-li') }); | ||
expect(onClick).toHaveBeenCalledTimes(1); | ||
expect(container.querySelector<HTMLDivElement>('.g6-contextmenu')!.style.display).toBe('none'); | ||
|
||
emit(); | ||
|
||
await sleep(100); | ||
expect(container.querySelector<HTMLDivElement>('.g6-contextmenu')!.style.display).toBe('block'); | ||
document.body.click(); | ||
expect(container.querySelector<HTMLDivElement>('.g6-contextmenu')!.style.display).toBe('none'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters