-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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): Use display option's @Version specifier #7351
Merged
tomi
merged 2 commits into
master
from
ado-884-not-every-operations-show-up-in-the-sidebar-node-search
Oct 5, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
390 changes: 390 additions & 0 deletions
390
packages/editor-ui/src/components/Node/NodeCreator/__tests__/useActionsGeneration.test.ts
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 |
---|---|---|
@@ -0,0 +1,390 @@ | ||
import type { INodeProperties, INodeTypeDescription } from 'n8n-workflow'; | ||
import { useActionsGenerator } from '../composables/useActionsGeneration'; | ||
|
||
describe('useActionsGenerator', () => { | ||
const { generateMergedNodesAndActions } = useActionsGenerator(); | ||
const NODE_NAME = 'n8n-nodes-base.test'; | ||
const baseV2NodeWoProps: INodeTypeDescription = { | ||
name: NODE_NAME, | ||
displayName: 'Test', | ||
description: 'Test Node', | ||
defaultVersion: 2, | ||
version: 2, | ||
group: ['output'], | ||
defaults: { | ||
name: 'Test', | ||
}, | ||
inputs: ['main'], | ||
outputs: ['main'], | ||
properties: [], | ||
}; | ||
|
||
describe('App actions for resource category', () => { | ||
const resourcePropertyWithUser: INodeProperties = { | ||
displayName: 'Resource', | ||
name: 'resource', | ||
type: 'options', | ||
noDataExpression: true, | ||
options: [ | ||
{ | ||
name: 'User', | ||
value: 'user', | ||
}, | ||
], | ||
default: 'user', | ||
}; | ||
const resourcePropertyWithUserAndPage: INodeProperties = { | ||
displayName: 'Resource', | ||
name: 'resource', | ||
type: 'options', | ||
noDataExpression: true, | ||
options: [ | ||
{ | ||
name: 'User', | ||
value: 'user', | ||
}, | ||
{ | ||
name: 'Page', | ||
value: 'page', | ||
}, | ||
], | ||
default: 'user', | ||
}; | ||
|
||
it('returns single action for single resource & single operation without resource filter', () => { | ||
const node: INodeTypeDescription = { | ||
...baseV2NodeWoProps, | ||
properties: [ | ||
resourcePropertyWithUser, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
displayOptions: {}, | ||
options: [ | ||
{ | ||
name: 'Get', | ||
value: 'get', | ||
description: 'Get description', | ||
}, | ||
], | ||
default: 'get', | ||
}, | ||
], | ||
}; | ||
|
||
const { actions } = generateMergedNodesAndActions([node]); | ||
expect(actions).toEqual({ | ||
[NODE_NAME]: [ | ||
expect.objectContaining({ | ||
actionKey: 'get', | ||
description: 'Get description', | ||
displayName: 'User Get', | ||
codex: { | ||
label: 'User Actions', | ||
categories: ['Actions'], | ||
}, | ||
}), | ||
], | ||
}); | ||
}); | ||
|
||
it('returns single action for single resource & single operation with matching resource filter', () => { | ||
const node: INodeTypeDescription = { | ||
...baseV2NodeWoProps, | ||
properties: [ | ||
resourcePropertyWithUser, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
displayOptions: { | ||
show: { | ||
resource: ['user'], | ||
}, | ||
}, | ||
options: [ | ||
{ | ||
name: 'Get', | ||
value: 'get', | ||
description: 'Get description', | ||
}, | ||
], | ||
default: 'get', | ||
}, | ||
], | ||
}; | ||
|
||
const { actions } = generateMergedNodesAndActions([node]); | ||
expect(actions).toEqual({ | ||
[NODE_NAME]: [ | ||
expect.objectContaining({ | ||
actionKey: 'get', | ||
description: 'Get description', | ||
displayName: 'User Get', | ||
codex: { | ||
label: 'User Actions', | ||
categories: ['Actions'], | ||
}, | ||
}), | ||
], | ||
}); | ||
}); | ||
|
||
it('returns nothing for multiple resources & single operation without resource filter', () => { | ||
const node: INodeTypeDescription = { | ||
...baseV2NodeWoProps, | ||
properties: [ | ||
resourcePropertyWithUserAndPage, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
displayOptions: {}, | ||
options: [ | ||
{ | ||
name: 'Get', | ||
value: 'get', | ||
description: 'Get description', | ||
}, | ||
], | ||
default: 'get', | ||
}, | ||
], | ||
}; | ||
|
||
const { actions } = generateMergedNodesAndActions([node]); | ||
expect(actions).toEqual({ | ||
[NODE_NAME]: [], | ||
}); | ||
}); | ||
|
||
it('returns single action for multiple resources & single operation with resource filter', () => { | ||
const node: INodeTypeDescription = { | ||
...baseV2NodeWoProps, | ||
properties: [ | ||
resourcePropertyWithUserAndPage, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
displayOptions: { | ||
show: { | ||
resource: ['user'], | ||
}, | ||
}, | ||
options: [ | ||
{ | ||
name: 'Get', | ||
value: 'get', | ||
description: 'Get description', | ||
}, | ||
], | ||
default: 'get', | ||
}, | ||
], | ||
}; | ||
|
||
const { actions } = generateMergedNodesAndActions([node]); | ||
expect(actions).toEqual({ | ||
[NODE_NAME]: [ | ||
expect.objectContaining({ | ||
actionKey: 'get', | ||
description: 'Get description', | ||
displayName: 'User Get', | ||
codex: { | ||
label: 'User Actions', | ||
categories: ['Actions'], | ||
}, | ||
}), | ||
], | ||
}); | ||
}); | ||
|
||
it('returns multiple actions for multiple resources & multiple operations with resource filters', () => { | ||
const node: INodeTypeDescription = { | ||
...baseV2NodeWoProps, | ||
properties: [ | ||
resourcePropertyWithUserAndPage, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
displayOptions: { | ||
show: { | ||
resource: ['user'], | ||
}, | ||
}, | ||
options: [ | ||
{ | ||
name: 'Get', | ||
value: 'get', | ||
description: 'Get description', | ||
}, | ||
], | ||
default: 'get', | ||
}, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
displayOptions: { | ||
show: { | ||
resource: ['page'], | ||
}, | ||
}, | ||
options: [ | ||
{ | ||
name: 'Get', | ||
value: 'get', | ||
description: 'Get description', | ||
}, | ||
], | ||
default: 'get', | ||
}, | ||
], | ||
}; | ||
|
||
const { actions } = generateMergedNodesAndActions([node]); | ||
expect(actions).toEqual({ | ||
[NODE_NAME]: [ | ||
expect.objectContaining({ | ||
actionKey: 'get', | ||
description: 'Get description', | ||
displayName: 'User Get', | ||
codex: { | ||
label: 'User Actions', | ||
categories: ['Actions'], | ||
}, | ||
}), | ||
expect.objectContaining({ | ||
actionKey: 'get', | ||
description: 'Get description', | ||
displayName: 'Page Get', | ||
codex: { | ||
label: 'Page Actions', | ||
categories: ['Actions'], | ||
}, | ||
}), | ||
], | ||
}); | ||
}); | ||
|
||
it('returns correct action for single resource & multiple operations with different versions', () => { | ||
const node: INodeTypeDescription = { | ||
...baseV2NodeWoProps, | ||
properties: [ | ||
resourcePropertyWithUser, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
displayOptions: { | ||
show: { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
'@version': [1], | ||
resource: ['user'], | ||
}, | ||
}, | ||
options: [ | ||
{ | ||
name: 'Get Version 1', | ||
value: 'getv1', | ||
description: 'Get version 1', | ||
}, | ||
], | ||
default: 'getv1', | ||
}, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
displayOptions: { | ||
show: { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
'@version': [2], | ||
resource: ['user'], | ||
}, | ||
}, | ||
options: [ | ||
{ | ||
name: 'Get Version 2', | ||
value: 'getv2', | ||
description: 'Get version 2', | ||
}, | ||
], | ||
default: 'getv2', | ||
}, | ||
], | ||
}; | ||
|
||
const { actions } = generateMergedNodesAndActions([node]); | ||
expect(actions).toEqual({ | ||
[NODE_NAME]: [ | ||
expect.objectContaining({ | ||
actionKey: 'getv2', | ||
description: 'Get version 2', | ||
displayName: 'User Get Version 2', | ||
codex: { | ||
label: 'User Actions', | ||
categories: ['Actions'], | ||
}, | ||
}), | ||
], | ||
}); | ||
}); | ||
|
||
it('returns correct action for single resource & single operation with multiple versions', () => { | ||
const node: INodeTypeDescription = { | ||
...baseV2NodeWoProps, | ||
properties: [ | ||
resourcePropertyWithUser, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
displayOptions: { | ||
show: { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
'@version': [1, 2], | ||
resource: ['user'], | ||
}, | ||
}, | ||
options: [ | ||
{ | ||
name: 'Get Version 2', | ||
value: 'getv2', | ||
description: 'Get version 2', | ||
}, | ||
], | ||
default: 'getv2', | ||
}, | ||
], | ||
}; | ||
|
||
const { actions } = generateMergedNodesAndActions([node]); | ||
expect(actions).toEqual({ | ||
[NODE_NAME]: [ | ||
expect.objectContaining({ | ||
actionKey: 'getv2', | ||
description: 'Get version 2', | ||
displayName: 'User Get Version 2', | ||
codex: { | ||
label: 'User Actions', | ||
categories: ['Actions'], | ||
}, | ||
}), | ||
], | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
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.
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.
LOVE IT 👏