Skip to content

Commit

Permalink
fix(editor): Change tooltip for workflow with execute workflow trigger (
Browse files Browse the repository at this point in the history
  • Loading branch information
igatanasov authored Oct 29, 2024
1 parent 60cdf0b commit dcd6038
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
82 changes: 82 additions & 0 deletions packages/editor-ui/src/components/WorkflowActivator.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { describe, it, expect, vi } from 'vitest';
import WorkflowActivator from '@/components/WorkflowActivator.vue';
import userEvent from '@testing-library/user-event';

import { useWorkflowsStore } from '@/stores/workflows.store';

import { createTestingPinia } from '@pinia/testing';
import { createComponentRenderer } from '@/__tests__/render';
import { mockedStore } from '@/__tests__/utils';
import { EXECUTE_WORKFLOW_TRIGGER_NODE_TYPE } from '@/constants';

const renderComponent = createComponentRenderer(WorkflowActivator);
let mockWorkflowsStore: ReturnType<typeof mockedStore<typeof useWorkflowsStore>>;

describe('WorkflowActivator', () => {
beforeEach(() => {
createTestingPinia();

mockWorkflowsStore = mockedStore(useWorkflowsStore);
});

afterEach(() => {
vi.clearAllMocks();
});

it('renders correctly', () => {
const renderOptions = {
props: {
workflowActive: false,
workflowId: '1',
workflowPermissions: { update: true },
},
};

const { getByTestId, getByRole } = renderComponent(renderOptions);
expect(getByTestId('workflow-activator-status')).toBeInTheDocument();
expect(getByRole('switch')).toBeInTheDocument();
});

it('display an inactive tooltip when there are no nodes available', async () => {
mockWorkflowsStore.workflowId = '1';

const { getByTestId, getByRole } = renderComponent({
props: {
workflowActive: false,
workflowId: '1',
workflowPermissions: { update: true },
},
});

await userEvent.hover(getByRole('switch'));
expect(getByRole('tooltip')).toBeInTheDocument();

expect(getByRole('tooltip')).toHaveTextContent(
'This workflow has no trigger nodes that require activation',
);
expect(getByTestId('workflow-activator-status')).toHaveTextContent('Inactive');
});

it('display an inactive tooltip when only execute workflow trigger is available', async () => {
mockWorkflowsStore.workflowId = '1';
mockWorkflowsStore.workflowTriggerNodes = [
{ type: EXECUTE_WORKFLOW_TRIGGER_NODE_TYPE, disabled: false } as never,
];

const { getByTestId, getByRole } = renderComponent({
props: {
workflowActive: false,
workflowId: '1',
workflowPermissions: { update: true },
},
});

await userEvent.hover(getByRole('switch'));
expect(getByRole('tooltip')).toBeInTheDocument();

expect(getByRole('tooltip')).toHaveTextContent(
"Execute Workflow Trigger' doesn't require activation as it is triggered by another workflow",
);
expect(getByTestId('workflow-activator-status')).toHaveTextContent('Inactive');
});
});
21 changes: 19 additions & 2 deletions packages/editor-ui/src/components/WorkflowActivator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { VNode } from 'vue';
import { computed, h } from 'vue';
import { useI18n } from '@/composables/useI18n';
import type { PermissionsRecord } from '@/permissions';
import { PLACEHOLDER_EMPTY_WORKFLOW_ID } from '@/constants';
import { EXECUTE_WORKFLOW_TRIGGER_NODE_TYPE, PLACEHOLDER_EMPTY_WORKFLOW_ID } from '@/constants';
import WorkflowActivationErrorMessage from './WorkflowActivationErrorMessage.vue';
const props = defineProps<{
Expand Down Expand Up @@ -43,6 +43,17 @@ const containsTrigger = computed((): boolean => {
return foundTriggers.length > 0;
});
const containsOnlyExecuteWorkflowTrigger = computed((): boolean => {
const foundActiveTriggers = workflowsStore.workflowTriggerNodes.filter(
(trigger) => !trigger.disabled,
);
const foundTriggers = foundActiveTriggers.filter(
(trigger) => trigger.type === EXECUTE_WORKFLOW_TRIGGER_NODE_TYPE,
);
return foundTriggers.length > 0 && foundTriggers.length === foundActiveTriggers.length;
});
const isNewWorkflow = computed(
() =>
!props.workflowId ||
Expand Down Expand Up @@ -109,7 +120,13 @@ async function displayActivationError() {
<n8n-tooltip :disabled="!disabled" placement="bottom">
<template #content>
<div>
{{ i18n.baseText('workflowActivator.thisWorkflowHasNoTriggerNodes') }}
{{
i18n.baseText(
containsOnlyExecuteWorkflowTrigger
? 'workflowActivator.thisWorkflowHasOnlyOneExecuteWorkflowTriggerNode'
: 'workflowActivator.thisWorkflowHasNoTriggerNodes',
)
}}
</div>
</template>
<el-switch
Expand Down
1 change: 1 addition & 0 deletions packages/editor-ui/src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,7 @@
"workflowActivator.showMessage.displayActivationError.title": "Problem activating workflow",
"workflowActivator.theWorkflowIsSetToBeActiveBut": "The workflow is activated but could not be started.<br />Click to display error message.",
"workflowActivator.thisWorkflowHasNoTriggerNodes": "This workflow has no trigger nodes that require activation",
"workflowActivator.thisWorkflowHasOnlyOneExecuteWorkflowTriggerNode": "'Execute Workflow Trigger' doesn't require activation as it is triggered by another workflow",
"workflowDetails.share": "Share",
"workflowDetails.active": "Active",
"workflowDetails.addTag": "Add tag",
Expand Down

0 comments on commit dcd6038

Please sign in to comment.