-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
fix(editor): Enable pinning main output with error and always allow unpinning #11452
Changes from 3 commits
306d13d
dd354ff
abee2f7
aae7ccc
1cb39c7
4f95885
a63af7f
ec5b581
f03b325
4db633a
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 |
---|---|---|
|
@@ -3,9 +3,10 @@ import { setActivePinia, createPinia } from 'pinia'; | |
import { ref } from 'vue'; | ||
import { usePinnedData } from '@/composables/usePinnedData'; | ||
import type { INodeUi } from '@/Interface'; | ||
import { MAX_PINNED_DATA_SIZE } from '@/constants'; | ||
import { HTTP_REQUEST_NODE_TYPE, IF_NODE_TYPE, MAX_PINNED_DATA_SIZE } from '@/constants'; | ||
import { useWorkflowsStore } from '@/stores/workflows.store'; | ||
import { useTelemetry } from '@/composables/useTelemetry'; | ||
import { NodeConnectionType, type INodeTypeDescription } from 'n8n-workflow'; | ||
|
||
vi.mock('@/composables/useToast', () => ({ useToast: vi.fn(() => ({ showError: vi.fn() })) })); | ||
vi.mock('@/composables/useI18n', () => ({ | ||
|
@@ -17,6 +18,13 @@ vi.mock('@/composables/useExternalHooks', () => ({ | |
})), | ||
})); | ||
|
||
const getNodeType = vi.fn(); | ||
vi.mock('@/stores/nodeTypes.store', () => ({ | ||
useNodeTypesStore: vi.fn(() => ({ | ||
getNodeType, | ||
})), | ||
})); | ||
|
||
describe('usePinnedData', () => { | ||
beforeEach(() => { | ||
setActivePinia(createPinia()); | ||
|
@@ -133,4 +141,71 @@ describe('usePinnedData', () => { | |
expect(spy).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('canPinData()', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for adding Unit tests. Would it also be useful to add some e2e tests as well for this bug? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Especially if we now drop the condition in the vue file or move it to the composable this unit test should now have us fully covered. I'm a bit unclear still on when to add e2e tests, I understand we're looking to move away from them "by default" and that there is a real cost associated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's no rule. My general rule is if the bug depends on the interaction of multiple modules, then better to have an e2e test for it. |
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('allows pin on single output', async () => { | ||
const node = ref({ | ||
name: 'single output node', | ||
typeVersion: 1, | ||
type: HTTP_REQUEST_NODE_TYPE, | ||
|
||
parameters: {}, | ||
onError: 'stopWorkflow', | ||
} as INodeUi); | ||
getNodeType.mockReturnValue(makeNodeType([NodeConnectionType.Main], HTTP_REQUEST_NODE_TYPE)); | ||
|
||
const { canPinNode } = usePinnedData(node); | ||
|
||
expect(canPinNode()).toBe(true); | ||
}); | ||
|
||
it('allows pin on one main and one error output', async () => { | ||
const node = ref({ | ||
name: 'single output node', | ||
typeVersion: 1, | ||
type: HTTP_REQUEST_NODE_TYPE, | ||
parameters: {}, | ||
onError: 'continueErrorOutput', | ||
} as INodeUi); | ||
getNodeType.mockReturnValue(makeNodeType([NodeConnectionType.Main], HTTP_REQUEST_NODE_TYPE)); | ||
|
||
const { canPinNode } = usePinnedData(node); | ||
|
||
expect(canPinNode()).toBe(true); | ||
}); | ||
|
||
it('does not allow pin on two main outputs', async () => { | ||
const node = ref({ | ||
name: 'single output node', | ||
typeVersion: 1, | ||
type: IF_NODE_TYPE, | ||
parameters: {}, | ||
onError: 'stopWorkflow', | ||
} as INodeUi); | ||
getNodeType.mockReturnValue( | ||
makeNodeType([NodeConnectionType.Main, NodeConnectionType.Main], IF_NODE_TYPE), | ||
); | ||
|
||
const { canPinNode } = usePinnedData(node); | ||
|
||
expect(canPinNode()).toBe(false); | ||
}); | ||
}); | ||
}); | ||
|
||
const makeNodeType = (outputs: NodeConnectionType[], name: string) => | ||
({ | ||
displayName: name, | ||
name, | ||
version: [1], | ||
inputs: [], | ||
outputs, | ||
properties: [], | ||
defaults: { color: '', name: '' }, | ||
group: [], | ||
description: '', | ||
}) as INodeTypeDescription; |
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.
Would it be more safe here to check the type instead of the output index? Because, for example, if the UX changes and suddenly error output is on top, this would be wrong.
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.
Indeed this assumption is a bit wacky. It's rooted in the explicit effort elsewhere in the code to add the error path after node specific outputs, but it might not hold long-term.
So it turns out we actually don't need this check here, as this line
n8n/packages/editor-ui/src/components/RunData.vue
Line 263 in 73b0a80
!this.rawInputData.length
, which causes us to return early for errors.I don't fully understand this, does this happen to align, or can we rely on this semantically?
I can still add the check, though I'd move it to
canPinNode
by adding an index parameter if that works for you.