diff --git a/e2e/blueprints.test.ts b/e2e/blueprints.test.ts index f1a9ba47d..221910e44 100644 --- a/e2e/blueprints.test.ts +++ b/e2e/blueprints.test.ts @@ -5,7 +5,6 @@ import { E2ESession } from './e2e-helpers'; import MainSidebar from './page-objects/main-sidebar'; import Onboarding from './page-objects/onboarding'; import SiteContent from './page-objects/site-content'; -import WhatsNewModal from './page-objects/whats-new-modal'; import { getUrlWithAutoLogin } from './utils'; test.describe( 'Blueprints', () => { @@ -14,14 +13,9 @@ test.describe( 'Blueprints', () => { test.beforeAll( async () => { await session.launch(); - // Complete onboarding before tests const onboarding = new Onboarding( session.mainWindow ); await onboarding.completeOnboarding(); - - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.closeButton.click(); - } + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, DEFAULT_SITE_NAME ); await expect( siteContent.siteNameHeading ).toBeVisible( { timeout: 120_000 } ); diff --git a/e2e/import-export.test.ts b/e2e/import-export.test.ts index ec0466d89..94e4316ce 100644 --- a/e2e/import-export.test.ts +++ b/e2e/import-export.test.ts @@ -3,7 +3,6 @@ import { test, expect } from '@playwright/test'; import { E2ESession } from './e2e-helpers'; import Onboarding from './page-objects/onboarding'; import SiteContent from './page-objects/site-content'; -import WhatsNewModal from './page-objects/whats-new-modal'; import type { MessageBoxOptions } from 'electron'; const global = globalThis as unknown as { @@ -17,14 +16,9 @@ test.describe( 'Import / Export', () => { test.beforeAll( async () => { await session.launch(); - // Complete onboarding before tests const onboarding = new Onboarding( session.mainWindow ); await onboarding.completeOnboarding(); - - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.closeButton.click(); - } + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, defaultSiteName ); await expect( siteContent.siteNameHeading ).toBeVisible( { timeout: 120_000 } ); diff --git a/e2e/import.test.ts b/e2e/import.test.ts index e561d1dc6..3de69bbd9 100644 --- a/e2e/import.test.ts +++ b/e2e/import.test.ts @@ -5,7 +5,6 @@ import { E2ESession } from './e2e-helpers'; import MainSidebar from './page-objects/main-sidebar'; import Onboarding from './page-objects/onboarding'; import SiteContent from './page-objects/site-content'; -import WhatsNewModal from './page-objects/whats-new-modal'; /** * Import Tests @@ -29,14 +28,9 @@ test.describe( 'Import', () => { test.beforeAll( async () => { await session.launch(); - // Complete onboarding before tests const onboarding = new Onboarding( session.mainWindow ); await onboarding.completeOnboarding(); - - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.closeButton.click(); - } + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, defaultSiteName ); await expect( siteContent.siteNameHeading ).toBeVisible( { timeout: 120_000 } ); diff --git a/e2e/localization.test.ts b/e2e/localization.test.ts index 289b7ebe1..2901a6889 100644 --- a/e2e/localization.test.ts +++ b/e2e/localization.test.ts @@ -43,14 +43,9 @@ test.describe( 'Localization', () => { test.beforeAll( async () => { await session.launch(); - // Complete onboarding before tests const onboarding = new Onboarding( session.mainWindow ); await onboarding.completeOnboarding(); - - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.closeButton.click(); - } + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, 'My WordPress Website' ); await expect( siteContent.siteNameHeading ).toBeVisible( { timeout: 120_000 } ); @@ -101,15 +96,7 @@ test.describe( 'Localization', () => { // Onboarding not visible, continue with test } - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - try { - const visible = await whatsNewModal.locator.isVisible( { timeout: 2000 } ); - if ( visible ) { - await whatsNewModal.closeButton.click(); - } - } catch ( error ) { - // What's New modal not visible, continue with test - } + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, 'My WordPress Website' ); await expect( siteContent.siteNameHeading ).toBeVisible( { timeout: 120_000 } ); diff --git a/e2e/overview-customize-links.test.ts b/e2e/overview-customize-links.test.ts index c157b21e2..8c2b338bf 100644 --- a/e2e/overview-customize-links.test.ts +++ b/e2e/overview-customize-links.test.ts @@ -76,11 +76,7 @@ test.describe( 'Overview customize links', () => { const onboarding = new Onboarding( session.mainWindow ); await onboarding.completeOnboarding( { customSiteName: siteName } ); - - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.close(); - } + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, siteName ); await expect( siteContent.siteNameHeading ).toBeVisible( { timeout: 120_000 } ); diff --git a/e2e/page-objects/main-sidebar.ts b/e2e/page-objects/main-sidebar.ts index a9a83e73e..51d37a275 100644 --- a/e2e/page-objects/main-sidebar.ts +++ b/e2e/page-objects/main-sidebar.ts @@ -10,7 +10,7 @@ export default class MainSidebar { } get addSiteButton() { - return this.page.getByTestId( 'add-site-button' ); + return this.locator.getByTestId( 'add-site-button' ); } getSiteNavButton( siteName: string ) { @@ -20,15 +20,13 @@ export default class MainSidebar { async openAddSiteModal() { const isButtonVisible = await this.addSiteButton.isVisible().catch( () => false ); - if ( isButtonVisible ) { - // Sites exist - need to open the modal - await this.addSiteButton.click(); - const dialog = new AddSiteModal( this.page ); - await expect( dialog.locator ).toBeVisible(); - return dialog; + if ( ! isButtonVisible ) { + throw new Error( 'Add Site button not found on the main sidebar' ); } - // No Add Site button visible means we're on empty screen - content is directly on page (no dialog wrapper) - return new AddSiteModal( this.page ); + await this.addSiteButton.click(); + const dialog = new AddSiteModal( this.page ); + await expect( dialog.locator ).toBeVisible(); + return dialog; } } diff --git a/e2e/page-objects/onboarding.ts b/e2e/page-objects/onboarding.ts index 462d1923a..876638169 100644 --- a/e2e/page-objects/onboarding.ts +++ b/e2e/page-objects/onboarding.ts @@ -1,6 +1,7 @@ import { type Page } from '@playwright/test'; import { expect } from '@playwright/test'; -import MainSidebar from './main-sidebar'; +import AddSiteModal from './add-site-modal'; +import WhatsNewModal from './whats-new-modal'; export default class Onboarding { constructor( private page: Page ) {} @@ -20,8 +21,7 @@ export default class Onboarding { await expect( this.heading ).toBeVisible(); await this.locator.getByRole( 'button', { name: 'Skip →' } ).click(); - const sidebar = new MainSidebar( this.page ); - const modal = await sidebar.openAddSiteModal(); + const modal = new AddSiteModal( this.page ); await modal.createSiteButton.click(); if ( customSiteName ) { @@ -42,4 +42,11 @@ export default class Onboarding { localPath, }; } + + async closeWhatsNew() { + const whatsNewModal = new WhatsNewModal( this.page ); + if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { + await whatsNewModal.closeButton.click(); + } + } } diff --git a/e2e/page-objects/whats-new-modal.ts b/e2e/page-objects/whats-new-modal.ts index ecedd84e3..a23f6bd59 100644 --- a/e2e/page-objects/whats-new-modal.ts +++ b/e2e/page-objects/whats-new-modal.ts @@ -10,8 +10,4 @@ export default class WhatsNewModal { get closeButton() { return this.locator.getByRole( 'button', { name: 'Close' } ); } - - async close() { - await this.closeButton.click(); - } } diff --git a/e2e/sites.test.ts b/e2e/sites.test.ts index e16da3435..1c3e97370 100644 --- a/e2e/sites.test.ts +++ b/e2e/sites.test.ts @@ -8,7 +8,6 @@ import { E2ESession } from './e2e-helpers'; import MainSidebar from './page-objects/main-sidebar'; import Onboarding from './page-objects/onboarding'; import SiteContent from './page-objects/site-content'; -import WhatsNewModal from './page-objects/whats-new-modal'; import { getUrlWithAutoLogin } from './utils'; const skipTestOnWindows = process.platform === 'win32' ? test.skip : test; @@ -35,7 +34,7 @@ test.describe( 'Servers', () => { customFolderName, } ); - await closeWhatsNew(); + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, siteName ); await expect( siteContent.siteNameHeading ).toBeVisible( { timeout: 120_000 } ); @@ -46,13 +45,6 @@ test.describe( 'Servers', () => { }; } - async function closeWhatsNew() { - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.closeButton.click(); - } - } - test.afterEach( async () => { await session.cleanup(); } ); diff --git a/metrics/tests/site-editor.test.ts b/metrics/tests/site-editor.test.ts index 40354fe1f..c24843bc5 100644 --- a/metrics/tests/site-editor.test.ts +++ b/metrics/tests/site-editor.test.ts @@ -37,12 +37,7 @@ test.describe( 'Site Editor Load Metrics', () => { // Wait for store initialization to complete (provider constants loading) await new Promise( ( resolve ) => setTimeout( resolve, 500 ) ); await onboarding.completeOnboarding( { customSiteName: siteName } ); - - // Handle the What's New modal if it appears - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.closeButton.click(); - } + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, siteName ); diff --git a/metrics/tests/site-startup.test.ts b/metrics/tests/site-startup.test.ts index 1f4409c22..59a95a1bb 100644 --- a/metrics/tests/site-startup.test.ts +++ b/metrics/tests/site-startup.test.ts @@ -41,12 +41,7 @@ test.describe( 'Startup Metrics', () => { await expect( onboarding.heading ).toBeVisible(); const startTime = Date.now(); await onboarding.completeOnboarding(); - - // Handle the What's New modal if it appears - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.closeButton.click(); - } + await onboarding.closeWhatsNew(); siteContent = new SiteContent( session.mainWindow, siteName ); await expect( siteContent.runningButton ).toBeAttached();