-
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: Account for nanoid workflow ids for subworkflow execute policy #7094
Merged
krynble
merged 4 commits into
master
from
pay-763-selected-workflows-setting-with-new-id-format
Sep 13, 2023
Merged
Changes from all commits
Commits
Show all changes
4 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
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
152 changes: 152 additions & 0 deletions
152
packages/editor-ui/src/components/__tests__/WorkflowSettings.spec.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,152 @@ | ||
import { createPinia, setActivePinia } from 'pinia'; | ||
import WorkflowSettingsVue from '../WorkflowSettings.vue'; | ||
|
||
import { setupServer } from '@/__tests__/server'; | ||
import { afterAll, beforeAll } from 'vitest'; | ||
import { within, fireEvent } from '@testing-library/vue'; | ||
|
||
import { useWorkflowsStore } from '@/stores/workflows.store'; | ||
import { useSettingsStore } from '@/stores/settings.store'; | ||
import { useUIStore } from '@/stores/ui.store'; | ||
|
||
import { createComponentRenderer } from '@/__tests__/render'; | ||
import { EnterpriseEditionFeature, WORKFLOW_SETTINGS_MODAL_KEY } from '@/constants'; | ||
|
||
import { nextTick } from 'vue'; | ||
|
||
let pinia: ReturnType<typeof createPinia>; | ||
let workflowsStore: ReturnType<typeof useWorkflowsStore>; | ||
let settingsStore: ReturnType<typeof useSettingsStore>; | ||
let uiStore: ReturnType<typeof useUIStore>; | ||
|
||
const createComponent = createComponentRenderer(WorkflowSettingsVue, { | ||
global: { | ||
stubs: ['n8n-tooltip'], | ||
}, | ||
}); | ||
|
||
describe('WorkflowSettingsVue', () => { | ||
let server: ReturnType<typeof setupServer>; | ||
beforeAll(() => { | ||
server = setupServer(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
pinia = createPinia(); | ||
setActivePinia(pinia); | ||
|
||
workflowsStore = useWorkflowsStore(); | ||
settingsStore = useSettingsStore(); | ||
uiStore = useUIStore(); | ||
|
||
await settingsStore.getSettings(); | ||
|
||
vi.spyOn(workflowsStore, 'workflowName', 'get').mockReturnValue('Test Workflow'); | ||
vi.spyOn(workflowsStore, 'workflowId', 'get').mockReturnValue('1'); | ||
vi.spyOn(workflowsStore, 'workflow', 'get').mockReturnValue({ | ||
id: '1', | ||
name: 'Test Workflow', | ||
active: true, | ||
nodes: [], | ||
connections: {}, | ||
createdAt: 1, | ||
updatedAt: 1, | ||
versionId: '123', | ||
} as IWorkflowDb); | ||
|
||
uiStore.modals[WORKFLOW_SETTINGS_MODAL_KEY] = { | ||
open: true, | ||
}; | ||
}); | ||
|
||
afterAll(() => { | ||
server.shutdown(); | ||
}); | ||
|
||
it('should render correctly', async () => { | ||
settingsStore.settings.enterprise[EnterpriseEditionFeature.Sharing] = false; | ||
const wrapper = createComponent({ pinia }); | ||
await nextTick(); | ||
expect(wrapper.getByTestId('workflow-settings-dialog')).toBeVisible(); | ||
}); | ||
|
||
it('should not render workflow caller policy when sharing is not enabled', async () => { | ||
settingsStore.settings.enterprise[EnterpriseEditionFeature.Sharing] = false; | ||
const wrapper = createComponent({ pinia }); | ||
|
||
await nextTick(); | ||
|
||
expect( | ||
within(wrapper.getByTestId('workflow-settings-dialog')).queryByTestId( | ||
'workflow-caller-policy', | ||
), | ||
).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should render workflow caller policy when sharing is enabled', async () => { | ||
settingsStore.settings.enterprise[EnterpriseEditionFeature.Sharing] = true; | ||
const wrapper = createComponent({ pinia }); | ||
|
||
await nextTick(); | ||
|
||
expect(wrapper.getByTestId('workflow-caller-policy')).toBeVisible(); | ||
}); | ||
|
||
it('should render list of workflows field when policy is set to workflowsFromAList', async () => { | ||
settingsStore.settings.enterprise[EnterpriseEditionFeature.Sharing] = true; | ||
const wrapper = createComponent({ pinia }); | ||
|
||
await nextTick(); | ||
|
||
await fireEvent.click(wrapper.getByTestId('workflow-caller-policy')); | ||
console.log(window.document.querySelectorAll('.el-select-dropdown__item')[4].innerHTML); | ||
await fireEvent.click(window.document.querySelectorAll('.el-select-dropdown__item')[4]); | ||
|
||
expect(wrapper.getByTestId('workflow-caller-policy-workflow-ids')).toBeVisible(); | ||
}); | ||
|
||
it('should not remove valid workflow ID characters', async () => { | ||
const validWorkflowList = '1234567890, abcde, efgh, 1234'; | ||
|
||
settingsStore.settings.enterprise[EnterpriseEditionFeature.Sharing] = true; | ||
const wrapper = createComponent({ pinia }); | ||
|
||
await nextTick(); | ||
|
||
await fireEvent.click(wrapper.getByTestId('workflow-caller-policy')); | ||
console.log(window.document.querySelectorAll('.el-select-dropdown__item')[4].innerHTML); | ||
await fireEvent.click(window.document.querySelectorAll('.el-select-dropdown__item')[4]); | ||
|
||
await fireEvent.update( | ||
wrapper.getByTestId('workflow-caller-policy-workflow-ids'), | ||
validWorkflowList, | ||
); | ||
|
||
expect(wrapper.getByTestId('workflow-caller-policy-workflow-ids')).toHaveValue( | ||
validWorkflowList, | ||
); | ||
}); | ||
|
||
it('should remove invalid workflow ID characters', async () => { | ||
const invalidWorkflowList = '1234567890@, abc/de, ef*gh, 12%34'; | ||
const cleanedUpWorkflowList = '1234567890, abcde, efgh, 1234'; | ||
|
||
settingsStore.settings.enterprise[EnterpriseEditionFeature.Sharing] = true; | ||
const wrapper = createComponent({ pinia }); | ||
|
||
await nextTick(); | ||
|
||
await fireEvent.click(wrapper.getByTestId('workflow-caller-policy')); | ||
console.log(window.document.querySelectorAll('.el-select-dropdown__item')[4].innerHTML); | ||
await fireEvent.click(window.document.querySelectorAll('.el-select-dropdown__item')[4]); | ||
|
||
await fireEvent.update( | ||
wrapper.getByTestId('workflow-caller-policy-workflow-ids'), | ||
invalidWorkflowList, | ||
); | ||
|
||
expect(wrapper.getByTestId('workflow-caller-policy-workflow-ids')).toHaveValue( | ||
cleanedUpWorkflowList, | ||
); | ||
}); | ||
}); |
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
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.
nitpick - maybe this could be a constant then? instead of this being a magic value and have to update it in two places
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.
They are slightly different, one contains the
g
modifier at the end, so I don't know if we can combine them.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.
ah missed that.. you can if you use new RegExp I guess but not a big deal