|
| 1 | +import { element, by } from "detox"; |
| 2 | +import { Step } from "jest-allure2-reporter/api"; |
| 3 | +import { openDeeplink } from "../../helpers/commonHelpers"; |
| 4 | + |
| 5 | +export default class MainNavigationPage { |
| 6 | + // --- Wallet 4.0 bottom tabs --- |
| 7 | + // withAncestor scopes to the tab bar, avoiding collisions with same-label CTAs elsewhere on the page. |
| 8 | + wallet40HomeTab = () => element(by.label("Home").withAncestor(by.id("w40-tab-bar"))); |
| 9 | + wallet40SwapTab = () => element(by.label("Swap").withAncestor(by.id("w40-tab-bar"))); |
| 10 | + wallet40EarnTab = () => element(by.label("Earn").withAncestor(by.id("w40-tab-bar"))); |
| 11 | + wallet40CardTab = () => element(by.label("Card").withAncestor(by.id("w40-tab-bar"))); |
| 12 | + |
| 13 | + // --- Wallet 4.0 top bar buttons --- |
| 14 | + topBarMyLedgerId = "topbar-myledger"; |
| 15 | + topBarDiscoverId = "topbar-discover"; |
| 16 | + topBarNotificationsId = "topbar-notifications"; |
| 17 | + topBarSettingsId = "topbar-settings"; |
| 18 | + |
| 19 | + // --- Legacy bottom tabs --- |
| 20 | + legacyPortfolioTabId = "tab-bar-portfolio"; |
| 21 | + legacyEarnTabId = "tab-bar-earn"; |
| 22 | + legacyTransferButtonId = "transfer-button"; |
| 23 | + legacyDiscoverTabId = "tab-bar-discover"; |
| 24 | + legacyMyLedgerTabId = "TabBarManager"; |
| 25 | + |
| 26 | + // --- Destination page verification IDs --- |
| 27 | + portfolioAccountsListId = "PortfolioAccountsList"; |
| 28 | + portfolioEmptyListId = "PortfolioEmptyList"; |
| 29 | + swapFormId = "swap-form-tab"; |
| 30 | + earnScreenId = "earn-screen"; |
| 31 | + cardScreenId = "card-landing-screen"; |
| 32 | + managerHeaderTitle = "My Ledger"; |
| 33 | + discoverHeaderTitle = "Discover"; |
| 34 | + settingsCardId = "general-settings-card"; |
| 35 | + |
| 36 | + // ===================== |
| 37 | + // Wait helpers |
| 38 | + // ===================== |
| 39 | + |
| 40 | + @Step("Wait for Wallet 4.0 navigation to be ready") |
| 41 | + async waitForWallet40Ready() { |
| 42 | + await waitForElementById(this.topBarSettingsId, 120000); |
| 43 | + } |
| 44 | + |
| 45 | + @Step("Wait for Legacy navigation to be ready") |
| 46 | + async waitForLegacyReady() { |
| 47 | + await waitForElementById(this.legacyMyLedgerTabId, 120000); |
| 48 | + } |
| 49 | + |
| 50 | + // ===================== |
| 51 | + // Wallet 4.0 Tab Actions |
| 52 | + // ===================== |
| 53 | + |
| 54 | + @Step("Tap Home tab (Wallet 4.0)") |
| 55 | + async tapWallet40HomeTab() { |
| 56 | + await this.wallet40HomeTab().tap(); |
| 57 | + } |
| 58 | + |
| 59 | + @Step("Tap Swap tab (Wallet 4.0)") |
| 60 | + async tapWallet40SwapTab() { |
| 61 | + await this.wallet40SwapTab().tap(); |
| 62 | + } |
| 63 | + |
| 64 | + @Step("Tap Earn tab (Wallet 4.0)") |
| 65 | + async tapWallet40EarnTab() { |
| 66 | + await this.wallet40EarnTab().tap(); |
| 67 | + } |
| 68 | + |
| 69 | + @Step("Tap Card tab (Wallet 4.0)") |
| 70 | + async tapWallet40CardTab() { |
| 71 | + await this.wallet40CardTab().tap(); |
| 72 | + } |
| 73 | + |
| 74 | + // ===================== |
| 75 | + // Wallet 4.0 Top Bar Actions |
| 76 | + // ===================== |
| 77 | + |
| 78 | + @Step("Tap My Ledger in top bar") |
| 79 | + async tapTopBarMyLedger() { |
| 80 | + await tapById(this.topBarMyLedgerId); |
| 81 | + } |
| 82 | + |
| 83 | + @Step("Tap Discover in top bar") |
| 84 | + async tapTopBarDiscover() { |
| 85 | + await tapById(this.topBarDiscoverId); |
| 86 | + } |
| 87 | + |
| 88 | + @Step("Tap Notifications in top bar") |
| 89 | + async tapTopBarNotifications() { |
| 90 | + await tapById(this.topBarNotificationsId); |
| 91 | + } |
| 92 | + |
| 93 | + @Step("Tap Settings in top bar") |
| 94 | + async tapTopBarSettings() { |
| 95 | + await tapById(this.topBarSettingsId); |
| 96 | + } |
| 97 | + |
| 98 | + // ===================== |
| 99 | + // Legacy Tab Actions |
| 100 | + // ===================== |
| 101 | + |
| 102 | + @Step("Tap Portfolio tab (Legacy)") |
| 103 | + async tapLegacyPortfolioTab() { |
| 104 | + await tapById(this.legacyPortfolioTabId); |
| 105 | + } |
| 106 | + |
| 107 | + @Step("Tap Earn tab (Legacy)") |
| 108 | + async tapLegacyEarnTab() { |
| 109 | + await tapById(this.legacyEarnTabId); |
| 110 | + } |
| 111 | + |
| 112 | + @Step("Tap Discover tab (Legacy)") |
| 113 | + async tapLegacyDiscoverTab() { |
| 114 | + await tapById(this.legacyDiscoverTabId); |
| 115 | + } |
| 116 | + |
| 117 | + @Step("Tap My Ledger tab (Legacy)") |
| 118 | + async tapLegacyMyLedgerTab() { |
| 119 | + await tapById(this.legacyMyLedgerTabId); |
| 120 | + } |
| 121 | + |
| 122 | + // ===================== |
| 123 | + // Wallet 4.0 Expectations |
| 124 | + // ===================== |
| 125 | + |
| 126 | + @Step("Expect Wallet 4.0 bottom tabs to be visible") |
| 127 | + async expectWallet40BottomTabsVisible() { |
| 128 | + await detoxExpect(this.wallet40HomeTab()).toBeVisible(); |
| 129 | + await detoxExpect(this.wallet40SwapTab()).toBeVisible(); |
| 130 | + await detoxExpect(this.wallet40EarnTab()).toBeVisible(); |
| 131 | + await detoxExpect(this.wallet40CardTab()).toBeVisible(); |
| 132 | + } |
| 133 | + |
| 134 | + @Step("Expect Wallet 4.0 top bar to be visible") |
| 135 | + async expectWallet40TopBarVisible() { |
| 136 | + await detoxExpect(getElementById(this.topBarMyLedgerId)).toBeVisible(); |
| 137 | + await detoxExpect(getElementById(this.topBarDiscoverId)).toBeVisible(); |
| 138 | + await detoxExpect(getElementById(this.topBarNotificationsId)).toBeVisible(); |
| 139 | + await detoxExpect(getElementById(this.topBarSettingsId)).toBeVisible(); |
| 140 | + } |
| 141 | + |
| 142 | + @Step("Expect legacy bottom tabs NOT visible") |
| 143 | + async expectLegacyTabsNotVisible() { |
| 144 | + await detoxExpect(getElementById(this.legacyTransferButtonId)).not.toBeVisible(); |
| 145 | + await detoxExpect(getElementById(this.legacyMyLedgerTabId)).not.toBeVisible(); |
| 146 | + } |
| 147 | + |
| 148 | + // ===================== |
| 149 | + // Legacy Expectations |
| 150 | + // ===================== |
| 151 | + |
| 152 | + @Step("Expect legacy bottom tabs to be visible") |
| 153 | + async expectLegacyBottomTabsVisible() { |
| 154 | + await detoxExpect(getElementById(this.legacyPortfolioTabId)).toBeVisible(); |
| 155 | + await detoxExpect(getElementById(this.legacyEarnTabId)).toBeVisible(); |
| 156 | + await detoxExpect(getElementById(this.legacyTransferButtonId)).toBeVisible(); |
| 157 | + await detoxExpect(getElementById(this.legacyDiscoverTabId)).toBeVisible(); |
| 158 | + await detoxExpect(getElementById(this.legacyMyLedgerTabId)).toBeVisible(); |
| 159 | + } |
| 160 | + |
| 161 | + @Step("Expect Wallet 4.0 top bar NOT visible") |
| 162 | + async expectWallet40TopBarNotVisible() { |
| 163 | + await detoxExpect(getElementById(this.topBarMyLedgerId)).not.toBeVisible(); |
| 164 | + } |
| 165 | + |
| 166 | + // ===================== |
| 167 | + // Destination Page Expectations |
| 168 | + // ===================== |
| 169 | + |
| 170 | + @Step("Open Portfolio via deeplink (W40)") |
| 171 | + async openPortfolioViaDeeplink() { |
| 172 | + await openDeeplink("portfolio"); |
| 173 | + await this.waitForWallet40Ready(); |
| 174 | + } |
| 175 | + |
| 176 | + @Step("Expect Portfolio page visible") |
| 177 | + async expectPortfolioPageVisible() { |
| 178 | + try { |
| 179 | + await waitForElementById(this.portfolioAccountsListId, 5000); |
| 180 | + } catch { |
| 181 | + await waitForElementById(this.portfolioEmptyListId, 5000); |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | + @Step("Expect Swap page visible") |
| 186 | + async expectSwapPageVisible() { |
| 187 | + await waitForElementById(this.swapFormId); |
| 188 | + } |
| 189 | + |
| 190 | + @Step("Expect Earn page visible") |
| 191 | + async expectEarnPageVisible() { |
| 192 | + await waitForElementById(this.earnScreenId); |
| 193 | + } |
| 194 | + |
| 195 | + @Step("Expect Card page visible") |
| 196 | + async expectCardPageVisible() { |
| 197 | + await waitForElementById(this.cardScreenId); |
| 198 | + } |
| 199 | + |
| 200 | + @Step("Expect My Ledger page visible") |
| 201 | + async expectMyLedgerPageVisible() { |
| 202 | + await detoxExpect(element(by.text(this.managerHeaderTitle)).atIndex(0)).toBeVisible(); |
| 203 | + } |
| 204 | + |
| 205 | + @Step("Go back via header back button") |
| 206 | + async tapHeaderBackButton() { |
| 207 | + await element(by.label("Back")).atIndex(0).tap(); |
| 208 | + } |
| 209 | + |
| 210 | + @Step("Expect Discover page visible") |
| 211 | + async expectDiscoverPageVisible() { |
| 212 | + await detoxExpect(element(by.text(this.discoverHeaderTitle)).atIndex(0)).toBeVisible(); |
| 213 | + } |
| 214 | + |
| 215 | + @Step("Expect Settings page visible") |
| 216 | + async expectSettingsPageVisible() { |
| 217 | + await waitForElementById(this.settingsCardId); |
| 218 | + } |
| 219 | +} |
0 commit comments