-
Notifications
You must be signed in to change notification settings - Fork 512
fix: "convert to subgraph" not shown in context menu if subgraph inside the selection context #7470
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
Merged
Merged
Changes from all commits
Commits
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
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,106 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { useSelectionMenuOptions } from '@/composables/graph/useSelectionMenuOptions' | ||
|
|
||
| const subgraphMocks = vi.hoisted(() => ({ | ||
| convertToSubgraph: vi.fn(), | ||
| unpackSubgraph: vi.fn(), | ||
| addSubgraphToLibrary: vi.fn(), | ||
| createI18nMock: vi.fn(() => ({ | ||
| global: { | ||
| t: vi.fn(), | ||
| te: vi.fn(), | ||
| d: vi.fn() | ||
| } | ||
| })) | ||
| })) | ||
|
|
||
| vi.mock('vue-i18n', () => ({ | ||
| useI18n: () => ({ | ||
| t: (key: string) => key | ||
| }), | ||
| createI18n: subgraphMocks.createI18nMock | ||
| })) | ||
|
|
||
| vi.mock('@/composables/graph/useSelectionOperations', () => ({ | ||
| useSelectionOperations: () => ({ | ||
| copySelection: vi.fn(), | ||
| duplicateSelection: vi.fn(), | ||
| deleteSelection: vi.fn(), | ||
| renameSelection: vi.fn() | ||
| }) | ||
| })) | ||
|
|
||
| vi.mock('@/composables/graph/useNodeArrangement', () => ({ | ||
| useNodeArrangement: () => ({ | ||
| alignOptions: [{ localizedName: 'align-left', icon: 'align-left' }], | ||
| distributeOptions: [{ localizedName: 'distribute', icon: 'distribute' }], | ||
| applyAlign: vi.fn(), | ||
| applyDistribute: vi.fn() | ||
| }) | ||
| })) | ||
|
|
||
| vi.mock('@/composables/graph/useSubgraphOperations', () => ({ | ||
| useSubgraphOperations: () => ({ | ||
| convertToSubgraph: subgraphMocks.convertToSubgraph, | ||
| unpackSubgraph: subgraphMocks.unpackSubgraph, | ||
| addSubgraphToLibrary: subgraphMocks.addSubgraphToLibrary | ||
| }) | ||
| })) | ||
|
|
||
| vi.mock('@/composables/graph/useFrameNodes', () => ({ | ||
| useFrameNodes: () => ({ | ||
| frameNodes: vi.fn() | ||
| }) | ||
| })) | ||
|
|
||
| describe('useSelectionMenuOptions - subgraph options', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| it('returns only convert option when no subgraphs are selected', () => { | ||
| const { getSubgraphOptions } = useSelectionMenuOptions() | ||
| const options = getSubgraphOptions({ | ||
| hasSubgraphs: false, | ||
| hasMultipleSelection: true | ||
| }) | ||
|
|
||
| expect(options).toHaveLength(1) | ||
| expect(options[0]?.label).toBe('contextMenu.Convert to Subgraph') | ||
| expect(options[0]?.action).toBe(subgraphMocks.convertToSubgraph) | ||
| }) | ||
|
|
||
| it('includes convert, add to library, and unpack when subgraphs are selected', () => { | ||
| const { getSubgraphOptions } = useSelectionMenuOptions() | ||
| const options = getSubgraphOptions({ | ||
| hasSubgraphs: true, | ||
| hasMultipleSelection: true | ||
| }) | ||
| const labels = options.map((option) => option.label) | ||
|
|
||
| expect(labels).toContain('contextMenu.Convert to Subgraph') | ||
| expect(labels).toContain('contextMenu.Add Subgraph to Library') | ||
| expect(labels).toContain('contextMenu.Unpack Subgraph') | ||
|
|
||
| const convertOption = options.find( | ||
| (option) => option.label === 'contextMenu.Convert to Subgraph' | ||
| ) | ||
| expect(convertOption?.action).toBe(subgraphMocks.convertToSubgraph) | ||
| }) | ||
|
|
||
| it('hides convert option when only a single subgraph is selected', () => { | ||
| const { getSubgraphOptions } = useSelectionMenuOptions() | ||
| const options = getSubgraphOptions({ | ||
| hasSubgraphs: true, | ||
| hasMultipleSelection: false | ||
| }) | ||
|
|
||
| const labels = options.map((option) => option.label) | ||
| expect(labels).not.toContain('contextMenu.Convert to Subgraph') | ||
| expect(labels).toEqual([ | ||
| 'contextMenu.Add Subgraph to Library', | ||
| 'contextMenu.Unpack Subgraph' | ||
| ]) | ||
| }) | ||
| }) | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test description is misleading; consider covering single-selection/no-subgraph case.
The test says “no subgraphs are selected” but sets
hasMultipleSelection: true(it’s really “no subgraphs + multiple selection”). If UX differs forhasMultipleSelection: false, consider adding an explicit case to lock intended behavior.🤖 Prompt for AI Agents