Skip to content

Commit

Permalink
tests: refactor wallet page
Browse files Browse the repository at this point in the history
  • Loading branch information
phoebus-84 committed Oct 18, 2024
1 parent 018ee0c commit 051e163
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 17 deletions.
53 changes: 53 additions & 0 deletions tests/fixtures/WalletPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// WalletPage.ts
import { type Page, type Locator, expect } from '@playwright/test';

export class WalletPage {
private readonly page: Page;
private readonly walletHeading: Locator;
private readonly credentialsHeading: Locator;
private readonly credentialsDescription: Locator;
private readonly emptyStateHeading: Locator;
private readonly emptyStateDescription: Locator;
private readonly getCredentialsButton: Locator;
private readonly credentialCard: Locator;
private readonly credentialLink: Locator;

constructor(page: Page) {
this.page = page;
this.walletHeading = page.getByText('WALLET').first();
this.credentialsHeading = page.getByText('My credentials').first();
this.credentialsDescription = page.locator('d-text p');
this.emptyStateHeading = page.locator(
'd-heading:has-text("There is no Credential in your wallet")'
);
this.emptyStateDescription = page.locator('d-text:has-text("Get your first credential")');
this.getCredentialsButton = page.locator('d-button:has-text("GET CREDENTIALS")');
this.credentialCard = page.locator('d-credential-card');
this.credentialLink = page.locator('button[class*="relative"]').first();
}

async verifyWalletPage() {
await expect(this.page).toHaveURL('/en/wallet');
await expect(this.walletHeading).toBeVisible();
}

async verifyCredentialsHeadingAndDescription() {
await expect(this.credentialsHeading).toBeVisible();
await expect(this.credentialsDescription).toContainText('Explore and manage your credentials');
}

async verifyEmptyState() {
await expect(this.emptyStateHeading).toBeVisible();
await expect(this.emptyStateDescription).toBeVisible();
await expect(this.getCredentialsButton).toBeVisible();
}

async verifyCredentialsVisible() {
await expect(this.credentialCard.first()).toBeVisible();
}

async clickFirstCredential() {
await this.credentialLink.click();
await expect(this.page).toHaveURL(/\/credential-detail$/);
}
}
4 changes: 2 additions & 2 deletions tests/register.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ test.describe('Security Questions Page', () => {
await securityQuestionsPage.fillQuestionTwo('Buddy');
await securityQuestionsPage.fillQuestionThree('New York');
await securityQuestionsPage.clickNext();
await page.waitForTimeout(10000);
await page.waitForTimeout(5000);

// await securityQuestionsPage.expectKeyringGenerated();
await securityQuestionsPage.expectKeyringGenerated();
await securityQuestionsPage.verifyKeyringAndDID();
});
});
27 changes: 12 additions & 15 deletions tests/wallet.spec.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
import { expect, test } from '@playwright/test';
import { test } from '@playwright/test';
import { addCredentialsToLocalStorage, login, tabBarClick } from './utils';
import { WalletPage } from './fixtures/WalletPage';

test.describe('Wallet Page', () => {
test('should load wallet page after login', async ({ page }) => {
await login(page);
await expect(page).toHaveURL('/en/wallet');
await expect(page.getByText('WALLET').first()).toBeVisible();
const walletPage = new WalletPage(page);
await walletPage.verifyWalletPage();
});

test('should display heading and description', async ({ page }) => {
await login(page);
await expect(page.getByText('My credentials').first()).toBeVisible();
await expect(page.locator('d-text p')).toContainText('Explore and manage your credentials');
const walletPage = new WalletPage(page);
await walletPage.verifyCredentialsHeadingAndDescription();
});

test('should show empty state when no credentials', async ({ page }) => {
await login(page);
await expect(
page.locator('d-heading:has-text("There is no Credential in your wallet")')
).toBeVisible();
await expect(page.locator('d-text:has-text("Get your first credential")')).toBeVisible();
await expect(page.locator('d-button:has-text("GET CREDENTIALS")')).toBeVisible();
const walletPage = new WalletPage(page);
await walletPage.verifyEmptyState();
});

test('should list credentials if available', async ({ page }) => {
await login(page);
await addCredentialsToLocalStorage(page);
await tabBarClick('Home', page);
await tabBarClick('Wallet', page);
const credentialLocator = page.locator('d-credential-card');
await expect(credentialLocator.first()).toBeVisible();
const walletPage = new WalletPage(page);
await walletPage.verifyCredentialsVisible();
});

test('should navigate to credential detail on click', async ({ page }) => {
await login(page);
await addCredentialsToLocalStorage(page);
await tabBarClick('Home', page);
await tabBarClick('Wallet', page);
const credentialLink = page.locator('button[class*="relative"]').first();
await credentialLink.click();
await expect(page).toHaveURL(/\/credential-detail$/);
const walletPage = new WalletPage(page);
await walletPage.clickFirstCredential();
});
});

0 comments on commit 051e163

Please sign in to comment.