-
-
Notifications
You must be signed in to change notification settings - Fork 9k
fix: render state diagram click tooltips #7751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
puneetdixit200
wants to merge
7
commits into
mermaid-js:develop
Choose a base branch
from
puneetdixit200:bug/6701_state-diagram-tooltips
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
65a0cd3
fix: render state diagram click tooltips
0f34e6c
Potential fix for pull request finding
puneetdixit200 d1f05e6
fix: bind state tooltips for hand drawn nodes
3f1b388
fix: cover state click tooltip rendering
8972be8
Merge branch 'mermaid-js:develop' into bug/6701_state-diagram-tooltips
puneetdixit200 0f742b1
Add state tooltip integration coverage
puneetdixit200 0ea9ba6
Harden state tooltip selector
puneetdixit200 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'mermaid': patch | ||
| --- | ||
|
|
||
| fix: render state diagram click tooltips with mermaidTooltip |
This file contains hidden or 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 hidden or 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
86 changes: 86 additions & 0 deletions
86
packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.spec.js
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { vi, describe, it, expect, beforeEach } from 'vitest'; | ||
|
|
||
| const renderState = vi.hoisted(() => ({ | ||
| nodeClass: 'node', | ||
| })); | ||
|
|
||
| vi.mock('../../diagram-api/diagramAPI.js', () => ({ | ||
| getConfig: vi.fn(() => ({ | ||
| securityLevel: 'loose', | ||
| state: { | ||
| titleTopMargin: 25, | ||
| useMaxWidth: true, | ||
| nodeSpacing: 50, | ||
| rankSpacing: 50, | ||
| }, | ||
| layout: 'dagre', | ||
| look: 'classic', | ||
| })), | ||
| })); | ||
|
|
||
| vi.mock('../../rendering-util/render.js', () => ({ | ||
| render: vi.fn((data, svg) => { | ||
| const layoutNode = data.nodes.find((node) => node.id === 'A') ?? data.nodes[0]; | ||
| const node = document.createElementNS('http://www.w3.org/2000/svg', 'g'); | ||
| node.setAttribute('class', renderState.nodeClass); | ||
| node.setAttribute('id', layoutNode?.domId ?? 'state-A-0'); | ||
|
|
||
| const label = document.createElementNS('http://www.w3.org/2000/svg', 'text'); | ||
| label.textContent = Array.isArray(layoutNode?.label) | ||
| ? layoutNode.label[0] | ||
| : (layoutNode?.label ?? 'Google'); | ||
| node.appendChild(label); | ||
|
|
||
| svg.node().appendChild(node); | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock('../../rendering-util/setupViewPortForSVG.js', () => ({ | ||
| setupViewPortForSVG: vi.fn(), | ||
| })); | ||
|
|
||
| import { StateDB } from './stateDb.js'; | ||
| import { draw } from './stateRenderer-v3-unified.js'; | ||
|
|
||
| const DIAGRAM_ID = 'state-click-tooltip'; | ||
|
|
||
| describe('stateRenderer v3 clickable links', () => { | ||
| beforeEach(() => { | ||
| document.body.innerHTML = `<svg id="${DIAGRAM_ID}"></svg>`; | ||
| }); | ||
|
|
||
| it.each(['node', 'rough-node'])( | ||
| 'uses mermaidTooltip for state click tooltips on %s elements', | ||
| async (nodeClass) => { | ||
| renderState.nodeClass = nodeClass; | ||
|
|
||
| const stateDb = new StateDB(1); | ||
| stateDb.setRootDoc([{ stmt: 'state', id: 'A', description: 'Google' }]); | ||
| stateDb.addLink('A', '"https://google.com"', '"Visit Google"'); | ||
|
|
||
| await draw('', DIAGRAM_ID, '1.0.0', { | ||
| type: 'stateDiagram', | ||
| db: stateDb, | ||
| }); | ||
|
|
||
| const node = document.querySelector(`svg#${DIAGRAM_ID} a > g.${nodeClass}`); | ||
|
|
||
| expect(node).not.toBeNull(); | ||
| expect(node.getAttribute('title')).toBe('Visit Google'); | ||
|
|
||
| stateDb.bindFunctions(document.body); | ||
|
|
||
| const tooltip = document.querySelector('.mermaidTooltip'); | ||
| expect(tooltip).not.toBeNull(); | ||
|
|
||
| node.dispatchEvent(new window.MouseEvent('mouseover', { bubbles: true })); | ||
|
|
||
| expect(tooltip.innerHTML).toBe('Visit Google'); | ||
| expect(node.classList.contains('hover')).toBe(true); | ||
|
|
||
| node.dispatchEvent(new window.MouseEvent('mouseout', { bubbles: true })); | ||
|
|
||
| expect(node.classList.contains('hover')).toBe(false); | ||
| } | ||
| ); | ||
| }); | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.