Skip to content

Commit

Permalink
test(homepage): adjust homepage.page implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysKarmazynDFINITY committed Aug 20, 2024
1 parent e8f83b9 commit aa66058
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
2 changes: 1 addition & 1 deletion e2e/authentication.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
8 changes: 4 additions & 4 deletions e2e/homepage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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 });
});

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 });
});
56 changes: 36 additions & 20 deletions e2e/utils/pages/homepage.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
await this.page
private async hideHeroAnimation(): Promise<void> {
await this.#page
.getByTestId(HERO_ANIMATION_CANVAS)
.evaluate((element) => (element.style.display = 'none'));
}

async goto(): Promise<void> {
await this.page.goto(HOMEPAGE_URL);
private async goto(): Promise<void> {
await this.#page.goto(HOMEPAGE_URL);
}

async waitForLoggedOut(): Promise<void> {
protected async waitForHomepageReady(): Promise<void> {
await this.goto();
await this.page.getByTestId(LOGIN_BUTTON).waitFor();
await this.#page.getByTestId(LOGIN_BUTTON).waitFor();
await this.hideHeroAnimation();
}

protected async waitForTokenSkeletonsInitialization(): Promise<void> {
await this.#page.getByTestId(TOKENS_SKELETONS_INITIALIZED).waitFor();
}

abstract waitForReady(): Promise<void>;
}

export class HomepageLoggedOut extends Homepage {
constructor({ page }: HomepageParams) {
super(page);
}

async waitForReady(): Promise<void> {
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<void> {
await this.iiPage.waitReady({
async waitForAuthentication(): Promise<void> {
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<void> {
await this.signInWithNewIdentity();
async waitForReady(): Promise<void> {
await this.waitForAuthentication();

await this.page.getByTestId(TOKENS_SKELETONS_INITIALIZED).waitFor();
await this.waitForTokenSkeletonsInitialization();
}
}

0 comments on commit aa66058

Please sign in to comment.