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:
OlegIvaniv 2023-03-30 14:34:04 +02:00 committed by GitHub
parent 87e979c19a
commit 0b0024d722
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 34 deletions

View file

@ -190,14 +190,8 @@ describe('Workflow Actions', () => {
cy.url().should('include', '/workflow/new');
});
it('should duplicate workflow', () => {
// 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.saveWorkflowOnButtonClick();
describe('duplicate workflow', () => {
function duplicateWorkflow() {
WorkflowPage.getters.workflowMenu().should('be.visible');
WorkflowPage.getters.workflowMenu().click();
WorkflowPage.getters.workflowMenuItemDuplicate().click();
@ -222,5 +216,22 @@ describe('Workflow Actions', () => {
.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);
});
it('should duplicate unsaved workflow', () => {
duplicateWorkflow();
});
it('should duplicate saved workflow', () => {
WorkflowPage.actions.saveWorkflowOnButtonClick();
duplicateWorkflow();
});
});
});

View file

@ -89,10 +89,18 @@ export default mixins(showMessage, workflowHelpers, restApi).extend({
computed: {
...mapStores(useUsersStore, useSettingsStore, useWorkflowsStore),
workflowPermissions(): IPermissions {
return getWorkflowPermissions(
this.usersStore.currentUser,
this.workflowsStore.getWorkflowById(this.data.id),
);
const isEmptyWorkflow = this.data.id === PLACEHOLDER_EMPTY_WORKFLOW_ID;
const isCurrentWorkflowEmpty =
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: {