|
| 1 | +import { expect, type Locator, type Page } from '@playwright/test'; |
| 2 | +import { |
| 3 | + ACCTS_HUB_URL, |
| 4 | + ACCTS_OIDC_EMAIL, |
| 5 | + DASHBOARD_CURRENT_SUBSCRIPTION_CUSTOM_DOMAINS, |
| 6 | + DASHBOARD_CURRENT_SUBSCRIPTION_EMAIL_ADDRESSES, |
| 7 | + DASHBOARD_CURRENT_SUBSCRIPTION_MAIL_STORAGE, |
| 8 | + DASHBOARD_CURRENT_SUBSCRIPTION_PRICE, |
| 9 | + DASHBOARD_CURRENT_SUBSCRIPTION_SEND_STORAGE, |
| 10 | + PADDLE_HOST, |
| 11 | + TIMEOUT_2_SECONDS, |
| 12 | + TIMEOUT_5_SECONDS, |
| 13 | + TIMEOUT_30_SECONDS, |
| 14 | +} from '../const/constants'; |
| 15 | +import { waitForVueApp } from '../utils/utils'; |
| 16 | + |
| 17 | +interface ServiceUrls { |
| 18 | + appointment: string; |
| 19 | + send: string; |
| 20 | +} |
| 21 | + |
| 22 | +const escapeRegExp = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); |
| 23 | + |
| 24 | +export class DashboardPage { |
| 25 | + readonly page: Page; |
| 26 | + readonly myAccountHeading: Locator; |
| 27 | + readonly myAccountCard: Locator; |
| 28 | + readonly privacyAndDataHeading: Locator; |
| 29 | + readonly manageYourServicesHeading: Locator; |
| 30 | + readonly currentSubscriptionHeading: Locator; |
| 31 | + readonly currentSubscriptionSection: Locator; |
| 32 | + readonly passwordChangeLink: Locator; |
| 33 | + readonly updatePasswordHeader: Locator; |
| 34 | + readonly deleteAccountLink: Locator; |
| 35 | + readonly thundermailLink: Locator; |
| 36 | + readonly appointmentLink: Locator; |
| 37 | + readonly sendLink: Locator; |
| 38 | + readonly manageSubscriptionButton: Locator; |
| 39 | + readonly userAvatar: Locator; |
| 40 | + readonly supportLink: Locator; |
| 41 | + readonly logoutLink: Locator; |
| 42 | + readonly contactHeader: Locator; |
| 43 | + |
| 44 | + constructor(page: Page) { |
| 45 | + this.page = page; |
| 46 | + this.myAccountHeading = this.page.getByRole('heading', { name: 'My Account' }); |
| 47 | + this.myAccountCard = this.page.locator('.my-account-card'); |
| 48 | + this.privacyAndDataHeading = this.page.getByRole('heading', { name: 'Privacy & Data' }); |
| 49 | + this.manageYourServicesHeading = this.page.getByRole('heading', { name: 'Manage Your Services' }); |
| 50 | + this.currentSubscriptionHeading = this.page.getByRole('heading', { name: 'Your Current Subscription' }); |
| 51 | + this.currentSubscriptionSection = this.page.locator('section').filter({ has: this.currentSubscriptionHeading }); |
| 52 | + this.passwordChangeLink = this.page.locator('a[href="/reset-password/"]'); |
| 53 | + this.updatePasswordHeader = this.page.getByRole('heading', { name: 'Update password' }); |
| 54 | + this.deleteAccountLink = this.page.getByRole('link', { name: 'Delete account and all data' }); |
| 55 | + this.thundermailLink = this.page.locator('.service-icon-link[href="/mail"]').filter({ hasText: 'Thundermail' }); |
| 56 | + this.appointmentLink = this.page.locator('.service-icon-link').filter({ hasText: 'Appointment' }); |
| 57 | + this.sendLink = this.page.locator('.service-icon-link').filter({ hasText: 'Send' }); |
| 58 | + this.manageSubscriptionButton = this.page.getByRole('button', { name: 'Manage Subscription' }); |
| 59 | + this.userAvatar = this.page.getByRole('banner').locator('.avatar'); |
| 60 | + this.supportLink = this.page.getByRole('link', { name: 'Support' }); |
| 61 | + this.logoutLink = this.page.getByRole('link', { name: 'Logout' }); |
| 62 | + this.contactHeader = this.page.getByRole('heading', { name: 'Submit a request' }); |
| 63 | + } |
| 64 | + |
| 65 | + async navigateToDashboard() { |
| 66 | + await this.page.goto(`${ACCTS_HUB_URL}/dashboard`); |
| 67 | + await this.waitForPageToSettle(); |
| 68 | + // This test expects that the signed-in user already has a tb pro subscription setup |
| 69 | + // so the dashboard is displayed after sign-in and not the tb pro subscription page |
| 70 | + await expect.poll(async () => new URL(this.page.url()).pathname).toBe('/dashboard'); |
| 71 | + } |
| 72 | + |
| 73 | + async verifyDashboardDisplayed() { |
| 74 | + await expect(this.myAccountHeading).toBeVisible(); |
| 75 | + await expect(this.myAccountCard).toContainText(ACCTS_OIDC_EMAIL); |
| 76 | + await expect(this.privacyAndDataHeading).toBeVisible(); |
| 77 | + await expect(this.manageYourServicesHeading).toBeVisible(); |
| 78 | + await expect(this.currentSubscriptionHeading).toBeVisible(); |
| 79 | + await expect(this.currentSubscriptionSection).toContainText(DASHBOARD_CURRENT_SUBSCRIPTION_PRICE); |
| 80 | + await expect(this.currentSubscriptionSection).toContainText( |
| 81 | + new RegExp(`${escapeRegExp(DASHBOARD_CURRENT_SUBSCRIPTION_MAIL_STORAGE)}\\s*of Mail Storage`), |
| 82 | + ); |
| 83 | + await expect(this.currentSubscriptionSection).toContainText( |
| 84 | + new RegExp(`${escapeRegExp(DASHBOARD_CURRENT_SUBSCRIPTION_SEND_STORAGE)}\\s*of Send Storage`), |
| 85 | + ); |
| 86 | + await expect(this.currentSubscriptionSection).toContainText( |
| 87 | + new RegExp(`${escapeRegExp(DASHBOARD_CURRENT_SUBSCRIPTION_EMAIL_ADDRESSES)}\\s*Email Addresses`), |
| 88 | + ); |
| 89 | + await expect(this.currentSubscriptionSection).toContainText( |
| 90 | + new RegExp(`${escapeRegExp(DASHBOARD_CURRENT_SUBSCRIPTION_CUSTOM_DOMAINS)}\\s*Custom Domains`), |
| 91 | + ); |
| 92 | + await expect(this.passwordChangeLink).toBeVisible(); |
| 93 | + await expect(this.deleteAccountLink).toBeVisible(); |
| 94 | + await expect(this.thundermailLink).toBeVisible(); |
| 95 | + await expect(this.appointmentLink).toBeVisible(); |
| 96 | + await expect(this.sendLink).toBeVisible(); |
| 97 | + await expect(this.manageSubscriptionButton).toBeVisible({ timeout: TIMEOUT_30_SECONDS }); |
| 98 | + } |
| 99 | + |
| 100 | + async verifyPasswordChangeNavigation() { |
| 101 | + await this.passwordChangeLink.click(); |
| 102 | + await this.waitForPageToSettle(); |
| 103 | + await expect(this.updatePasswordHeader).toBeVisible({ timeout: TIMEOUT_30_SECONDS }); |
| 104 | + } |
| 105 | + |
| 106 | + async verifyDeleteAccountNavigationOnly() { |
| 107 | + await this.deleteAccountLink.click(); |
| 108 | + await this.verifyContactScreenDisplayed(); |
| 109 | + } |
| 110 | + |
| 111 | + async verifyThundermailNavigation() { |
| 112 | + await this.thundermailLink.click(); |
| 113 | + await this.waitForPageToSettle(); |
| 114 | + await expect.poll(async () => new URL(this.page.url()).pathname).toBe('/mail'); |
| 115 | + } |
| 116 | + |
| 117 | + async verifyServiceLinksOpenConfiguredUrls() { |
| 118 | + const serviceUrls = await this.getConfiguredServiceUrls(); |
| 119 | + await this.verifyLinkOpensPopup(this.appointmentLink, serviceUrls.appointment); |
| 120 | + await this.verifyLinkOpensPopup(this.sendLink, serviceUrls.send); |
| 121 | + } |
| 122 | + |
| 123 | + async verifyManageSubscriptionOpensPortal() { |
| 124 | + const [popup] = await Promise.all([ |
| 125 | + this.page.waitForEvent('popup'), |
| 126 | + this.manageSubscriptionButton.click(), |
| 127 | + ]); |
| 128 | + |
| 129 | + await expect.poll(async () => popup.url()).not.toBe('about:blank'); |
| 130 | + expect(new URL(popup.url()).protocol).toMatch(/^https?:$/); |
| 131 | + expect(new URL(popup.url()).host).toBe(PADDLE_HOST); |
| 132 | + await popup.close(); |
| 133 | + } |
| 134 | + |
| 135 | + async verifyUserMenuControls() { |
| 136 | + await this.userAvatar.click(); |
| 137 | + await expect(this.supportLink).toBeVisible(); |
| 138 | + await expect(this.logoutLink).toBeVisible(); |
| 139 | + await expect(this.logoutLink).toHaveAttribute('href', '/logout/'); |
| 140 | + |
| 141 | + await this.supportLink.click(); |
| 142 | + await this.verifyContactScreenDisplayed(); |
| 143 | + } |
| 144 | + |
| 145 | + private async verifyContactScreenDisplayed() { |
| 146 | + await this.waitForPageToSettle(); |
| 147 | + await expect.poll(async () => new URL(this.page.url()).pathname).toMatch(/^\/contact\/?$/); |
| 148 | + await expect(this.contactHeader).toBeVisible({ timeout: TIMEOUT_30_SECONDS }); |
| 149 | + } |
| 150 | + |
| 151 | + private async waitForPageToSettle() { |
| 152 | + await waitForVueApp(this.page); |
| 153 | + await this.page.waitForLoadState('networkidle', { timeout: TIMEOUT_5_SECONDS }).catch(() => {}); |
| 154 | + await this.page.waitForTimeout(TIMEOUT_2_SECONDS); |
| 155 | + } |
| 156 | + |
| 157 | + private async getConfiguredServiceUrls(): Promise<ServiceUrls> { |
| 158 | + return await this.page.evaluate(() => ({ |
| 159 | + appointment: (window as any)._page?.tbProAppointmentUrl, |
| 160 | + send: (window as any)._page?.tbProSendUrl, |
| 161 | + })); |
| 162 | + } |
| 163 | + |
| 164 | + private async verifyLinkOpensPopup(link: Locator, expectedUrl: string) { |
| 165 | + expect(expectedUrl).toBeTruthy(); |
| 166 | + await expect(link).toHaveAttribute('href', expectedUrl); |
| 167 | + await expect(link).toHaveAttribute('target', '_blank'); |
| 168 | + |
| 169 | + const [popup] = await Promise.all([ |
| 170 | + this.page.waitForEvent('popup'), |
| 171 | + link.click(), |
| 172 | + ]); |
| 173 | + |
| 174 | + await expect.poll(async () => popup.url()).not.toBe('about:blank'); |
| 175 | + expect(new URL(popup.url()).href).toBe(new URL(expectedUrl).href); |
| 176 | + await popup.close(); |
| 177 | + } |
| 178 | +} |
0 commit comments