Skip to content

Commit

Permalink
fix(editor): Show all workflows in the error workflow dropdown in the…
Browse files Browse the repository at this point in the history
… workflow settings (#12413)
  • Loading branch information
despairblue authored Jan 6, 2025
1 parent f043ff1 commit ccda7f9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
29 changes: 29 additions & 0 deletions packages/editor-ui/src/components/WorkflowSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createPinia, setActivePinia } from 'pinia';
import WorkflowSettingsVue from '@/components/WorkflowSettings.vue';

import { setupServer } from '@/__tests__/server';
import type { MockInstance } from 'vitest';
import { afterAll, beforeAll } from 'vitest';
import { within } from '@testing-library/vue';
import userEvent from '@testing-library/user-event';
Expand All @@ -24,6 +25,8 @@ let workflowsStore: ReturnType<typeof useWorkflowsStore>;
let settingsStore: ReturnType<typeof useSettingsStore>;
let uiStore: ReturnType<typeof useUIStore>;

let fetchAllWorkflowsSpy: MockInstance<(typeof workflowsStore)['fetchAllWorkflows']>;

const createComponent = createComponentRenderer(WorkflowSettingsVue);

describe('WorkflowSettingsVue', () => {
Expand All @@ -46,6 +49,18 @@ describe('WorkflowSettingsVue', () => {

vi.spyOn(workflowsStore, 'workflowName', 'get').mockReturnValue('Test Workflow');
vi.spyOn(workflowsStore, 'workflowId', 'get').mockReturnValue('1');
fetchAllWorkflowsSpy = vi.spyOn(workflowsStore, 'fetchAllWorkflows').mockResolvedValue([
{
id: '1',
name: 'Test Workflow',
active: true,
nodes: [],
connections: {},
createdAt: 1,
updatedAt: 1,
versionId: '123',
},
]);
vi.spyOn(workflowsStore, 'getWorkflowById').mockReturnValue({
id: '1',
name: 'Test Workflow',
Expand Down Expand Up @@ -113,6 +128,20 @@ describe('WorkflowSettingsVue', () => {
expect(getByTestId('workflow-caller-policy-workflow-ids')).toBeVisible();
});

it('should fetch all workflows and render them in the error workflows dropdown', async () => {
settingsStore.settings.enterprise[EnterpriseEditionFeature.Sharing] = true;
const { getByTestId } = createComponent({ pinia });

await nextTick();
const dropdownItems = await getDropdownItems(getByTestId('error-workflow'));

// first is `- No Workflow -`, second is the workflow returned by
// `workflowsStore.fetchAllWorkflows`
expect(dropdownItems).toHaveLength(2);
expect(fetchAllWorkflowsSpy).toHaveBeenCalledTimes(1);
expect(fetchAllWorkflowsSpy).toHaveBeenCalledWith();
});

it('should not remove valid workflow ID characters', async () => {
const validWorkflowList = '1234567890, abcde, efgh, 1234';

Expand Down
6 changes: 2 additions & 4 deletions packages/editor-ui/src/components/WorkflowSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ const loadTimezones = async () => {
};
const loadWorkflows = async () => {
const workflowsData = (await workflowsStore.fetchAllWorkflows(
workflow.value.homeProject?.id,
)) as IWorkflowShortResponse[];
const workflowsData = (await workflowsStore.fetchAllWorkflows()) as IWorkflowShortResponse[];
workflowsData.sort((a, b) => {
if (a.name.toLowerCase() < b.name.toLowerCase()) {
return -1;
Expand Down Expand Up @@ -506,7 +504,7 @@ onMounted(async () => {
</el-col>
</el-row>

<el-row>
<el-row data-test-id="error-workflow">
<el-col :span="10" class="setting-name">
{{ i18n.baseText('workflowSettings.errorWorkflow') + ':' }}
<n8n-tooltip placement="top">
Expand Down

0 comments on commit ccda7f9

Please sign in to comment.