fix(editor): Show all workflows in the error workflow dropdown in the workflow settings (#12413)

This commit is contained in:
Danny Martini 2025-01-06 11:35:53 +01:00 committed by GitHub
parent f043ff12c6
commit ccda7f9c62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 4 deletions

View file

@ -2,6 +2,7 @@ import { createPinia, setActivePinia } from 'pinia';
import WorkflowSettingsVue from '@/components/WorkflowSettings.vue'; import WorkflowSettingsVue from '@/components/WorkflowSettings.vue';
import { setupServer } from '@/__tests__/server'; import { setupServer } from '@/__tests__/server';
import type { MockInstance } from 'vitest';
import { afterAll, beforeAll } from 'vitest'; import { afterAll, beforeAll } from 'vitest';
import { within } from '@testing-library/vue'; import { within } from '@testing-library/vue';
import userEvent from '@testing-library/user-event'; import userEvent from '@testing-library/user-event';
@ -24,6 +25,8 @@ let workflowsStore: ReturnType<typeof useWorkflowsStore>;
let settingsStore: ReturnType<typeof useSettingsStore>; let settingsStore: ReturnType<typeof useSettingsStore>;
let uiStore: ReturnType<typeof useUIStore>; let uiStore: ReturnType<typeof useUIStore>;
let fetchAllWorkflowsSpy: MockInstance<(typeof workflowsStore)['fetchAllWorkflows']>;
const createComponent = createComponentRenderer(WorkflowSettingsVue); const createComponent = createComponentRenderer(WorkflowSettingsVue);
describe('WorkflowSettingsVue', () => { describe('WorkflowSettingsVue', () => {
@ -46,6 +49,18 @@ describe('WorkflowSettingsVue', () => {
vi.spyOn(workflowsStore, 'workflowName', 'get').mockReturnValue('Test Workflow'); vi.spyOn(workflowsStore, 'workflowName', 'get').mockReturnValue('Test Workflow');
vi.spyOn(workflowsStore, 'workflowId', 'get').mockReturnValue('1'); 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({ vi.spyOn(workflowsStore, 'getWorkflowById').mockReturnValue({
id: '1', id: '1',
name: 'Test Workflow', name: 'Test Workflow',
@ -113,6 +128,20 @@ describe('WorkflowSettingsVue', () => {
expect(getByTestId('workflow-caller-policy-workflow-ids')).toBeVisible(); 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 () => { it('should not remove valid workflow ID characters', async () => {
const validWorkflowList = '1234567890, abcde, efgh, 1234'; const validWorkflowList = '1234567890, abcde, efgh, 1234';

View file

@ -266,9 +266,7 @@ const loadTimezones = async () => {
}; };
const loadWorkflows = async () => { const loadWorkflows = async () => {
const workflowsData = (await workflowsStore.fetchAllWorkflows( const workflowsData = (await workflowsStore.fetchAllWorkflows()) as IWorkflowShortResponse[];
workflow.value.homeProject?.id,
)) as IWorkflowShortResponse[];
workflowsData.sort((a, b) => { workflowsData.sort((a, b) => {
if (a.name.toLowerCase() < b.name.toLowerCase()) { if (a.name.toLowerCase() < b.name.toLowerCase()) {
return -1; return -1;
@ -506,7 +504,7 @@ onMounted(async () => {
</el-col> </el-col>
</el-row> </el-row>
<el-row> <el-row data-test-id="error-workflow">
<el-col :span="10" class="setting-name"> <el-col :span="10" class="setting-name">
{{ i18n.baseText('workflowSettings.errorWorkflow') + ':' }} {{ i18n.baseText('workflowSettings.errorWorkflow') + ':' }}
<n8n-tooltip placement="top"> <n8n-tooltip placement="top">