-
Notifications
You must be signed in to change notification settings - Fork 442
Sync node help with selection and add watcher tests #7105
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
base: main
Are you sure you want to change the base?
Changes from all commits
a436c94
4c3718f
82e13d4
00aaa14
19e1ede
22cdd36
5ff1e8b
65d07a0
d859246
b9f22c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| class="flex items-center border-b border-(--p-divider-color) px-3 py-2" | ||
| > | ||
| <Button | ||
| v-tooltip.bottom="$t('g.back')" | ||
|
Check failure on line 7 in src/components/sidebar/tabs/nodeLibrary/NodeHelpPage.vue
|
||
| icon="pi pi-arrow-left" | ||
| text | ||
| severity="secondary" | ||
|
|
@@ -19,14 +19,31 @@ | |
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { whenever } from '@vueuse/core' | ||
| import Button from 'primevue/button' | ||
|
|
||
| import NodeHelpContent from '@/components/node/NodeHelpContent.vue' | ||
| import { useSelectionState } from '@/composables/graph/useSelectionState' | ||
| import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore' | ||
| import { useNodeHelpStore } from '@/stores/workspace/nodeHelpStore' | ||
|
|
||
| const { node } = defineProps<{ node: ComfyNodeDefImpl }>() | ||
|
|
||
| defineEmits<{ | ||
| (e: 'close'): void | ||
| }>() | ||
|
|
||
| const nodeHelpStore = useNodeHelpStore() | ||
| const { nodeDef } = useSelectionState() | ||
|
|
||
| // Keep the open help page synced with the current selection while help is open. | ||
| whenever( | ||
| () => (nodeHelpStore.isHelpOpen ? nodeDef.value : null), | ||
| (def) => { | ||
| if (!def) return | ||
| const currentHelpNode = nodeHelpStore.currentHelpNode | ||
| if (currentHelpNode?.nodePath === def.nodePath) return | ||
| nodeHelpStore.openHelp(def) | ||
| } | ||
| ) | ||
| </script> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { flushPromises, mount } from '@vue/test-utils' | ||
| import { computed, ref } from 'vue' | ||
| import { beforeEach, describe, expect, test, vi } from 'vitest' | ||
|
|
||
| import NodeHelpPage from '@/components/sidebar/tabs/nodeLibrary/NodeHelpPage.vue' | ||
| import { useSelectionState } from '@/composables/graph/useSelectionState' | ||
| import { useNodeHelpStore } from '@/stores/workspace/nodeHelpStore' | ||
|
|
||
| vi.mock('@/composables/graph/useSelectionState') | ||
| vi.mock('@/stores/workspace/nodeHelpStore') | ||
|
|
||
| const baseNode = { | ||
| nodePath: 'NodeA', | ||
| display_name: 'Node A', | ||
| description: '', | ||
| inputs: {}, | ||
| outputs: [] | ||
| } | ||
|
|
||
| describe('NodeHelpPage', () => { | ||
| const selection = ref<any | null>(null) | ||
| let openHelp: ReturnType<typeof vi.fn> | ||
|
|
||
| const mountPage = () => | ||
| mount(NodeHelpPage, { | ||
| props: { node: baseNode as any }, | ||
| global: { | ||
| stubs: { | ||
| ProgressSpinner: true, | ||
| Button: true | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| beforeEach(() => { | ||
| vi.resetAllMocks() | ||
| selection.value = null | ||
| openHelp = vi.fn() | ||
|
|
||
| vi.mocked(useSelectionState).mockReturnValue({ | ||
| nodeDef: computed(() => selection.value) | ||
| } as any) | ||
|
|
||
| vi.mocked(useNodeHelpStore).mockReturnValue({ | ||
| renderedHelpHtml: ref('<p>help</p>'), | ||
| isLoading: ref(false), | ||
| error: ref(null), | ||
| isHelpOpen: true, | ||
| currentHelpNode: { nodePath: 'NodeA' }, | ||
| openHelp, | ||
| closeHelp: vi.fn() | ||
| } as any) | ||
| }) | ||
|
|
||
| test('opens help for a newly selected node while help is open', async () => { | ||
| const wrapper = mountPage() | ||
|
|
||
| selection.value = { nodePath: 'NodeB' } | ||
| await flushPromises() | ||
|
|
||
| expect(openHelp).toHaveBeenCalledWith({ nodePath: 'NodeB' }) | ||
|
|
||
| wrapper.unmount() | ||
| }) | ||
|
|
||
| test('does not reopen help when the same node stays selected', async () => { | ||
| const wrapper = mountPage() | ||
|
|
||
| selection.value = { nodePath: 'NodeA' } | ||
| await flushPromises() | ||
|
|
||
| expect(openHelp).not.toHaveBeenCalled() | ||
|
|
||
| wrapper.unmount() | ||
| }) | ||
|
|
||
| test('does not react to selection when help is closed', async () => { | ||
| vi.mocked(useNodeHelpStore).mockReturnValueOnce({ | ||
| renderedHelpHtml: ref('<p>help</p>'), | ||
| isLoading: ref(false), | ||
| error: ref(null), | ||
| isHelpOpen: false, | ||
| currentHelpNode: null, | ||
| openHelp, | ||
| closeHelp: vi.fn() | ||
| } as any) | ||
|
|
||
| const wrapper = mountPage() | ||
|
|
||
| selection.value = { nodePath: 'NodeB' } | ||
| await flushPromises() | ||
|
|
||
| expect(openHelp).not.toHaveBeenCalled() | ||
|
|
||
| wrapper.unmount() | ||
| }) | ||
| }) | ||
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.
🛠️ Refactor suggestion | 🟠 Major
Avoid
any/as anyin test typingsThis test uses
ref<any | null>and severalas anyassertions for props and mocked composables. Given the repo guidelines for TypeScript, it would be better to give these values concrete structural types.For example:
selectionasref<{ nodePath: string } | null>instead ofany.useSelectionStatereturn asPick<ReturnType<typeof useSelectionState>, 'nodeDef'>(or a small local interface) instead ofas any.useNodeHelpStoremock asPartial<ReturnType<typeof useNodeHelpStore>>and satisfy only the fields this test needs.This keeps tests aligned with the real APIs and avoids
anywhile remaining lightweight.Also applies to: 58-61, 66-87
🤖 Prompt for AI Agents