|
| 1 | +// Import necessary helpers and libraries. |
| 2 | +import { featureFlagIntercept } from "../../../../support/Objects/FeatureFlags"; |
| 3 | +import { |
| 4 | + agHelper, |
| 5 | + appSettings, |
| 6 | + assertHelper, |
| 7 | + deployMode, |
| 8 | + homePage, |
| 9 | + locators, |
| 10 | +} from "../../../../support/Objects/ObjectsCore"; |
| 11 | +import EditorNavigation, { |
| 12 | + EntityType, |
| 13 | +} from "../../../../support/Pages/EditorNavigation"; |
| 14 | +import pageList from "../../../../support/Pages/PageList"; |
| 15 | + |
| 16 | +describe( |
| 17 | + "On-Page Unload Functionality", |
| 18 | + { tags: ["@tag.JS", "@tag.Sanity"] }, |
| 19 | + () => { |
| 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 | + it("1. [Deployed Mode] Nav via links: Triggers unload, then doesn't on return", () => { |
| 37 | + deployMode.DeployApp(); |
| 38 | + // Start on Page 1 and navigate to Page 2. |
| 39 | + agHelper.WaitUntilEleAppear(appSettings.locators._header); |
| 40 | + agHelper.AssertElementVisibility( |
| 41 | + appSettings.locators._getActivePage(page1), |
| 42 | + ); |
| 43 | + agHelper.GetNClickByContains( |
| 44 | + appSettings.locators._navigationMenuItem, |
| 45 | + page2, |
| 46 | + ); |
| 47 | + agHelper.ValidateToastMessage(page1ToastForOnPageUnload); |
| 48 | + agHelper.GetNClickByContains( |
| 49 | + appSettings.locators._navigationMenuItem, |
| 50 | + page1, |
| 51 | + ); |
| 52 | + deployMode.NavigateBacktoEditor(); |
| 53 | + }); |
| 54 | + |
| 55 | + it("2. [Edit Mode] Nav via Page Selector: Triggers unload", () => { |
| 56 | + EditorNavigation.SelectEntityByName(page2, EntityType.Page); |
| 57 | + agHelper.ValidateToastMessage(page1ToastForOnPageUnload); |
| 58 | + agHelper.WaitUntilAllToastsDisappear(); |
| 59 | + |
| 60 | + EditorNavigation.SelectEntityByName(page3, EntityType.Page); |
| 61 | + agHelper.ValidateToastMessage(page2ToastForOnPageUnload); |
| 62 | + agHelper.WaitUntilAllToastsDisappear(); |
| 63 | + |
| 64 | + EditorNavigation.SelectEntityByName(page1, EntityType.Page); |
| 65 | + }); |
| 66 | + |
| 67 | + it("3. [Preview mode] Multiple Handlers: Triggers all handlers", () => { |
| 68 | + agHelper.GetNClick(locators._enterPreviewMode); |
| 69 | + agHelper.AssertElementVisibility( |
| 70 | + appSettings.locators._getActivePage(page1), |
| 71 | + ); |
| 72 | + agHelper.GetNClickByContains( |
| 73 | + appSettings.locators._navigationMenuItem, |
| 74 | + page2, |
| 75 | + ); |
| 76 | + agHelper.ValidateToastMessage(page1ToastForOnPageUnload); |
| 77 | + agHelper.WaitUntilAllToastsDisappear(); |
| 78 | + |
| 79 | + agHelper.GetNClickByContains( |
| 80 | + appSettings.locators._navigationMenuItem, |
| 81 | + page3, |
| 82 | + ); |
| 83 | + agHelper.ValidateToastMessage(page2ToastForOnPageUnload); |
| 84 | + agHelper.WaitUntilAllToastsDisappear(); |
| 85 | + agHelper.GetNClickByContains( |
| 86 | + appSettings.locators._navigationMenuItem, |
| 87 | + page1, |
| 88 | + ); |
| 89 | + agHelper.GetNClick(locators._exitPreviewMode); |
| 90 | + }); |
| 91 | + |
| 92 | + it("4. [Both Modes - Programmatic nav]: Triggers unload via button click", () => { |
| 93 | + agHelper.ClickButton(page1ButtonText); |
| 94 | + agHelper.ValidateToastMessage(page1ToastForOnPageUnload); |
| 95 | + agHelper.WaitUntilAllToastsDisappear(); |
| 96 | + pageList.ShowList(); |
| 97 | + EditorNavigation.SelectEntityByName(page1, EntityType.Page); |
| 98 | + |
| 99 | + deployMode.DeployApp(); |
| 100 | + agHelper.ClickButton(page1ButtonText); |
| 101 | + agHelper.ValidateToastMessage(page1ToastForOnPageUnload); |
| 102 | + agHelper.AssertElementVisibility( |
| 103 | + appSettings.locators._getActivePage(page2), |
| 104 | + ); |
| 105 | + agHelper.GetNClickByContains( |
| 106 | + appSettings.locators._navigationMenuItem, |
| 107 | + page1, |
| 108 | + ); |
| 109 | + deployMode.NavigateBacktoEditor(); |
| 110 | + }); |
| 111 | + }, |
| 112 | +); |
0 commit comments