-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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): Fix workflow card open action #8839
Changes from 4 commits
abf93d8
928bae9
5dd4b67
38e64c4
739acb1
47a9086
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 |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
</n8n-text> | ||
</div> | ||
<template #append> | ||
<div ref="cardActions" :class="$style.cardActions"> | ||
<div :class="$style.cardActions" @click.stop> | ||
<enterprise-edition :features="[EnterpriseEditionFeature.Sharing]"> | ||
<n8n-badge v-if="workflowPermissions.isOwner" class="mr-xs" theme="tertiary" bold> | ||
{{ $locale.baseText('workflows.item.owner') }} | ||
|
@@ -48,7 +48,6 @@ | |
theme="dark" | ||
data-test-id="workflow-card-actions" | ||
@action="onAction" | ||
@click.stop | ||
/> | ||
</div> | ||
</template> | ||
|
@@ -169,15 +168,8 @@ export default defineComponent({ | |
}, | ||
}, | ||
methods: { | ||
async onClick(event: Event) { | ||
if ( | ||
this.$refs.cardActions === event.target || | ||
this.$refs.cardActions?.contains(event.target) | ||
) { | ||
return; | ||
} | ||
|
||
if (event.metaKey || event.ctrlKey) { | ||
async onClick(event?: KeyboardEvent | PointerEvent) { | ||
if (event?.metaKey || event?.ctrlKey) { | ||
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 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. Sure, done 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. This change has broken the functionality and also the unit test. With nullish coalescing if Rolling back the change |
||
const route = this.$router.resolve({ | ||
name: VIEWS.WORKFLOW, | ||
params: { name: this.data.id }, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import type { MockInstance } from 'vitest'; | ||
import { setActivePinia, createPinia } from 'pinia'; | ||
import { waitFor, within } from '@testing-library/vue'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { createComponentRenderer } from '@/__tests__/render'; | ||
import { VIEWS } from '@/constants'; | ||
import WorkflowCard from '@/components/WorkflowCard.vue'; | ||
|
||
const $router = { | ||
push: vi.fn(), | ||
resolve: vi.fn().mockImplementation(() => ({ href: '' })), | ||
}; | ||
|
||
const renderComponent = createComponentRenderer(WorkflowCard, { | ||
global: { | ||
mocks: { | ||
$router, | ||
}, | ||
}, | ||
}); | ||
|
||
const createWorkflow = (overrides = {}) => ({ | ||
id: '1', | ||
name: 'My Workflow', | ||
createdAt: '2021-01-01T00:00:00.000Z', | ||
...overrides, | ||
}); | ||
|
||
describe('WorkflowCard', () => { | ||
let pinia: ReturnType<typeof createPinia>; | ||
let windowOpenSpy: MockInstance; | ||
|
||
beforeEach(async () => { | ||
pinia = createPinia(); | ||
setActivePinia(pinia); | ||
windowOpenSpy = vi.spyOn(window, 'open'); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('should render a card with the workflow name and open workflow clicking on it', async () => { | ||
const data = createWorkflow(); | ||
const { getByRole } = renderComponent({ props: { data } }); | ||
const cardTitle = getByRole('heading', { level: 2, name: data.name }); | ||
|
||
expect(cardTitle).toBeInTheDocument(); | ||
|
||
await userEvent.click(cardTitle); | ||
await waitFor(() => { | ||
expect($router.push).toHaveBeenCalledWith({ | ||
name: VIEWS.WORKFLOW, | ||
params: { name: data.id }, | ||
}); | ||
}); | ||
|
||
// Opens in new tab if meta key is used | ||
const user = userEvent.setup(); | ||
|
||
await user.keyboard('[ControlLeft>]'); | ||
await user.click(cardTitle); | ||
await waitFor(() => { | ||
expect($router.push).toHaveBeenCalledTimes(1); | ||
}); | ||
expect(windowOpenSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should open card actions menu and not open workflow, open only on card action', async () => { | ||
const data = createWorkflow(); | ||
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); | ||
await waitFor(() => { | ||
expect($router.push).not.toHaveBeenCalled(); | ||
}); | ||
|
||
const actions = document.querySelector(`#${controllingId}`); | ||
await waitFor(() => { | ||
expect(actions).toBeInTheDocument(); | ||
}); | ||
await userEvent.click(actions!.querySelectorAll('li')[0]); | ||
await waitFor(() => { | ||
expect($router.push).toHaveBeenCalledWith({ | ||
name: VIEWS.WORKFLOW, | ||
params: { name: data.id }, | ||
}); | ||
}); | ||
}); | ||
}); |
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.
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.
@krynble that was checking manually if the
ref="cardActions"
div is the event target or if it contains the event target but it's easier to stop the event on this div by adding@click.stop
.The purpose of both solution is to stop opening the workflow when you click on the right side area of the workflow card (where there are other actions)