diff --git a/e2e/authentication.spec.ts b/e2e/authentication.spec.ts index 684760688c..70dbf4fb5e 100644 --- a/e2e/authentication.spec.ts +++ b/e2e/authentication.spec.ts @@ -4,5 +4,5 @@ import { HomepageLoggedIn } from './utils/pages/homepage.page'; testWithII('should sign-in', async ({ page, iiPage }) => { const homepageLoggedIn = new HomepageLoggedIn({ page, iiPage }); - await homepageLoggedIn.signInWithNewIdentity(); + await homepageLoggedIn.waitForAuthentication(); }); diff --git a/e2e/homepage.spec.ts b/e2e/homepage.spec.ts index 2162e5494e..1a732c70f9 100644 --- a/e2e/homepage.spec.ts +++ b/e2e/homepage.spec.ts @@ -1,11 +1,11 @@ import { testWithII } from '@dfinity/internet-identity-playwright'; import { expect, test } from '@playwright/test'; -import { Homepage, HomepageLoggedIn } from './utils/pages/homepage.page'; +import { HomepageLoggedIn, HomepageLoggedOut } from './utils/pages/homepage.page'; test('should display homepage in logged out state', async ({ page }) => { - const homepage = new Homepage({ page }); + const homepageLoggedOut = new HomepageLoggedOut({ page }); - await homepage.waitForLoggedOut(); + await homepageLoggedOut.waitForReady(); await expect(page).toHaveScreenshot({ fullPage: true }); }); @@ -13,7 +13,7 @@ test('should display homepage in logged out state', async ({ page }) => { testWithII('should display homepage in logged in state', async ({ page, iiPage }) => { const homepageLoggedIn = new HomepageLoggedIn({ page, iiPage }); - await homepageLoggedIn.waitForLoggedIn(); + await homepageLoggedIn.waitForReady(); await expect(page).toHaveScreenshot({ fullPage: true }); }); diff --git a/e2e/utils/pages/homepage.page.ts b/e2e/utils/pages/homepage.page.ts index 127e656a24..127f8b791d 100644 --- a/e2e/utils/pages/homepage.page.ts +++ b/e2e/utils/pages/homepage.page.ts @@ -15,54 +15,70 @@ type HomepageLoggedInParams = { iiPage: InternetIdentityPage; } & HomepageParams; -export class Homepage { - readonly page: Page; +abstract class Homepage { + readonly #page: Page; - constructor({ page }: HomepageParams) { - this.page = page; + protected constructor(page: Page) { + this.#page = page; } - protected async hideHeroAnimation(): Promise { - await this.page + private async hideHeroAnimation(): Promise { + await this.#page .getByTestId(HERO_ANIMATION_CANVAS) .evaluate((element) => (element.style.display = 'none')); } - async goto(): Promise { - await this.page.goto(HOMEPAGE_URL); + private async goto(): Promise { + await this.#page.goto(HOMEPAGE_URL); } - async waitForLoggedOut(): Promise { + protected async waitForHomepageReady(): Promise { await this.goto(); - await this.page.getByTestId(LOGIN_BUTTON).waitFor(); + await this.#page.getByTestId(LOGIN_BUTTON).waitFor(); await this.hideHeroAnimation(); } + + protected async waitForTokenSkeletonsInitialization(): Promise { + await this.#page.getByTestId(TOKENS_SKELETONS_INITIALIZED).waitFor(); + } + + abstract waitForReady(): Promise; +} + +export class HomepageLoggedOut extends Homepage { + constructor({ page }: HomepageParams) { + super(page); + } + + async waitForReady(): Promise { + await this.waitForHomepageReady(); + } } export class HomepageLoggedIn extends Homepage { - readonly iiPage: InternetIdentityPage; + readonly #iiPage: InternetIdentityPage; constructor({ page, iiPage }: HomepageLoggedInParams) { - super({ page }); + super(page); - this.iiPage = iiPage; + this.#iiPage = iiPage; } - async signInWithNewIdentity(): Promise { - await this.iiPage.waitReady({ + async waitForAuthentication(): Promise { + await this.#iiPage.waitReady({ url: LOCAL_REPLICA_URL, // TODO: take this value from vite.utils or FE constants canisterId: 'rdmx6-jaaaa-aaaaa-aaadq-cai' }); - await this.waitForLoggedOut(); + await this.waitForHomepageReady(); - await this.iiPage.signInWithNewIdentity(); + await this.#iiPage.signInWithNewIdentity(); } - async waitForLoggedIn(): Promise { - await this.signInWithNewIdentity(); + async waitForReady(): Promise { + await this.waitForAuthentication(); - await this.page.getByTestId(TOKENS_SKELETONS_INITIALIZED).waitFor(); + await this.waitForTokenSkeletonsInitialization(); } }