-
Notifications
You must be signed in to change notification settings - Fork 50.8k
fix(editor): Missing duplicate workflow action on workflow list #22230
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
Open
guillaumejacquart
wants to merge
2
commits into
master
Choose a base branch
from
pay-4170-missing-duplicate-option-in-workflow-list-view
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+164
−1
Open
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
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 |
|---|---|---|
|
|
@@ -6,13 +6,16 @@ import { type MockedStore, mockedStore } from '@/__tests__/utils'; | |
| import { MODAL_CONFIRM, VIEWS } from '@/app/constants'; | ||
| import WorkflowCard from '@/app/components/WorkflowCard.vue'; | ||
| import type { WorkflowResource } from '@/Interface'; | ||
| import type { IUser } from '@n8n/rest-api-client/api/users'; | ||
| import * as vueRouter from 'vue-router'; | ||
| import { useProjectsStore } from '@/features/collaboration/projects/projects.store'; | ||
| import type { ProjectListItem } from '@/features/collaboration/projects/projects.types'; | ||
| import { useMessage } from '@/app/composables/useMessage'; | ||
| import { useToast } from '@/app/composables/useToast'; | ||
| import { useWorkflowsStore } from '@/app/stores/workflows.store'; | ||
| import { createTestingPinia } from '@pinia/testing'; | ||
| import { useSettingsStore } from '@/app/stores/settings.store'; | ||
| import { useUsersStore } from '@/features/settings/users/users.store'; | ||
|
|
||
| vi.mock('vue-router', () => { | ||
| const push = vi.fn(); | ||
|
|
@@ -73,6 +76,7 @@ describe('WorkflowCard', () => { | |
| let projectsStore: MockedStore<typeof useProjectsStore>; | ||
| let settingsStore: MockedStore<typeof useSettingsStore>; | ||
| let workflowsStore: MockedStore<typeof useWorkflowsStore>; | ||
| let usersStore: MockedStore<typeof useUsersStore>; | ||
| let message: ReturnType<typeof useMessage>; | ||
| let toast: ReturnType<typeof useToast>; | ||
|
|
||
|
|
@@ -81,6 +85,7 @@ describe('WorkflowCard', () => { | |
| projectsStore = mockedStore(useProjectsStore); | ||
| settingsStore = mockedStore(useSettingsStore); | ||
| workflowsStore = mockedStore(useWorkflowsStore); | ||
| usersStore = mockedStore(useUsersStore); | ||
| message = useMessage(); | ||
| toast = useToast(); | ||
|
|
||
|
|
@@ -631,4 +636,143 @@ describe('WorkflowCard', () => { | |
| expect(queryByTestId('workflow-card-archived')).not.toBeInTheDocument(); | ||
| expect(queryByTestId('workflow-card-activator')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("should show 'Duplicate' action when user has read permission and can create workflows", async () => { | ||
| const data = createWorkflow({ | ||
| scopes: ['workflow:read'], | ||
| isArchived: false, | ||
| }); | ||
|
|
||
| vi.spyOn(vueRouter, 'useRoute').mockReturnValueOnce({ | ||
| name: VIEWS.PROJECTS, | ||
| } as vueRouter.RouteLocationNormalizedLoadedGeneric); | ||
|
|
||
| // Mock user with global workflow create permission | ||
| usersStore.currentUser = { | ||
| id: '1', | ||
| email: '[email protected]', | ||
| firstName: 'Test', | ||
| lastName: 'User', | ||
| isDefaultUser: false, | ||
| isPendingUser: false, | ||
| mfaEnabled: false, | ||
| globalScopes: ['workflow:create'], | ||
| } as IUser; | ||
|
|
||
| const { getByTestId } = renderComponent({ props: { data } }); | ||
| const cardActions = getByTestId('workflow-card-actions'); | ||
|
|
||
| expect(cardActions).toBeInTheDocument(); | ||
|
|
||
| const cardActionsOpener = within(cardActions).getByRole('button'); | ||
| expect(cardActionsOpener).toBeInTheDocument(); | ||
|
|
||
| const controllingId = cardActionsOpener.getAttribute('aria-controls'); | ||
|
|
||
| await userEvent.click(cardActions); | ||
| const actions = document.querySelector<HTMLElement>(`#${controllingId}`); | ||
| if (!actions) { | ||
| throw new Error('Actions menu not found'); | ||
| } | ||
| expect(actions).toHaveTextContent('Duplicate'); | ||
| }); | ||
|
|
||
| it("should show 'Duplicate' action when user has project-level create workflow permission", async () => { | ||
| const projectId = 'project-123'; | ||
| const data = createWorkflow({ | ||
| scopes: ['workflow:read'], | ||
| isArchived: false, | ||
| homeProject: { | ||
| id: projectId, | ||
| name: 'Test Project', | ||
| }, | ||
| }); | ||
|
|
||
| vi.spyOn(vueRouter, 'useRoute').mockReturnValueOnce({ | ||
| name: VIEWS.PROJECTS, | ||
| } as vueRouter.RouteLocationNormalizedLoadedGeneric); | ||
|
|
||
| // Mock user without global workflow create permission | ||
| usersStore.currentUser = { | ||
| id: '1', | ||
| email: '[email protected]', | ||
| firstName: 'Test', | ||
| lastName: 'User', | ||
| isDefaultUser: false, | ||
| isPendingUser: false, | ||
| mfaEnabled: false, | ||
| globalScopes: [], | ||
| } as IUser; | ||
|
|
||
| // Mock project with workflow create permission | ||
| projectsStore.myProjects = [ | ||
| { | ||
| id: projectId, | ||
| name: 'Test Project', | ||
| icon: null, | ||
| type: 'team', | ||
| createdAt: new Date().toISOString(), | ||
| updatedAt: new Date().toISOString(), | ||
| role: 'project:editor', | ||
| scopes: ['workflow:create'], | ||
| } as ProjectListItem, | ||
| ]; | ||
|
|
||
| const { getByTestId } = renderComponent({ props: { data } }); | ||
| const cardActions = getByTestId('workflow-card-actions'); | ||
|
|
||
| expect(cardActions).toBeInTheDocument(); | ||
|
|
||
| const cardActionsOpener = within(cardActions).getByRole('button'); | ||
| expect(cardActionsOpener).toBeInTheDocument(); | ||
|
|
||
| const controllingId = cardActionsOpener.getAttribute('aria-controls'); | ||
|
|
||
| await userEvent.click(cardActions); | ||
| const actions = document.querySelector<HTMLElement>(`#${controllingId}`); | ||
| if (!actions) { | ||
| throw new Error('Actions menu not found'); | ||
| } | ||
| expect(actions).toHaveTextContent('Duplicate'); | ||
| }); | ||
|
|
||
| it("should not show 'Duplicate' action when user does not have create workflow permission", async () => { | ||
| const data = createWorkflow({ | ||
| scopes: ['workflow:read'], | ||
| isArchived: false, | ||
| }); | ||
|
|
||
| vi.spyOn(vueRouter, 'useRoute').mockReturnValueOnce({ | ||
| name: VIEWS.PROJECTS, | ||
| } as vueRouter.RouteLocationNormalizedLoadedGeneric); | ||
|
|
||
| // Mock user without workflow create permission | ||
| usersStore.currentUser = { | ||
| id: '1', | ||
| email: '[email protected]', | ||
| firstName: 'Test', | ||
| lastName: 'User', | ||
| isDefaultUser: false, | ||
| isPendingUser: false, | ||
| mfaEnabled: false, | ||
| globalScopes: [], | ||
| } as IUser; | ||
|
|
||
| const { getByTestId } = renderComponent({ props: { data } }); | ||
| const cardActions = getByTestId('workflow-card-actions'); | ||
|
|
||
| expect(cardActions).toBeInTheDocument(); | ||
|
|
||
| const cardActionsOpener = within(cardActions).getByRole('button'); | ||
| expect(cardActionsOpener).toBeInTheDocument(); | ||
|
|
||
| const controllingId = cardActionsOpener.getAttribute('aria-controls'); | ||
|
|
||
| await userEvent.click(cardActions); | ||
| const actions = document.querySelector<HTMLElement>(`#${controllingId}`); | ||
| if (!actions) { | ||
| throw new Error('Actions menu not found'); | ||
| } | ||
| expect(actions).not.toHaveTextContent('Duplicate'); | ||
| }); | ||
| }); | ||
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
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.
Unrelated to your changes: Took me a while to understand this because of the
homeProjectattribute name.Do you know where the name
homeProjectcomes from, rather than just usingproject?