test: adds cypress spec to test onpage unload functionality (#41084)
## Description Adds spec file and fixture file for on page unload functionality Fixes #41000 _or_ Fixes `Issue URL` > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation /ok-to-test tags="@tag.JS, @tag.Sanity" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/16070917983> > Commit: 9435c88d922a2c1344cc5feb955ce3eb5f8620f5 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=16070917983&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.JS, @tag.Sanity` > Spec: > <hr>Fri, 04 Jul 2025 10:45:13 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added a comprehensive end-to-end test suite to verify on-page unload behavior across different application modes and navigation methods. * Included scenarios to ensure unload handlers trigger correctly and do not fire redundantly. * Confirmed execution of multiple unload handlers in preview mode. * **Chores** * Introduced a new application fixture for testing on-page unload actions with multiple pages, widgets, and JavaScript actions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
parent
f9e1a5d4e4
commit
96981d870b
|
|
@ -0,0 +1,112 @@
|
|||
// Import necessary helpers and libraries.
|
||||
import { featureFlagIntercept } from "../../../../support/Objects/FeatureFlags";
|
||||
import {
|
||||
agHelper,
|
||||
appSettings,
|
||||
assertHelper,
|
||||
deployMode,
|
||||
homePage,
|
||||
locators,
|
||||
} from "../../../../support/Objects/ObjectsCore";
|
||||
import EditorNavigation, {
|
||||
EntityType,
|
||||
} from "../../../../support/Pages/EditorNavigation";
|
||||
import pageList from "../../../../support/Pages/PageList";
|
||||
|
||||
describe(
|
||||
"On-Page Unload Functionality",
|
||||
{ tags: ["@tag.JS", "@tag.Sanity"] },
|
||||
() => {
|
||||
const page1 = "Page1 - with long long name";
|
||||
const page2 = "Page2 - with long long name";
|
||||
const page3 = "Page3 - with long long name";
|
||||
const page1ToastForOnPageUnload = "Page 1 on page unload.";
|
||||
const page2ToastForOnPageUnload = "Page 2 on page unload.";
|
||||
const page1ButtonText = "Submit";
|
||||
// Setup: Runs once before all tests in this block.
|
||||
before(() => {
|
||||
homePage.NavigateToHome();
|
||||
homePage.ImportApp("onPageUnloadBehavior_app.json");
|
||||
assertHelper.AssertNetworkStatus("@importNewApplication");
|
||||
featureFlagIntercept({
|
||||
release_jsobjects_onpageunloadactions_enabled: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("1. [Deployed Mode] Nav via links: Triggers unload, then doesn't on return", () => {
|
||||
deployMode.DeployApp();
|
||||
// Start on Page 1 and navigate to Page 2.
|
||||
agHelper.WaitUntilEleAppear(appSettings.locators._header);
|
||||
agHelper.AssertElementVisibility(
|
||||
appSettings.locators._getActivePage(page1),
|
||||
);
|
||||
agHelper.GetNClickByContains(
|
||||
appSettings.locators._navigationMenuItem,
|
||||
page2,
|
||||
);
|
||||
agHelper.ValidateToastMessage(page1ToastForOnPageUnload);
|
||||
agHelper.GetNClickByContains(
|
||||
appSettings.locators._navigationMenuItem,
|
||||
page1,
|
||||
);
|
||||
deployMode.NavigateBacktoEditor();
|
||||
});
|
||||
|
||||
it("2. [Edit Mode] Nav via Page Selector: Triggers unload", () => {
|
||||
EditorNavigation.SelectEntityByName(page2, EntityType.Page);
|
||||
agHelper.ValidateToastMessage(page1ToastForOnPageUnload);
|
||||
agHelper.WaitUntilAllToastsDisappear();
|
||||
|
||||
EditorNavigation.SelectEntityByName(page3, EntityType.Page);
|
||||
agHelper.ValidateToastMessage(page2ToastForOnPageUnload);
|
||||
agHelper.WaitUntilAllToastsDisappear();
|
||||
|
||||
EditorNavigation.SelectEntityByName(page1, EntityType.Page);
|
||||
});
|
||||
|
||||
it("3. [Preview mode] Multiple Handlers: Triggers all handlers", () => {
|
||||
agHelper.GetNClick(locators._enterPreviewMode);
|
||||
agHelper.AssertElementVisibility(
|
||||
appSettings.locators._getActivePage(page1),
|
||||
);
|
||||
agHelper.GetNClickByContains(
|
||||
appSettings.locators._navigationMenuItem,
|
||||
page2,
|
||||
);
|
||||
agHelper.ValidateToastMessage(page1ToastForOnPageUnload);
|
||||
agHelper.WaitUntilAllToastsDisappear();
|
||||
|
||||
agHelper.GetNClickByContains(
|
||||
appSettings.locators._navigationMenuItem,
|
||||
page3,
|
||||
);
|
||||
agHelper.ValidateToastMessage(page2ToastForOnPageUnload);
|
||||
agHelper.WaitUntilAllToastsDisappear();
|
||||
agHelper.GetNClickByContains(
|
||||
appSettings.locators._navigationMenuItem,
|
||||
page1,
|
||||
);
|
||||
agHelper.GetNClick(locators._exitPreviewMode);
|
||||
});
|
||||
|
||||
it("4. [Both Modes - Programmatic nav]: Triggers unload via button click", () => {
|
||||
agHelper.ClickButton(page1ButtonText);
|
||||
agHelper.ValidateToastMessage(page1ToastForOnPageUnload);
|
||||
agHelper.WaitUntilAllToastsDisappear();
|
||||
pageList.ShowList();
|
||||
EditorNavigation.SelectEntityByName(page1, EntityType.Page);
|
||||
|
||||
deployMode.DeployApp();
|
||||
agHelper.ClickButton(page1ButtonText);
|
||||
agHelper.ValidateToastMessage(page1ToastForOnPageUnload);
|
||||
agHelper.AssertElementVisibility(
|
||||
appSettings.locators._getActivePage(page2),
|
||||
);
|
||||
agHelper.GetNClickByContains(
|
||||
appSettings.locators._navigationMenuItem,
|
||||
page1,
|
||||
);
|
||||
deployMode.NavigateBacktoEditor();
|
||||
});
|
||||
},
|
||||
);
|
||||
2597
app/client/cypress/fixtures/onPageUnloadBehavior_app.json
Normal file
2597
app/client/cypress/fixtures/onPageUnloadBehavior_app.json
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user