Skip to content

Commit 5796a0d

Browse files
committed
feat: add Cypress tests for onPageUnload functionality in both edit and deployed modes
This commit introduces comprehensive Cypress tests to validate the onPageUnload behavior during navigation in both edit and deployed modes. The tests ensure that the appropriate unload actions are triggered when navigating between pages, enhancing the reliability of the application during user interactions. The new test file `OnPageUnload_spec.ts` includes scenarios for navigation via links, page selectors, and programmatic navigation, ensuring that toast messages are displayed correctly for each page transition. Additionally, a fixture file `onPageUnloadBehavior_app.json` is added to support the testing environment with necessary application data. Fixes #41074
1 parent 3421f8b commit 5796a0d

2 files changed

Lines changed: 2712 additions & 0 deletions

File tree

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Import necessary helpers and libraries.
2+
import {
3+
agHelper,
4+
appSettings,
5+
assertHelper,
6+
deployMode,
7+
entityExplorer,
8+
homePage,
9+
jsEditor,
10+
locators,
11+
propPane,
12+
} from "../../../support/Objects/ObjectsCore";
13+
import pageList from "../../../support/Pages/PageList";
14+
import EditorNavigation, {
15+
EntityType,
16+
} from "../../../support/Pages/EditorNavigation";
17+
import { featureFlagIntercept } from "../../../support/Objects/FeatureFlags";
18+
19+
describe("On-Page Unload Functionality", () => {
20+
const page1 = "Page1 - with long long name";
21+
const page2 = "Page2 - with long long name";
22+
const page3 = "Page3 - with long long name";
23+
const page1ToastForOnPageUnload = "Page 1 on page unload.";
24+
const page2ToastForOnPageUnload = "Page 2 on page unload.";
25+
const page1ButtonText = "Submit";
26+
// Setup: Runs once before all tests in this block.
27+
before(() => {
28+
homePage.NavigateToHome();
29+
homePage.ImportApp("onPageUnloadBehavior_app.json");
30+
assertHelper.AssertNetworkStatus("@importNewApplication");
31+
featureFlagIntercept({
32+
release_jsobjects_onpageunloadactions_enabled: true,
33+
});
34+
});
35+
36+
describe("Deployed mode:", () => {
37+
it("1. Nav via links (Deployed Mode): Triggers unload, then doesn't on return", () => {
38+
deployMode.DeployApp();
39+
// Start on Page 1 and navigate to Page 2.
40+
agHelper.WaitUntilEleAppear(appSettings.locators._header);
41+
agHelper.AssertElementVisibility(
42+
appSettings.locators._getActivePage(page1),
43+
);
44+
agHelper.GetNClickByContains(
45+
appSettings.locators._navigationMenuItem,
46+
page2,
47+
);
48+
agHelper.ValidateToastMessage(page1ToastForOnPageUnload);
49+
agHelper.GetNClickByContains(
50+
appSettings.locators._navigationMenuItem,
51+
page1,
52+
);
53+
deployMode.NavigateBacktoEditor();
54+
});
55+
});
56+
57+
describe("Edit mode:", () => {
58+
it("2. Nav via Page Selector (Edit Mode): Triggers unload", () => {
59+
EditorNavigation.SelectEntityByName(page2, EntityType.Page);
60+
agHelper.ValidateToastMessage(page1ToastForOnPageUnload);
61+
agHelper.WaitUntilAllToastsDisappear();
62+
63+
EditorNavigation.SelectEntityByName(page3, EntityType.Page);
64+
agHelper.ValidateToastMessage(page2ToastForOnPageUnload);
65+
agHelper.WaitUntilAllToastsDisappear();
66+
67+
EditorNavigation.SelectEntityByName(page1, EntityType.Page);
68+
});
69+
70+
it("3. Multiple Handlers: Triggers all handlers on a Preview mode", () => {
71+
agHelper.GetNClick(locators._enterPreviewMode);
72+
agHelper.AssertElementVisibility(
73+
appSettings.locators._getActivePage(page1),
74+
);
75+
agHelper.GetNClickByContains(
76+
appSettings.locators._navigationMenuItem,
77+
page2,
78+
);
79+
agHelper.ValidateToastMessage(page1ToastForOnPageUnload);
80+
agHelper.WaitUntilAllToastsDisappear();
81+
82+
agHelper.GetNClickByContains(
83+
appSettings.locators._navigationMenuItem,
84+
page3,
85+
);
86+
agHelper.ValidateToastMessage(page2ToastForOnPageUnload);
87+
agHelper.WaitUntilAllToastsDisappear();
88+
agHelper.GetNClickByContains(
89+
appSettings.locators._navigationMenuItem,
90+
page1,
91+
);
92+
agHelper.GetNClick(locators._exitPreviewMode);
93+
});
94+
});
95+
96+
it("4. Programmatic nav (Both Modes): Triggers unload via button click", () => {
97+
agHelper.ClickButton(page1ButtonText);
98+
agHelper.ValidateToastMessage(page1ToastForOnPageUnload);
99+
agHelper.WaitUntilAllToastsDisappear();
100+
pageList.ShowList();
101+
EditorNavigation.SelectEntityByName(page1, EntityType.Page);
102+
103+
deployMode.DeployApp();
104+
agHelper.ClickButton(page1ButtonText);
105+
agHelper.ValidateToastMessage(page1ToastForOnPageUnload);
106+
agHelper.AssertElementVisibility(
107+
appSettings.locators._getActivePage(page2),
108+
);
109+
agHelper.GetNClickByContains(
110+
appSettings.locators._navigationMenuItem,
111+
page1,
112+
);
113+
deployMode.NavigateBacktoEditor();
114+
});
115+
});

0 commit comments

Comments
 (0)