mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 20:54:07 -08:00
fix(editor): Prevent error from showing-up when duplicating unsaved workflow (#5833)
* fix(editor): Prevent error from showing-up when duplicating unsaved workflow * Add unsaved workflow duplicate test
This commit is contained in:
parent
87e979c19a
commit
0b0024d722
|
@ -190,37 +190,48 @@ describe('Workflow Actions', () => {
|
||||||
cy.url().should('include', '/workflow/new');
|
cy.url().should('include', '/workflow/new');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should duplicate workflow', () => {
|
describe('duplicate workflow', () => {
|
||||||
// Stub window.open so new tab is not getting opened
|
function duplicateWorkflow() {
|
||||||
cy.window().then((win) => {
|
WorkflowPage.getters.workflowMenu().should('be.visible');
|
||||||
cy.stub(win, 'open').as('open');
|
WorkflowPage.getters.workflowMenu().click();
|
||||||
|
WorkflowPage.getters.workflowMenuItemDuplicate().click();
|
||||||
|
WorkflowPage.getters.duplicateWorkflowModal().should('be.visible');
|
||||||
|
WorkflowPage.getters.duplicateWorkflowModal().find('input').first().should('be.visible');
|
||||||
|
WorkflowPage.getters.duplicateWorkflowModal().find('input').first().type('{selectall}');
|
||||||
|
WorkflowPage.getters
|
||||||
|
.duplicateWorkflowModal()
|
||||||
|
.find('input')
|
||||||
|
.first()
|
||||||
|
.type(DUPLICATE_WORKFLOW_NAME);
|
||||||
|
WorkflowPage.getters
|
||||||
|
.duplicateWorkflowModal()
|
||||||
|
.find('.el-select__tags input')
|
||||||
|
.type(DUPLICATE_WORKFLOW_TAG);
|
||||||
|
WorkflowPage.getters.duplicateWorkflowModal().find('.el-select__tags input').type('{enter}');
|
||||||
|
WorkflowPage.getters.duplicateWorkflowModal().find('.el-select__tags input').type('{enter}');
|
||||||
|
WorkflowPage.getters
|
||||||
|
.duplicateWorkflowModal()
|
||||||
|
.find('button')
|
||||||
|
.contains('Duplicate')
|
||||||
|
.should('be.visible');
|
||||||
|
WorkflowPage.getters.duplicateWorkflowModal().find('button').contains('Duplicate').click();
|
||||||
|
WorkflowPage.getters.errorToast().should('not.exist');
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
// Stub window.open so new tab is not getting opened
|
||||||
|
cy.window().then((win) => {
|
||||||
|
cy.stub(win, 'open').as('open');
|
||||||
|
});
|
||||||
|
WorkflowPage.actions.addNodeToCanvas(MANUAL_TRIGGER_NODE_NAME);
|
||||||
});
|
});
|
||||||
|
|
||||||
WorkflowPage.actions.addNodeToCanvas(MANUAL_TRIGGER_NODE_NAME);
|
it('should duplicate unsaved workflow', () => {
|
||||||
WorkflowPage.actions.saveWorkflowOnButtonClick();
|
duplicateWorkflow();
|
||||||
WorkflowPage.getters.workflowMenu().should('be.visible');
|
});
|
||||||
WorkflowPage.getters.workflowMenu().click();
|
it('should duplicate saved workflow', () => {
|
||||||
WorkflowPage.getters.workflowMenuItemDuplicate().click();
|
WorkflowPage.actions.saveWorkflowOnButtonClick();
|
||||||
WorkflowPage.getters.duplicateWorkflowModal().should('be.visible');
|
duplicateWorkflow();
|
||||||
WorkflowPage.getters.duplicateWorkflowModal().find('input').first().should('be.visible');
|
});
|
||||||
WorkflowPage.getters.duplicateWorkflowModal().find('input').first().type('{selectall}');
|
|
||||||
WorkflowPage.getters
|
|
||||||
.duplicateWorkflowModal()
|
|
||||||
.find('input')
|
|
||||||
.first()
|
|
||||||
.type(DUPLICATE_WORKFLOW_NAME);
|
|
||||||
WorkflowPage.getters
|
|
||||||
.duplicateWorkflowModal()
|
|
||||||
.find('.el-select__tags input')
|
|
||||||
.type(DUPLICATE_WORKFLOW_TAG);
|
|
||||||
WorkflowPage.getters.duplicateWorkflowModal().find('.el-select__tags input').type('{enter}');
|
|
||||||
WorkflowPage.getters.duplicateWorkflowModal().find('.el-select__tags input').type('{enter}');
|
|
||||||
WorkflowPage.getters
|
|
||||||
.duplicateWorkflowModal()
|
|
||||||
.find('button')
|
|
||||||
.contains('Duplicate')
|
|
||||||
.should('be.visible');
|
|
||||||
WorkflowPage.getters.duplicateWorkflowModal().find('button').contains('Duplicate').click();
|
|
||||||
WorkflowPage.getters.errorToast().should('not.exist');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -89,10 +89,18 @@ export default mixins(showMessage, workflowHelpers, restApi).extend({
|
||||||
computed: {
|
computed: {
|
||||||
...mapStores(useUsersStore, useSettingsStore, useWorkflowsStore),
|
...mapStores(useUsersStore, useSettingsStore, useWorkflowsStore),
|
||||||
workflowPermissions(): IPermissions {
|
workflowPermissions(): IPermissions {
|
||||||
return getWorkflowPermissions(
|
const isEmptyWorkflow = this.data.id === PLACEHOLDER_EMPTY_WORKFLOW_ID;
|
||||||
this.usersStore.currentUser,
|
const isCurrentWorkflowEmpty =
|
||||||
this.workflowsStore.getWorkflowById(this.data.id),
|
this.workflowsStore.workflow.id === PLACEHOLDER_EMPTY_WORKFLOW_ID;
|
||||||
);
|
|
||||||
|
// If the workflow to be duplicated is empty and the current workflow is also empty
|
||||||
|
// we need to use the current workflow to get the permissions
|
||||||
|
const currentWorkflow =
|
||||||
|
isEmptyWorkflow && isCurrentWorkflowEmpty
|
||||||
|
? this.workflowsStore.workflow
|
||||||
|
: this.workflowsStore.getWorkflowById(this.data.id);
|
||||||
|
|
||||||
|
return getWorkflowPermissions(this.usersStore.currentUser, currentWorkflow);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
|
Loading…
Reference in a new issue