mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(editor): Adjust URL on lost change warning Cancel or failed save (#13683)
This commit is contained in:
@@ -1,3 +1,13 @@
|
|||||||
export function getSaveChangesModal() {
|
export function getSaveChangesModal() {
|
||||||
return cy.get('.el-overlay').contains('Save changes before leaving?');
|
return cy.get('.el-overlay').contains('Save changes before leaving?');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this is the button next to 'Save Changes'
|
||||||
|
export function getCancelSaveChangesButton() {
|
||||||
|
return cy.get('.btn--cancel');
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is the top right 'x'
|
||||||
|
export function getCloseSaveChangesButton() {
|
||||||
|
return cy.get('.el-message-box__headerbtn');
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ export function getWorkflowsPageUrl() {
|
|||||||
return '/home/workflows';
|
return '/home/workflows';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getCreateWorkflowButton = () => cy.getByTestId('add-resource-workflow');
|
||||||
|
|
||||||
|
export const getNewWorkflowCardButton = () => cy.getByTestId('new-workflow-card');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Actions
|
* Actions
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,26 +1,59 @@
|
|||||||
import { getSaveChangesModal } from '../composables/modals/save-changes-modal';
|
import {
|
||||||
|
getCancelSaveChangesButton,
|
||||||
|
getCloseSaveChangesButton,
|
||||||
|
getSaveChangesModal,
|
||||||
|
} from '../composables/modals/save-changes-modal';
|
||||||
|
import { getHomeButton } from '../composables/projects';
|
||||||
|
import { addNodeToCanvas } from '../composables/workflow';
|
||||||
|
import {
|
||||||
|
getCreateWorkflowButton,
|
||||||
|
getNewWorkflowCardButton,
|
||||||
|
getWorkflowsPageUrl,
|
||||||
|
visitWorkflowsPage,
|
||||||
|
} from '../composables/workflowsPage';
|
||||||
import { EDIT_FIELDS_SET_NODE_NAME } from '../constants';
|
import { EDIT_FIELDS_SET_NODE_NAME } from '../constants';
|
||||||
import { WorkflowPage as WorkflowPageClass } from '../pages/workflow';
|
|
||||||
import { WorkflowsPage as WorkflowsPageClass } from '../pages/workflows';
|
|
||||||
|
|
||||||
const WorkflowsPage = new WorkflowsPageClass();
|
|
||||||
const WorkflowPage = new WorkflowPageClass();
|
|
||||||
|
|
||||||
describe('Workflows', () => {
|
describe('Workflows', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.visit(WorkflowsPage.url);
|
visitWorkflowsPage();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should ask to save unsaved changes before leaving route', () => {
|
it('should ask to save unsaved changes before leaving route', () => {
|
||||||
WorkflowsPage.getters.newWorkflowButtonCard().should('be.visible');
|
getNewWorkflowCardButton().should('be.visible');
|
||||||
WorkflowsPage.getters.newWorkflowButtonCard().click();
|
getNewWorkflowCardButton().click();
|
||||||
|
|
||||||
cy.createFixtureWorkflow('Test_workflow_1.json', 'Empty State Card Workflow');
|
cy.createFixtureWorkflow('Test_workflow_1.json', 'Empty State Card Workflow');
|
||||||
|
|
||||||
WorkflowPage.actions.addNodeToCanvas(EDIT_FIELDS_SET_NODE_NAME);
|
addNodeToCanvas(EDIT_FIELDS_SET_NODE_NAME);
|
||||||
|
|
||||||
cy.getByTestId('project-home-menu-item').click();
|
getHomeButton().click();
|
||||||
|
|
||||||
|
// We expect to still be on the workflow route here
|
||||||
|
cy.url().should('include', '/workflow/');
|
||||||
|
|
||||||
getSaveChangesModal().should('be.visible');
|
getSaveChangesModal().should('be.visible');
|
||||||
|
getCancelSaveChangesButton().click();
|
||||||
|
|
||||||
|
// Only now do we switch
|
||||||
|
cy.url().should('include', getWorkflowsPageUrl());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should correct route after cancelling saveChangesModal', () => {
|
||||||
|
getCreateWorkflowButton().click();
|
||||||
|
|
||||||
|
cy.createFixtureWorkflow('Test_workflow_1.json', 'Empty State Card Workflow');
|
||||||
|
addNodeToCanvas(EDIT_FIELDS_SET_NODE_NAME);
|
||||||
|
|
||||||
|
// Here we go back via browser rather than the home button
|
||||||
|
// As this already updates the route
|
||||||
|
cy.go(-1);
|
||||||
|
|
||||||
|
cy.url().should('include', getWorkflowsPageUrl());
|
||||||
|
|
||||||
|
getSaveChangesModal().should('be.visible');
|
||||||
|
getCloseSaveChangesButton().click();
|
||||||
|
|
||||||
|
// Confirm the url is back to the workflow
|
||||||
|
cy.url().should('include', '/workflow/');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
HTTP_REQUEST_NODE_TYPE,
|
HTTP_REQUEST_NODE_TYPE,
|
||||||
MODAL_CANCEL,
|
MODAL_CANCEL,
|
||||||
|
MODAL_CLOSE,
|
||||||
MODAL_CONFIRM,
|
MODAL_CONFIRM,
|
||||||
PLACEHOLDER_EMPTY_WORKFLOW_ID,
|
PLACEHOLDER_EMPTY_WORKFLOW_ID,
|
||||||
PLACEHOLDER_FILLED_AT_EXECUTION_TIME,
|
PLACEHOLDER_FILLED_AT_EXECUTION_TIME,
|
||||||
@@ -827,6 +828,12 @@ export function useWorkflowHelpers(options: { router: ReturnType<typeof useRoute
|
|||||||
|
|
||||||
const workflowDataRequest: IWorkflowDataUpdate = await getWorkflowDataToSave();
|
const workflowDataRequest: IWorkflowDataUpdate = await getWorkflowDataToSave();
|
||||||
|
|
||||||
|
// This can happen if the user has another workflow in the browser history and navigates
|
||||||
|
// via the browser back button, encountering our warning dialog with the new route already set
|
||||||
|
if (workflowDataRequest.id !== currentWorkflow) {
|
||||||
|
throw new Error('Attempted to save a workflow different from the current workflow');
|
||||||
|
}
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
workflowDataRequest.name = name.trim();
|
workflowDataRequest.name = name.trim();
|
||||||
}
|
}
|
||||||
@@ -1134,23 +1141,34 @@ export function useWorkflowHelpers(options: { router: ReturnType<typeof useRoute
|
|||||||
showClose: true,
|
showClose: true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (confirmModal === MODAL_CONFIRM) {
|
if (confirmModal === MODAL_CONFIRM) {
|
||||||
const saved = await saveCurrentWorkflow({}, false);
|
const saved = await saveCurrentWorkflow({}, false);
|
||||||
if (saved) {
|
if (saved) {
|
||||||
await npsSurveyStore.fetchPromptsData();
|
await npsSurveyStore.fetchPromptsData();
|
||||||
}
|
uiStore.stateIsDirty = false;
|
||||||
uiStore.stateIsDirty = false;
|
const goToNext = await confirm();
|
||||||
|
next(goToNext);
|
||||||
const goToNext = await confirm();
|
} else {
|
||||||
if (goToNext) {
|
next(
|
||||||
next();
|
router.resolve({
|
||||||
|
name: VIEWS.WORKFLOW,
|
||||||
|
params: { name: workflowsStore.workflow.id },
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else if (confirmModal === MODAL_CANCEL) {
|
} else if (confirmModal === MODAL_CANCEL) {
|
||||||
await cancel();
|
await cancel();
|
||||||
|
|
||||||
uiStore.stateIsDirty = false;
|
uiStore.stateIsDirty = false;
|
||||||
next();
|
next();
|
||||||
|
} else if (confirmModal === MODAL_CLOSE) {
|
||||||
|
// The route may have already changed due to the browser back button, so let's restore it
|
||||||
|
next(
|
||||||
|
router.resolve({
|
||||||
|
name: VIEWS.WORKFLOW,
|
||||||
|
params: { name: workflowsStore.workflow.id },
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
next();
|
next();
|
||||||
|
|||||||
Reference in New Issue
Block a user